Finalize all relocations and output an object.
(mut self)
| 680 | |
| 681 | /// Finalize all relocations and output an object. |
| 682 | pub fn finish(mut self) -> ObjectProduct { |
| 683 | if cfg!(debug_assertions) { |
| 684 | for (func_id, decl) in self.declarations.get_functions() { |
| 685 | if !decl.linkage.requires_definition() { |
| 686 | continue; |
| 687 | } |
| 688 | |
| 689 | assert!( |
| 690 | self.functions[func_id].unwrap().1, |
| 691 | "function \"{}\" with linkage {:?} must be defined but is not", |
| 692 | decl.linkage_name(func_id), |
| 693 | decl.linkage, |
| 694 | ); |
| 695 | } |
| 696 | |
| 697 | for (data_id, decl) in self.declarations.get_data_objects() { |
| 698 | if !decl.linkage.requires_definition() { |
| 699 | continue; |
| 700 | } |
| 701 | |
| 702 | assert!( |
| 703 | self.data_objects[data_id].unwrap().1, |
| 704 | "data object \"{}\" with linkage {:?} must be defined but is not", |
| 705 | decl.linkage_name(data_id), |
| 706 | decl.linkage, |
| 707 | ); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | let symbol_relocs = mem::take(&mut self.relocs); |
| 712 | for symbol in symbol_relocs { |
| 713 | for &ObjectRelocRecord { |
| 714 | offset, |
| 715 | ref name, |
| 716 | flags, |
| 717 | addend, |
| 718 | } in &symbol.relocs |
| 719 | { |
| 720 | let target_symbol = self.get_symbol(name); |
| 721 | self.object |
| 722 | .add_relocation( |
| 723 | symbol.section, |
| 724 | Relocation { |
| 725 | offset: symbol.offset + u64::from(offset), |
| 726 | flags, |
| 727 | symbol: target_symbol, |
| 728 | addend, |
| 729 | }, |
| 730 | ) |
| 731 | .unwrap(); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | // Indicate that this object has a non-executable stack. |
| 736 | if self.object.format() == object::BinaryFormat::Elf { |
| 737 | self.object.add_section( |
| 738 | vec![], |
| 739 | ".note.GNU-stack".as_bytes().to_vec(), |
nothing calls this directly
no test coverage detected