authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:34-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:22:42-04:00
loga4b1a3a0b367912720122791f02289ea4a69cb84
treed90cf1164cb4d71b49ad3fb4de77d8abee5093b4
parentd8f23c57aaf70f9dcee25620f79c8a6d5512eaae

Coff: more work on inputs

- Fixup undefined symbol notes when there was a single one - Fixup undefined symbols being added to the linker members - Fix string table alignment causing resizes to add extra bytes (which were not correctly zeroed out)

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

src/link/Coff.zig+7-7
...@@ -1707,7 +1707,6 @@ fn initHeaders(...@@ -1707,7 +1707,6 @@ fn initHeaders(
1707 coff.nodes.appendAssumeCapacity(.symbol_table);1707 coff.nodes.appendAssumeCapacity(.symbol_table);
17081708
1709 coff.symbol_table.strings_ni = try coff.mf.addLastChildNode(gpa, zcu_coff_parent_ni, .{1709 coff.symbol_table.strings_ni = try coff.mf.addLastChildNode(gpa, zcu_coff_parent_ni, .{
1710 .alignment = .@"2",
1711 .size = @sizeOf(u32),1710 .size = @sizeOf(u32),
1712 .fixed = true,1711 .fixed = true,
1713 .resized = true,1712 .resized = true,
...@@ -2114,7 +2113,7 @@ pub fn symbolTableSectionAuxEntryPtr(coff: *Coff, si: Symbol.Index) *align(2) st...@@ -2114,7 +2113,7 @@ pub fn symbolTableSectionAuxEntryPtr(coff: *Coff, si: Symbol.Index) *align(2) st
2114 return @ptrCast(@alignCast(symbolTableEntryStoragePtr(coff, sti.unwrap().? + 1)));2113 return @ptrCast(@alignCast(symbolTableEntryStoragePtr(coff, sti.unwrap().? + 1)));
2115}2114}
21162115
2117pub fn symbolTableStringLenPtr(coff: *Coff) *align(2) u32 {2116pub fn symbolTableStringLenPtr(coff: *Coff) *align(1) u32 {
2118 return @ptrCast(@alignCast(coff.symbol_table.strings_ni.slice(&coff.mf)[0..@sizeOf(u32)]));2117 return @ptrCast(@alignCast(coff.symbol_table.strings_ni.slice(&coff.mf)[0..@sizeOf(u32)]));
2119}2118}
21202119
...@@ -3483,7 +3482,7 @@ fn loadObject(...@@ -3483,7 +3482,7 @@ fn loadObject(
3483 });3482 });
34843483
3485 if (is_archive) {3484 if (is_archive) {
3486 if (symbol.storage_class == .EXTERNAL)3485 if (symbol.storage_class == .EXTERNAL and symbol.section_number != .UNDEFINED)
3487 try coff.ensureMemberSymbol(mi, coff.getOrPutStringAssumeCapacity(name));3486 try coff.ensureMemberSymbol(mi, coff.getOrPutStringAssumeCapacity(name));
34883487
3489 continue;3488 continue;
...@@ -4042,7 +4041,6 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {...@@ -4042,7 +4041,6 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {
4042 num_unique_references = 1;4041 num_unique_references = 1;
4043 }4042 }
40444043
4045 const num_references = i - start_i;
4046 const num_notes =4044 const num_notes =
4047 @min(max_notes, num_unique_references) +4045 @min(max_notes, num_unique_references) +
4048 @intFromBool(num_unique_references > max_notes);4046 @intFromBool(num_unique_references > max_notes);
...@@ -4052,7 +4050,7 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {...@@ -4052,7 +4050,7 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {
4052 try err.addMsg("undefined symbol: {s}", .{target_sym.gmi.globalName(coff).name.toSlice(coff)});4050 try err.addMsg("undefined symbol: {s}", .{target_sym.gmi.globalName(coff).name.toSlice(coff)});
40534051
4054 var prev_loc_si: Symbol.Index = .null;4052 var prev_loc_si: Symbol.Index = .null;
4055 for (undef_indices.items[start_i..][0..num_references]) |reference_i| {4053 for (undef_indices.items[start_i..][0..@max(1, i - start_i)]) |reference_i| {
4056 if (err.note_slot == num_notes) break;4054 if (err.note_slot == num_notes) break;
40574055
4058 const loc_si = coff.relocs.items[reference_i].loc;4056 const loc_si = coff.relocs.items[reference_i].loc;
...@@ -4109,7 +4107,7 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {...@@ -4109,7 +4107,7 @@ fn reportUndefs(coff: *Coff, tid: Zcu.PerThread.Id) !void {
4109 }4107 }
41104108
4111 if (num_unique_references > max_notes)4109 if (num_unique_references > max_notes)
4112 err.addNote("referenced {d} more times", .{num_references - max_notes});4110 err.addNote("referenced {d} more times", .{num_unique_references - max_notes});
4113 } else if (i != start_i and4111 } else if (i != start_i and
4114 coff.relocs.items[undef_indices.items[i - 1]].loc != coff.relocs.items[undef_indices.items[i]].loc)4112 coff.relocs.items[undef_indices.items[i - 1]].loc != coff.relocs.items[undef_indices.items[i]].loc)
4115 {4113 {
...@@ -4129,7 +4127,9 @@ pub fn flush(...@@ -4129,7 +4127,9 @@ pub fn flush(
4129 _ = arena;4127 _ = arena;
4130 _ = prog_node;4128 _ = prog_node;
4131 while (try coff.idle(tid)) {}4129 while (try coff.idle(tid)) {}
4132 try coff.reportUndefs(tid);4130
4131 if (coff.isImage())
4132 try coff.reportUndefs(tid);
41334133
4134 const comp = coff.base.comp;4134 const comp = coff.base.comp;
41354135