(
&mut self,
func_id: FuncId,
alignment: u64,
bytes: &[u8],
relocs: Vec<ObjectRelocRecord>,
)
| 636 | |
| 637 | impl ObjectModule { |
| 638 | fn define_function_inner( |
| 639 | &mut self, |
| 640 | func_id: FuncId, |
| 641 | alignment: u64, |
| 642 | bytes: &[u8], |
| 643 | relocs: Vec<ObjectRelocRecord>, |
| 644 | ) -> Result<(), ModuleError> { |
| 645 | info!("defining function {func_id} with bytes"); |
| 646 | let decl = self.declarations.get_function_decl(func_id); |
| 647 | let decl_name = decl.linkage_name(func_id); |
| 648 | if !decl.linkage.is_definable() { |
| 649 | return Err(ModuleError::InvalidImportDefinition(decl_name.into_owned())); |
| 650 | } |
| 651 | |
| 652 | let &mut (symbol, ref mut defined) = self.functions[func_id].as_mut().unwrap(); |
| 653 | if *defined { |
| 654 | return Err(ModuleError::DuplicateDefinition(decl_name.into_owned())); |
| 655 | } |
| 656 | *defined = true; |
| 657 | |
| 658 | let align = alignment.max(self.isa.symbol_alignment()); |
| 659 | let section = if self.per_function_section { |
| 660 | // FIXME pass empty symbol name once add_subsection produces `.text` as section name |
| 661 | // instead of `.text.` when passed an empty symbol name. (object#748) Until then pass |
| 662 | // `subsection` to produce `.text.subsection` as section name to reduce confusion. |
| 663 | self.object |
| 664 | .add_subsection(StandardSection::Text, b"subsection") |
| 665 | } else { |
| 666 | self.object.section_id(StandardSection::Text) |
| 667 | }; |
| 668 | let offset = self.object.add_symbol_data(symbol, section, bytes, align); |
| 669 | |
| 670 | if !relocs.is_empty() { |
| 671 | self.relocs.push(SymbolRelocs { |
| 672 | section, |
| 673 | offset, |
| 674 | relocs, |
| 675 | }); |
| 676 | } |
| 677 | |
| 678 | Ok(()) |
| 679 | } |
| 680 | |
| 681 | /// Finalize all relocations and output an object. |
| 682 | pub fn finish(mut self) -> ObjectProduct { |
no test coverage detected