| ... | @@ -112,7 +112,6 @@ zig_data_section_index: ?u16 = null, | ... | @@ -112,7 +112,6 @@ zig_data_section_index: ?u16 = null, |
| 112 | zig_data_rela_section_index: ?u16 = null, | 112 | zig_data_rela_section_index: ?u16 = null, |
| 113 | zig_bss_section_index: ?u16 = null, | 113 | zig_bss_section_index: ?u16 = null, |
| 114 | zig_got_section_index: ?u16 = null, | 114 | zig_got_section_index: ?u16 = null, |
| 115 | zig_got_rela_section_index: ?u16 = null, | | |
| 116 | | 115 | |
| 117 | debug_info_section_index: ?u16 = null, | 116 | debug_info_section_index: ?u16 = null, |
| 118 | debug_abbrev_section_index: ?u16 = null, | 117 | debug_abbrev_section_index: ?u16 = null, |
| ... | @@ -612,8 +611,7 @@ pub fn initMetadata(self: *Elf) !void { | ... | @@ -612,8 +611,7 @@ pub fn initMetadata(self: *Elf) !void { |
| 612 | try self.last_atom_and_free_list_table.putNoClobber(gpa, self.zig_text_section_index.?, .{}); | 611 | try self.last_atom_and_free_list_table.putNoClobber(gpa, self.zig_text_section_index.?, .{}); |
| 613 | } | 612 | } |
| 614 | | 613 | |
| 615 | if (self.zig_got_section_index == null) { | 614 | if (self.zig_got_section_index == null and !self.isObject()) { |
| 616 | // TODO we don't actually need this section in a relocatable object file | | |
| 617 | self.zig_got_section_index = try self.addSection(.{ | 615 | self.zig_got_section_index = try self.addSection(.{ |
| 618 | .name = ".got.zig", | 616 | .name = ".got.zig", |
| 619 | .type = elf.SHT_PROGBITS, | 617 | .type = elf.SHT_PROGBITS, |
| ... | @@ -622,18 +620,11 @@ pub fn initMetadata(self: *Elf) !void { | ... | @@ -622,18 +620,11 @@ pub fn initMetadata(self: *Elf) !void { |
| 622 | .offset = std.math.maxInt(u64), | 620 | .offset = std.math.maxInt(u64), |
| 623 | }); | 621 | }); |
| 624 | const shdr = &self.shdrs.items[self.zig_got_section_index.?]; | 622 | const shdr = &self.shdrs.items[self.zig_got_section_index.?]; |
| 625 | fillSection( | 623 | const phndx = self.phdr_zig_got_index.?; |
| 626 | self, | 624 | const phdr = self.phdrs.items[phndx]; |
| 627 | shdr, | 625 | shdr.sh_addr = phdr.p_vaddr; |
| 628 | @as(u64, ptr_size) * self.base.options.symbol_count_hint, | 626 | shdr.sh_offset = phdr.p_offset; |
| 629 | self.phdr_zig_got_index, | 627 | shdr.sh_size = phdr.p_memsz; |
| 630 | ); | | |
| 631 | if (self.isObject()) { | | |
| 632 | self.zig_got_rela_section_index = try self.addRelaShdr( | | |
| 633 | ".rela.got.zig", | | |
| 634 | self.zig_got_section_index.?, | | |
| 635 | ); | | |
| 636 | } | | |
| 637 | } | 628 | } |
| 638 | | 629 | |
| 639 | if (self.zig_data_rel_ro_section_index == null) { | 630 | if (self.zig_data_rel_ro_section_index == null) { |
| ... | @@ -3701,7 +3692,6 @@ fn sortShdrs(self: *Elf) !void { | ... | @@ -3701,7 +3692,6 @@ fn sortShdrs(self: *Elf) !void { |
| 3701 | &self.zig_text_section_index, | 3692 | &self.zig_text_section_index, |
| 3702 | &self.zig_text_rela_section_index, | 3693 | &self.zig_text_rela_section_index, |
| 3703 | &self.zig_got_section_index, | 3694 | &self.zig_got_section_index, |
| 3704 | &self.zig_got_rela_section_index, | | |
| 3705 | &self.zig_data_rel_ro_section_index, | 3695 | &self.zig_data_rel_ro_section_index, |
| 3706 | &self.zig_data_rel_ro_rela_section_index, | 3696 | &self.zig_data_rel_ro_rela_section_index, |
| 3707 | &self.zig_data_section_index, | 3697 | &self.zig_data_section_index, |
| ... | @@ -3766,7 +3756,6 @@ fn sortShdrs(self: *Elf) !void { | ... | @@ -3766,7 +3756,6 @@ fn sortShdrs(self: *Elf) !void { |
| 3766 | | 3756 | |
| 3767 | for (&[_]?u16{ | 3757 | for (&[_]?u16{ |
| 3768 | self.zig_text_rela_section_index, | 3758 | self.zig_text_rela_section_index, |
| 3769 | self.zig_got_rela_section_index, | | |
| 3770 | self.zig_data_rel_ro_rela_section_index, | 3759 | self.zig_data_rel_ro_rela_section_index, |
| 3771 | self.zig_data_rela_section_index, | 3760 | self.zig_data_rela_section_index, |
| 3772 | }) |maybe_index| { | 3761 | }) |maybe_index| { |
| ... | @@ -3776,6 +3765,20 @@ fn sortShdrs(self: *Elf) !void { | ... | @@ -3776,6 +3765,20 @@ fn sortShdrs(self: *Elf) !void { |
| 3776 | shdr.sh_info = backlinks[shdr.sh_info]; | 3765 | shdr.sh_info = backlinks[shdr.sh_info]; |
| 3777 | } | 3766 | } |
| 3778 | | 3767 | |
| | 3768 | { |
| | 3769 | var last_atom_and_free_list_table = try self.last_atom_and_free_list_table.clone(gpa); |
| | 3770 | defer last_atom_and_free_list_table.deinit(gpa); |
| | 3771 | |
| | 3772 | self.last_atom_and_free_list_table.clearRetainingCapacity(); |
| | 3773 | |
| | 3774 | var it = last_atom_and_free_list_table.iterator(); |
| | 3775 | while (it.next()) |entry| { |
| | 3776 | const shndx = entry.key_ptr.*; |
| | 3777 | const meta = entry.value_ptr.*; |
| | 3778 | self.last_atom_and_free_list_table.putAssumeCapacityNoClobber(backlinks[shndx], meta); |
| | 3779 | } |
| | 3780 | } |
| | 3781 | |
| 3779 | { | 3782 | { |
| 3780 | var phdr_to_shdr_table = try self.phdr_to_shdr_table.clone(gpa); | 3783 | var phdr_to_shdr_table = try self.phdr_to_shdr_table.clone(gpa); |
| 3781 | defer phdr_to_shdr_table.deinit(gpa); | 3784 | defer phdr_to_shdr_table.deinit(gpa); |
| ... | @@ -3832,6 +3835,10 @@ fn updateSectionSizes(self: *Elf) !void { | ... | @@ -3832,6 +3835,10 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3832 | } | 3835 | } |
| 3833 | } | 3836 | } |
| 3834 | | 3837 | |
| | 3838 | if (self.zigObjectPtr()) |zig_object| { |
| | 3839 | zig_object.updateRelaSectionSizes(self); |
| | 3840 | } |
| | 3841 | |
| 3835 | if (self.eh_frame_section_index) |index| { | 3842 | if (self.eh_frame_section_index) |index| { |
| 3836 | self.shdrs.items[index].sh_size = try eh_frame.calcEhFrameSize(self); | 3843 | self.shdrs.items[index].sh_size = try eh_frame.calcEhFrameSize(self); |
| 3837 | } | 3844 | } |