elf: update .strtab with GOT symbols

This commit is contained in:
Jakub Konka 2023-10-02 15:07:45 +02:00
parent d06aa21e48
commit 43406c0696
2 changed files with 22 additions and 0 deletions

View File

@ -3503,6 +3503,11 @@ fn updateSyntheticSectionSizes(self: *Elf) !void {
try self.updateSymtabSize();
}
if (self.strtab_section_index) |index| {
// TODO I don't really this here but we need it to add symbol names from GOT and other synthetic
// sections into .strtab for easier debugging.
if (self.got_section_index) |_| {
try self.got.updateStrtab(self);
}
try self.growNonAllocSection(index, self.strtab.buffer.items.len, 1, false);
}
if (self.shstrtab_section_index) |index| {

View File

@ -376,6 +376,23 @@ pub const GotSection = struct {
got.output_symtab_size.nlocals = @as(u32, @intCast(got.entries.items.len));
}
pub fn updateStrtab(got: GotSection, elf_file: *Elf) !void {
const gpa = elf_file.base.allocator;
for (got.entries.items) |entry| {
const suffix = switch (entry.tag) {
.tlsld => "$tlsld",
.tlsgd => "$tlsgd",
.got => "$got",
.gottp => "$gottp",
.tlsdesc => "$tlsdesc",
};
const symbol = elf_file.symbol(entry.symbol_index);
const name = try std.fmt.allocPrint(gpa, "{s}{s}", .{ symbol.name(elf_file), suffix });
defer gpa.free(name);
_ = try elf_file.strtab.insert(gpa, name);
}
}
pub fn writeSymtab(got: GotSection, elf_file: *Elf, ctx: anytype) !void {
const gpa = elf_file.base.allocator;
for (got.entries.items, ctx.ilocal..) |entry, ilocal| {