|
| 1 | +pub trait Product { |
| 2 | + fn add_rustc_section(&mut self, symbol_name: String, data: Vec<u8>, is_like_osx: bool); |
| 3 | +} |
| 4 | + |
| 5 | +impl Product for faerie::Artifact { |
| 6 | + fn add_rustc_section(&mut self, symbol_name: String, data: Vec<u8>, is_like_osx: bool) { |
| 7 | + self |
| 8 | + .declare(".rustc", faerie::Decl::section(faerie::SectionKind::Data)) |
| 9 | + .unwrap(); |
| 10 | + self |
| 11 | + .define_with_symbols(".rustc", data, { |
| 12 | + let mut map = std::collections::BTreeMap::new(); |
| 13 | + // FIXME implement faerie elf backend section custom symbols |
| 14 | + // For MachO this is necessary to prevent the linker from throwing away the .rustc section, |
| 15 | + // but for ELF it isn't. |
| 16 | + if is_like_osx { |
| 17 | + map.insert( |
| 18 | + symbol_name, |
| 19 | + 0, |
| 20 | + ); |
| 21 | + } |
| 22 | + map |
| 23 | + }) |
| 24 | + .unwrap(); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +impl Product for object::write::Object { |
| 29 | + fn add_rustc_section(&mut self, symbol_name: String, data: Vec<u8>, is_like_osx: bool) { |
| 30 | + let segment = self.segment_name(object::write::StandardSegment::Data).to_vec(); |
| 31 | + let section_id = self.add_section(segment, b".rustc".to_vec(), object::SectionKind::Data); |
| 32 | + let offset = self.append_section_data(section_id, &data, 1); |
| 33 | + // FIXME implement faerie elf backend section custom symbols |
| 34 | + // For MachO this is necessary to prevent the linker from throwing away the .rustc section, |
| 35 | + // but for ELF it isn't. |
| 36 | + if is_like_osx { |
| 37 | + self.add_symbol(object::write::Symbol { |
| 38 | + name: symbol_name.into_bytes(), |
| 39 | + value: offset, |
| 40 | + size: data.len() as u64, |
| 41 | + kind: object::SymbolKind::Data, |
| 42 | + scope: object::SymbolScope::Compilation, |
| 43 | + weak: false, |
| 44 | + section: Some(section_id), |
| 45 | + }); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments