mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 05:20:34 +00:00
elf: update .strtab with GOT symbols
This commit is contained in:
parent
d06aa21e48
commit
43406c0696
@ -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| {
|
||||
|
||||
@ -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| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user