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 {...@@ -687,10 +687,13 @@ const coff = struct {
687 if (opts.section_headers) try w.writeByte('\n');687 if (opts.section_headers) try w.writeByte('\n');
688 }688 }
689689
690 var symbol_names: std.ArrayList([]const u8) = .empty;690 var symbols: std.ArrayList(struct {
691 defer symbol_names.deinit(gpa);691 name: []const u8,
692 section_number: std.coff.SectionNumber,
693 }) = .empty;
694 defer symbols.deinit(gpa);
692 if (opts.relocs)695 if (opts.relocs)
693 try symbol_names.ensureUnusedCapacity(gpa, header.number_of_symbols);696 try symbols.ensureUnusedCapacity(gpa, header.number_of_symbols);
694697
695 if (opts.symbols or opts.relocs) {698 if (opts.symbols or opts.relocs) {
696 if (header.pointer_to_symbol_table > 0) {699 if (header.pointer_to_symbol_table > 0) {
...@@ -733,7 +736,10 @@ const coff = struct {...@@ -733,7 +736,10 @@ const coff = struct {
733 } else &symbol.name, 0);736 } else &symbol.name, 0);
734737
735 if (opts.relocs)738 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
738 if (!opts.symbols)744 if (!opts.symbols)
739 continue;745 continue;
...@@ -896,7 +902,7 @@ const coff = struct {...@@ -896,7 +902,7 @@ const coff = struct {
896902
897 try w.print(903 try w.print(
898 \\Relocs for section {x} '{s}' in {s}:904 \\Relocs for section {x} '{s}' in {s}:
899 \\ Offset Type Symbol Name905 \\ Offset Type Symbol -> Sect Name
900 \\906 \\
901 , .{ section_i + 1, section.name, obj_name });907 , .{ section_i + 1, section.name, obj_name });
902908
...@@ -921,14 +927,19 @@ const coff = struct {...@@ -921,14 +927,19 @@ const coff = struct {
921 },927 },
922 }928 }
923929
924 if (reloc.symbol_table_index >= symbol_names.items.len)930 if (reloc.symbol_table_index >= symbols.items.len)
925 return failParse(931 return failParse(
926 opts,932 opts,
927 "reloc {x} in section {x} has out-of-bounds symbol index {x}",933 "reloc {x} in section {x} has out-of-bounds symbol index {x}",
928 .{ reloc_i, section_i + 1, reloc.symbol_table_index },934 .{ reloc_i, section_i + 1, reloc.symbol_table_index },
929 );935 );
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});
932 }943 }
933 try w.writeByte('\n');944 try w.writeByte('\n');
934 }945 }