authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-02 15:07:45+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:03+02:00
log43406c0696cd164c4da4d893d54390f21a42f0b0
treeb86dfbaa07a86eb65918c1f0a1b028126e7a9b08
parentd06aa21e484e891db208003d9814499586d80006

elf: update .strtab with GOT symbols


2 files changed, 22 insertions(+), 0 deletions(-)

src/link/Elf.zig+5
......@@ -3503,6 +3503,11 @@ fn updateSyntheticSectionSizes(self: *Elf) !void {
35033503 try self.updateSymtabSize();
35043504 }
35053505 if (self.strtab_section_index) |index| {
3506 // TODO I don't really this here but we need it to add symbol names from GOT and other synthetic
3507 // sections into .strtab for easier debugging.
3508 if (self.got_section_index) |_| {
3509 try self.got.updateStrtab(self);
3510 }
35063511 try self.growNonAllocSection(index, self.strtab.buffer.items.len, 1, false);
35073512 }
35083513 if (self.shstrtab_section_index) |index| {
src/link/Elf/synthetic_sections.zig+17
......@@ -376,6 +376,23 @@ pub const GotSection = struct {
376376 got.output_symtab_size.nlocals = @as(u32, @intCast(got.entries.items.len));
377377 }
378378
379 pub fn updateStrtab(got: GotSection, elf_file: *Elf) !void {
380 const gpa = elf_file.base.allocator;
381 for (got.entries.items) |entry| {
382 const suffix = switch (entry.tag) {
383 .tlsld => "$tlsld",
384 .tlsgd => "$tlsgd",
385 .got => "$got",
386 .gottp => "$gottp",
387 .tlsdesc => "$tlsdesc",
388 };
389 const symbol = elf_file.symbol(entry.symbol_index);
390 const name = try std.fmt.allocPrint(gpa, "{s}{s}", .{ symbol.name(elf_file), suffix });
391 defer gpa.free(name);
392 _ = try elf_file.strtab.insert(gpa, name);
393 }
394 }
395
379396 pub fn writeSymtab(got: GotSection, elf_file: *Elf, ctx: anytype) !void {
380397 const gpa = elf_file.base.allocator;
381398 for (got.entries.items, ctx.ilocal..) |entry, ilocal| {