@@ -9,37 +9,13 @@ use cranelift_codegen::isa::TargetIsa;
9
9
use cranelift_module:: FuncId ;
10
10
use cranelift_object:: { ObjectBuilder , ObjectModule , ObjectProduct } ;
11
11
12
- use object:: write:: * ;
13
- use object:: { RelocationEncoding , SectionKind , SymbolFlags } ;
12
+ use object:: write:: { Relocation , StandardSegment } ;
13
+ use object:: { RelocationEncoding , SectionKind } ;
14
14
15
15
use gimli:: SectionId ;
16
16
17
17
use crate :: debuginfo:: { DebugReloc , DebugRelocName } ;
18
18
19
- pub ( crate ) trait WriteMetadata {
20
- fn add_rustc_section ( & mut self , symbol_name : String , data : Vec < u8 > ) ;
21
- }
22
-
23
- impl WriteMetadata for object:: write:: Object {
24
- fn add_rustc_section ( & mut self , symbol_name : String , data : Vec < u8 > ) {
25
- let segment = self . segment_name ( object:: write:: StandardSegment :: Data ) . to_vec ( ) ;
26
- let section_id = self . add_section ( segment, b".rustc" . to_vec ( ) , object:: SectionKind :: Data ) ;
27
- let offset = self . append_section_data ( section_id, & data, 1 ) ;
28
- // For MachO and probably PE this is necessary to prevent the linker from throwing away the
29
- // .rustc section. For ELF this isn't necessary, but it also doesn't harm.
30
- self . add_symbol ( object:: write:: Symbol {
31
- name : symbol_name. into_bytes ( ) ,
32
- value : offset,
33
- size : data. len ( ) as u64 ,
34
- kind : object:: SymbolKind :: Data ,
35
- scope : object:: SymbolScope :: Dynamic ,
36
- weak : false ,
37
- section : SymbolSection :: Section ( section_id) ,
38
- flags : SymbolFlags :: None ,
39
- } ) ;
40
- }
41
- }
42
-
43
19
pub ( crate ) trait WriteDebugInfo {
44
20
type SectionId : Copy ;
45
21
@@ -112,48 +88,6 @@ impl WriteDebugInfo for ObjectProduct {
112
88
}
113
89
}
114
90
115
- pub ( crate ) fn with_object ( sess : & Session , name : & str , f : impl FnOnce ( & mut Object ) ) -> Vec < u8 > {
116
- let triple = crate :: target_triple ( sess) ;
117
-
118
- let binary_format = match triple. binary_format {
119
- target_lexicon:: BinaryFormat :: Elf => object:: BinaryFormat :: Elf ,
120
- target_lexicon:: BinaryFormat :: Coff => object:: BinaryFormat :: Coff ,
121
- target_lexicon:: BinaryFormat :: Macho => object:: BinaryFormat :: MachO ,
122
- binary_format => sess. fatal ( & format ! ( "binary format {} is unsupported" , binary_format) ) ,
123
- } ;
124
- let architecture = match triple. architecture {
125
- target_lexicon:: Architecture :: Aarch64 ( _) => object:: Architecture :: Aarch64 ,
126
- target_lexicon:: Architecture :: Arm ( _) => object:: Architecture :: Arm ,
127
- target_lexicon:: Architecture :: Avr => object:: Architecture :: Avr ,
128
- target_lexicon:: Architecture :: Hexagon => object:: Architecture :: Hexagon ,
129
- target_lexicon:: Architecture :: Mips32 ( _) => object:: Architecture :: Mips ,
130
- target_lexicon:: Architecture :: Mips64 ( _) => object:: Architecture :: Mips64 ,
131
- target_lexicon:: Architecture :: Msp430 => object:: Architecture :: Msp430 ,
132
- target_lexicon:: Architecture :: Powerpc => object:: Architecture :: PowerPc ,
133
- target_lexicon:: Architecture :: Powerpc64 => object:: Architecture :: PowerPc64 ,
134
- target_lexicon:: Architecture :: Powerpc64le => todo ! ( ) ,
135
- target_lexicon:: Architecture :: Riscv32 ( _) => object:: Architecture :: Riscv32 ,
136
- target_lexicon:: Architecture :: Riscv64 ( _) => object:: Architecture :: Riscv64 ,
137
- target_lexicon:: Architecture :: S390x => object:: Architecture :: S390x ,
138
- target_lexicon:: Architecture :: Sparc64 => object:: Architecture :: Sparc64 ,
139
- target_lexicon:: Architecture :: Sparcv9 => object:: Architecture :: Sparc64 ,
140
- target_lexicon:: Architecture :: X86_32 ( _) => object:: Architecture :: I386 ,
141
- target_lexicon:: Architecture :: X86_64 => object:: Architecture :: X86_64 ,
142
- architecture => {
143
- sess. fatal ( & format ! ( "target architecture {:?} is unsupported" , architecture, ) )
144
- }
145
- } ;
146
- let endian = match triple. endianness ( ) . unwrap ( ) {
147
- target_lexicon:: Endianness :: Little => object:: Endianness :: Little ,
148
- target_lexicon:: Endianness :: Big => object:: Endianness :: Big ,
149
- } ;
150
-
151
- let mut metadata_object = object:: write:: Object :: new ( binary_format, architecture, endian) ;
152
- metadata_object. add_file_symbol ( name. as_bytes ( ) . to_vec ( ) ) ;
153
- f ( & mut metadata_object) ;
154
- metadata_object. write ( ) . unwrap ( )
155
- }
156
-
157
91
pub ( crate ) fn make_module ( sess : & Session , isa : Box < dyn TargetIsa > , name : String ) -> ObjectModule {
158
92
let mut builder =
159
93
ObjectBuilder :: new ( isa, name + ".o" , cranelift_module:: default_libcall_names ( ) ) . unwrap ( ) ;
0 commit comments