| ... | @@ -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 | } |
| 689 | | 689 | |
| 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); |
| 694 | | 697 | |
| 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); |
| 734 | | 737 | |
| 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); |
| 737 | | 743 | |
| 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 { |
| 896 | | 902 | |
| 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 Name | 905 | \\ Offset Type Symbol -> Sect Name |
| 900 | \\ | 906 | \\ |
| 901 | , .{ section_i + 1, section.name, obj_name }); | 907 | , .{ section_i + 1, section.name, obj_name }); |
| 902 | | 908 | |
| ... | @@ -921,14 +927,19 @@ const coff = struct { | ... | @@ -921,14 +927,19 @@ const coff = struct { |
| 921 | }, | 927 | }, |
| 922 | } | 928 | } |
| 923 | | 929 | |
| 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 | ); |
| 930 | | 936 | |
| 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 | } |