11use cranelift_module:: { DataId , FuncId } ;
22use cranelift_object:: ObjectProduct ;
33use gimli:: SectionId ;
4- use object:: write:: { Relocation , StandardSegment } ;
4+ use object:: write:: { Relocation , StandardSection , StandardSegment } ;
55use object:: { RelocationEncoding , RelocationFlags , SectionKind } ;
66use rustc_data_structures:: fx:: FxHashMap ;
77
@@ -16,6 +16,7 @@ pub(super) trait WriteDebugInfo {
1616 section_map : & FxHashMap < SectionId , Self :: SectionId > ,
1717 from : & Self :: SectionId ,
1818 reloc : & DebugReloc ,
19+ use_section_symbol : bool ,
1920 ) ;
2021}
2122
@@ -27,29 +28,31 @@ impl WriteDebugInfo for ObjectProduct {
2728 id : SectionId ,
2829 data : Vec < u8 > ,
2930 ) -> ( object:: write:: SectionId , object:: write:: SymbolId ) {
30- let name = if self . object . format ( ) == object:: BinaryFormat :: MachO {
31- id. name ( ) . replace ( '.' , "__" ) // machO expects __debug_info instead of .debug_info
31+ let ( section_id, align) ;
32+ if id == SectionId :: EhFrame {
33+ section_id = self . object . section_id ( StandardSection :: EhFrame ) ;
34+ align = 8 ;
3235 } else {
33- id. name ( ) . to_string ( )
34- }
35- . into_bytes ( ) ;
36-
37- let segment = self . object . segment_name ( StandardSegment :: Debug ) . to_vec ( ) ;
38- // FIXME use SHT_X86_64_UNWIND for .eh_frame
39- let section_id = self . object . add_section (
40- segment,
41- name,
42- if id == SectionId :: DebugStr || id == SectionId :: DebugLineStr {
43- SectionKind :: DebugString
44- } else if id == SectionId :: EhFrame {
45- SectionKind :: ReadOnlyData
36+ let name = if self . object . format ( ) == object:: BinaryFormat :: MachO {
37+ id. name ( ) . replace ( '.' , "__" ) // machO expects __debug_info instead of .debug_info
4638 } else {
47- SectionKind :: Debug
48- } ,
49- ) ;
50- self . object
51- . section_mut ( section_id)
52- . set_data ( data, if id == SectionId :: EhFrame { 8 } else { 1 } ) ;
39+ id. name ( ) . to_string ( )
40+ }
41+ . into_bytes ( ) ;
42+
43+ let segment = self . object . segment_name ( StandardSegment :: Debug ) . to_vec ( ) ;
44+ section_id = self . object . add_section (
45+ segment,
46+ name,
47+ if id == SectionId :: DebugStr || id == SectionId :: DebugLineStr {
48+ SectionKind :: DebugString
49+ } else {
50+ SectionKind :: Debug
51+ } ,
52+ ) ;
53+ align = 1 ;
54+ }
55+ self . object . section_mut ( section_id) . set_data ( data, align) ;
5356 let symbol_id = self . object . section_symbol ( section_id) ;
5457 ( section_id, symbol_id)
5558 }
@@ -59,6 +62,7 @@ impl WriteDebugInfo for ObjectProduct {
5962 section_map : & FxHashMap < SectionId , Self :: SectionId > ,
6063 from : & Self :: SectionId ,
6164 reloc : & DebugReloc ,
65+ use_section_symbol : bool ,
6266 ) {
6367 let ( symbol, symbol_offset) = match reloc. name {
6468 DebugRelocName :: Section ( id) => ( section_map. get ( & id) . unwrap ( ) . 1 , 0 ) ,
@@ -69,7 +73,11 @@ impl WriteDebugInfo for ObjectProduct {
6973 } else {
7074 self . data_symbol ( DataId :: from_u32 ( id & !( 1 << 31 ) ) )
7175 } ;
72- self . object . symbol_section_and_offset ( symbol_id) . unwrap_or ( ( symbol_id, 0 ) )
76+ if use_section_symbol {
77+ self . object . symbol_section_and_offset ( symbol_id) . unwrap_or ( ( symbol_id, 0 ) )
78+ } else {
79+ ( symbol_id, 0 )
80+ }
7381 }
7482 } ;
7583 self . object
0 commit comments