elf: dump PLT entries

This commit is contained in:
Jakub Konka 2023-11-12 10:29:13 +01:00 committed by Jacob Young
parent 984c598590
commit 0dab319e86
2 changed files with 32 additions and 1 deletions

View File

@ -6265,8 +6265,9 @@ fn fmtDumpState(
try writer.print("linker_defined({d}) : (linker defined)\n", .{index});
try writer.print("{}\n", .{linker_defined.fmtSymtab(self)});
}
try writer.print("{}\n", .{self.got.fmt(self)});
try writer.print("{}\n", .{self.zig_got.fmt(self)});
try writer.print("{}\n", .{self.got.fmt(self)});
try writer.print("{}\n", .{self.plt.fmt(self)});
try writer.writeAll("Output COMDAT groups\n");
for (self.comdat_group_sections.items) |cg| {

View File

@ -935,6 +935,36 @@ pub const PltSection = struct {
ilocal += 1;
}
}
const FormatCtx = struct {
plt: PltSection,
elf_file: *Elf,
};
pub fn fmt(plt: PltSection, elf_file: *Elf) std.fmt.Formatter(format2) {
return .{ .data = .{ .plt = plt, .elf_file = elf_file } };
}
pub fn format2(
ctx: FormatCtx,
comptime unused_fmt_string: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = options;
_ = unused_fmt_string;
try writer.writeAll("PLT\n");
for (ctx.plt.symbols.items, 0..) |symbol_index, i| {
const symbol = ctx.elf_file.symbol(symbol_index);
try writer.print(" {d}@0x{x} => {d}@0x{x} ({s})\n", .{
i,
symbol.pltAddress(ctx.elf_file),
symbol_index,
symbol.address(.{}, ctx.elf_file),
symbol.name(ctx.elf_file),
});
}
}
};
pub const GotPltSection = struct {