authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-15 15:07:09+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-15 15:07:09+01:00
log760ce69734e8c6fca02356c53729909ccb5d8ff9
treef9e0348529eab5458b6db4407aaefe381ef7f711
parent0c6cb8d8c80f0a316a77eddfebaa42cb77c8bf7d

elf: actually write synthetic globals to output symtab


2 files changed, 11 insertions(+), 18 deletions(-)

src/link/Elf.zig+9-12
......@@ -4819,15 +4819,12 @@ fn updateSymtabSize(self: *Elf) !void {
48194819 const gpa = self.base.allocator;
48204820 var files = std.ArrayList(File.Index).init(gpa);
48214821 defer files.deinit();
4822 try files.ensureTotalCapacityPrecise(self.objects.items.len + self.shared_objects.items.len + 1);
4822 try files.ensureTotalCapacityPrecise(self.objects.items.len + self.shared_objects.items.len + 2);
48234823
48244824 if (self.zig_object_index) |index| files.appendAssumeCapacity(index);
4825 for (self.objects.items) |index| {
4826 files.appendAssumeCapacity(index);
4827 }
4828 for (self.shared_objects.items) |index| {
4829 files.appendAssumeCapacity(index);
4830 }
4825 for (self.objects.items) |index| files.appendAssumeCapacity(index);
4826 for (self.shared_objects.items) |index| files.appendAssumeCapacity(index);
4827 if (self.linker_defined_index) |index| files.appendAssumeCapacity(index);
48314828
48324829 // Section symbols
48334830 for (self.output_sections.keys()) |_| {
......@@ -5166,6 +5163,11 @@ fn writeSymtab(self: *Elf) !void {
51665163 file_ptr.writeSymtab(self);
51675164 }
51685165
5166 if (self.linker_defined_index) |index| {
5167 const file_ptr = self.file(index).?;
5168 file_ptr.writeSymtab(self);
5169 }
5170
51695171 if (self.zig_got_section_index) |_| {
51705172 self.zig_got.writeSymtab(self);
51715173 }
......@@ -5182,11 +5184,6 @@ fn writeSymtab(self: *Elf) !void {
51825184 self.plt_got.writeSymtab(self);
51835185 }
51845186
5185 if (self.linker_defined_index) |index| {
5186 const file_ptr = self.file(index).?;
5187 file_ptr.writeSymtab(self);
5188 }
5189
51905187 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
51915188 switch (self.ptr_width) {
51925189 .p32 => {
src/link/Elf/synthetic_sections.zig+2-6
......@@ -917,8 +917,7 @@ pub const PltSection = struct {
917917 }
918918
919919 pub fn writeSymtab(plt: PltSection, elf_file: *Elf) void {
920 var ilocal = plt.output_symtab_ctx.ilocal;
921 for (plt.symbols.items) |sym_index| {
920 for (plt.symbols.items, plt.output_symtab_ctx.ilocal..) |sym_index, ilocal| {
922921 const sym = elf_file.symbol(sym_index);
923922 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));
924923 elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file));
......@@ -932,7 +931,6 @@ pub const PltSection = struct {
932931 .st_value = sym.pltAddress(elf_file),
933932 .st_size = 16,
934933 };
935 ilocal += 1;
936934 }
937935 }
938936
......@@ -1046,8 +1044,7 @@ pub const PltGotSection = struct {
10461044 }
10471045
10481046 pub fn writeSymtab(plt_got: PltGotSection, elf_file: *Elf) void {
1049 var ilocal = plt_got.output_symtab_ctx.ilocal;
1050 for (plt_got.symbols.items) |sym_index| {
1047 for (plt_got.symbols.items, plt_got.output_symtab_ctx.ilocal..) |sym_index, ilocal| {
10511048 const sym = elf_file.symbol(sym_index);
10521049 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));
10531050 elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file));
......@@ -1061,7 +1058,6 @@ pub const PltGotSection = struct {
10611058 .st_value = sym.pltGotAddress(elf_file),
10621059 .st_size = 16,
10631060 };
1064 ilocal += 1;
10651061 }
10661062 }
10671063};