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 {...@@ -4819,15 +4819,12 @@ fn updateSymtabSize(self: *Elf) !void {
4819 const gpa = self.base.allocator;4819 const gpa = self.base.allocator;
4820 var files = std.ArrayList(File.Index).init(gpa);4820 var files = std.ArrayList(File.Index).init(gpa);
4821 defer files.deinit();4821 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
4824 if (self.zig_object_index) |index| files.appendAssumeCapacity(index);4824 if (self.zig_object_index) |index| files.appendAssumeCapacity(index);
4825 for (self.objects.items) |index| {4825 for (self.objects.items) |index| files.appendAssumeCapacity(index);
4826 files.appendAssumeCapacity(index);4826 for (self.shared_objects.items) |index| files.appendAssumeCapacity(index);
4827 }4827 if (self.linker_defined_index) |index| files.appendAssumeCapacity(index);
4828 for (self.shared_objects.items) |index| {
4829 files.appendAssumeCapacity(index);
4830 }
48314828
4832 // Section symbols4829 // Section symbols
4833 for (self.output_sections.keys()) |_| {4830 for (self.output_sections.keys()) |_| {
...@@ -5166,6 +5163,11 @@ fn writeSymtab(self: *Elf) !void {...@@ -5166,6 +5163,11 @@ fn writeSymtab(self: *Elf) !void {
5166 file_ptr.writeSymtab(self);5163 file_ptr.writeSymtab(self);
5167 }5164 }
51685165
5166 if (self.linker_defined_index) |index| {
5167 const file_ptr = self.file(index).?;
5168 file_ptr.writeSymtab(self);
5169 }
5170
5169 if (self.zig_got_section_index) |_| {5171 if (self.zig_got_section_index) |_| {
5170 self.zig_got.writeSymtab(self);5172 self.zig_got.writeSymtab(self);
5171 }5173 }
...@@ -5182,11 +5184,6 @@ fn writeSymtab(self: *Elf) !void {...@@ -5182,11 +5184,6 @@ fn writeSymtab(self: *Elf) !void {
5182 self.plt_got.writeSymtab(self);5184 self.plt_got.writeSymtab(self);
5183 }5185 }
51845186
5185 if (self.linker_defined_index) |index| {
5186 const file_ptr = self.file(index).?;
5187 file_ptr.writeSymtab(self);
5188 }
5189
5190 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();5187 const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian();
5191 switch (self.ptr_width) {5188 switch (self.ptr_width) {
5192 .p32 => {5189 .p32 => {
src/link/Elf/synthetic_sections.zig+2-6
...@@ -917,8 +917,7 @@ pub const PltSection = struct {...@@ -917,8 +917,7 @@ pub const PltSection = struct {
917 }917 }
918918
919 pub fn writeSymtab(plt: PltSection, elf_file: *Elf) void {919 pub fn writeSymtab(plt: PltSection, elf_file: *Elf) void {
920 var ilocal = plt.output_symtab_ctx.ilocal;920 for (plt.symbols.items, plt.output_symtab_ctx.ilocal..) |sym_index, ilocal| {
921 for (plt.symbols.items) |sym_index| {
922 const sym = elf_file.symbol(sym_index);921 const sym = elf_file.symbol(sym_index);
923 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));922 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));
924 elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file));923 elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file));
...@@ -932,7 +931,6 @@ pub const PltSection = struct {...@@ -932,7 +931,6 @@ pub const PltSection = struct {
932 .st_value = sym.pltAddress(elf_file),931 .st_value = sym.pltAddress(elf_file),
933 .st_size = 16,932 .st_size = 16,
934 };933 };
935 ilocal += 1;
936 }934 }
937 }935 }
938936
...@@ -1046,8 +1044,7 @@ pub const PltGotSection = struct {...@@ -1046,8 +1044,7 @@ pub const PltGotSection = struct {
1046 }1044 }
10471045
1048 pub fn writeSymtab(plt_got: PltGotSection, elf_file: *Elf) void {1046 pub fn writeSymtab(plt_got: PltGotSection, elf_file: *Elf) void {
1049 var ilocal = plt_got.output_symtab_ctx.ilocal;1047 for (plt_got.symbols.items, plt_got.output_symtab_ctx.ilocal..) |sym_index, ilocal| {
1050 for (plt_got.symbols.items) |sym_index| {
1051 const sym = elf_file.symbol(sym_index);1048 const sym = elf_file.symbol(sym_index);
1052 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));1049 const st_name = @as(u32, @intCast(elf_file.strtab.items.len));
1053 elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file));1050 elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file));
...@@ -1061,7 +1058,6 @@ pub const PltGotSection = struct {...@@ -1061,7 +1058,6 @@ pub const PltGotSection = struct {
1061 .st_value = sym.pltGotAddress(elf_file),1058 .st_value = sym.pltGotAddress(elf_file),
1062 .st_size = 16,1059 .st_size = 16,
1063 };1060 };
1064 ilocal += 1;
1065 }1061 }
1066 }1062 }
1067};1063};