authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:36-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:26:57-04:00
log32377bb73cc70dfd141629eef0e5238b5debeb57
treed5de66e93459c41e8b0783c5029b4df344a1b54c
parent815ef725235cd4f5f0caed906bfe868225994f89

objdump: show section number in relocation table


1 files changed, 18 insertions(+), 7 deletions(-)

lib/compiler/objdump.zig+18-7
......@@ -687,10 +687,13 @@ const coff = struct {
687687 if (opts.section_headers) try w.writeByte('\n');
688688 }
689689
690 var symbol_names: std.ArrayList([]const u8) = .empty;
691 defer symbol_names.deinit(gpa);
690 var symbols: std.ArrayList(struct {
691 name: []const u8,
692 section_number: std.coff.SectionNumber,
693 }) = .empty;
694 defer symbols.deinit(gpa);
692695 if (opts.relocs)
693 try symbol_names.ensureUnusedCapacity(gpa, header.number_of_symbols);
696 try symbols.ensureUnusedCapacity(gpa, header.number_of_symbols);
694697
695698 if (opts.symbols or opts.relocs) {
696699 if (header.pointer_to_symbol_table > 0) {
......@@ -733,7 +736,10 @@ const coff = struct {
733736 } else &symbol.name, 0);
734737
735738 if (opts.relocs)
736 symbol_names.appendNTimesAssumeCapacity(name, 1 + symbol.number_of_aux_symbols);
739 symbols.appendNTimesAssumeCapacity(.{
740 .name = name,
741 .section_number = symbol.section_number,
742 }, 1 + symbol.number_of_aux_symbols);
737743
738744 if (!opts.symbols)
739745 continue;
......@@ -896,7 +902,7 @@ const coff = struct {
896902
897903 try w.print(
898904 \\Relocs for section {x} '{s}' in {s}:
899 \\ Offset Type Symbol Name
905 \\ Offset Type Symbol -> Sect Name
900906 \\
901907 , .{ section_i + 1, section.name, obj_name });
902908
......@@ -921,14 +927,19 @@ const coff = struct {
921927 },
922928 }
923929
924 if (reloc.symbol_table_index >= symbol_names.items.len)
930 if (reloc.symbol_table_index >= symbols.items.len)
925931 return failParse(
926932 opts,
927933 "reloc {x} in section {x} has out-of-bounds symbol index {x}",
928934 .{ reloc_i, section_i + 1, reloc.symbol_table_index },
929935 );
930936
931 try w.print("{x: >8} | {s}\n", .{ reloc.symbol_table_index, symbol_names.items[reloc.symbol_table_index] });
937 try w.print("{x: >8} ", .{reloc.symbol_table_index});
938
939 const sym = &symbols.items[reloc.symbol_table_index];
940 try sectionNumberString(sym.section_number, w);
941
942 try w.print(" | {s}\n", .{sym.name});
932943 }
933944 try w.writeByte('\n');
934945 }