authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-08 00:27:32-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:27:17-04:00
logc7bb3a39b781fdecb74ae8df0537516ed1d31826
tree0e3f0241210eac018076368b1683978973b1f4c9
parentc0b07b144bcce98c25c67d1f91e49d1cb92be1cd

Coff: TODO cleanup


1 files changed, 9 insertions(+), 24 deletions(-)

src/link/Coff.zig+9-24
...@@ -199,7 +199,7 @@ pub const Node = union(enum) {...@@ -199,7 +199,7 @@ pub const Node = union(enum) {
199 relocation_table: Symbol.SectionNumber,199 relocation_table: Symbol.SectionNumber,
200 relocation_table_entry: Reloc.Index,200 relocation_table_entry: Reloc.Index,
201201
202 image_section: Symbol.Index, // TODO: rename image_section -> section202 image_section: Symbol.Index,
203203
204 /// Images only204 /// Images only
205 import_directory_table,205 import_directory_table,
...@@ -603,7 +603,7 @@ pub const LongNamesTable = struct {...@@ -603,7 +603,7 @@ pub const LongNamesTable = struct {
603 coff: *Coff,603 coff: *Coff,
604604
605 pub fn eql(adapter: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {605 pub fn eql(adapter: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {
606 assert(adapter.coff.isArchive()); // TODO: move to helper that uses this606 assert(adapter.coff.isArchive());
607 const longnames_slice = Node.known.longnames_member.slice(&adapter.coff.mf);607 const longnames_slice = Node.known.longnames_member.slice(&adapter.coff.mf);
608 const rhs = adapter.coff.long_names_table.entries.values()[rhs_index];608 const rhs = adapter.coff.long_names_table.entries.values()[rhs_index];
609 return std.mem.eql(u8, longnames_slice[rhs.offset..][0..rhs.len], lhs_key);609 return std.mem.eql(u8, longnames_slice[rhs.offset..][0..rhs.len], lhs_key);
...@@ -763,7 +763,6 @@ pub const ImportTable = struct {...@@ -763,7 +763,6 @@ pub const ImportTable = struct {
763};763};
764764
765pub const String = enum(u32) {765pub const String = enum(u32) {
766 // TODO: Re-order
767 @".data" = 0,766 @".data" = 0,
768 @".idata" = 6,767 @".idata" = 6,
769 @".rdata" = 13,768 @".rdata" = 13,
...@@ -943,7 +942,6 @@ pub const Symbol = struct {...@@ -943,7 +942,6 @@ pub const Symbol = struct {
943 // The size of the symbol942 // The size of the symbol
944 size: u32,943 size: u32,
945 /// Only valid when .ni == .input_section and .value_tag == .node_offset944 /// Only valid when .ni == .input_section and .value_tag == .node_offset
946 /// TODO: This is only used for name lookups, could just be String, remove `input_symbols`?
947 isli: Node.InputSection.LocalIndex,945 isli: Node.InputSection.LocalIndex,
948 /// The next symbol in the list of aliases of this symbol.946 /// The next symbol in the list of aliases of this symbol.
949 next_alias_si: Symbol.Index,947 next_alias_si: Symbol.Index,
...@@ -2919,7 +2917,6 @@ fn addMemberAssumeCapacity(coff: *Coff, kind: std.coff.ArchiveMemberHeader.Kind,...@@ -2919,7 +2917,6 @@ fn addMemberAssumeCapacity(coff: *Coff, kind: std.coff.ArchiveMemberHeader.Kind,
2919 const gpa = comp.gpa;2917 const gpa = comp.gpa;
29202918
2921 // TODO: These two nodes could to be inside a movable node if kind == .coff|.import2919 // TODO: These two nodes could to be inside a movable node if kind == .coff|.import
2922
2923 const header_ni = try coff.mf.addLastChildNode(gpa, Node.known.file, .{2920 const header_ni = try coff.mf.addLastChildNode(gpa, Node.known.file, .{
2924 .size = @sizeOf(std.coff.ArchiveMemberHeader),2921 .size = @sizeOf(std.coff.ArchiveMemberHeader),
2925 .alignment = .@"2",2922 .alignment = .@"2",
...@@ -3573,7 +3570,6 @@ fn objectSectionMapIndex(...@@ -3573,7 +3570,6 @@ fn objectSectionMapIndex(
3573 return osmi;3570 return osmi;
3574}3571}
35753572
3576// TODO: Include align in attrs and verify the current align is >= requested
3577fn verifyParentSectionAttributes(3573fn verifyParentSectionAttributes(
3578 coff: *Coff,3574 coff: *Coff,
3579 parent: Symbol.SectionNumber,3575 parent: Symbol.SectionNumber,
...@@ -3727,7 +3723,7 @@ fn addRelocAssumeCapacity(...@@ -3727,7 +3723,7 @@ fn addRelocAssumeCapacity(
3727 if (coff.symbolTableSectionAuxEntryPtr(loc_sn.symbol(coff).sti(coff))) |aux_ptr|3723 if (coff.symbolTableSectionAuxEntryPtr(loc_sn.symbol(coff).sti(coff))) |aux_ptr|
3728 coff.targetStore(&aux_ptr.number_of_relocations, new_num_relocations);3724 coff.targetStore(&aux_ptr.number_of_relocations, new_num_relocations);
37293725
3730 // TODO: These need to allocate from a free list (once deleting relocs is supported) (or can we just remove swap?)3726 // TODO: These need to allocate from a free list, once deleting relocs is supported
3731 const sri: Section.RelocationIndex = .wrap(old_num_relocations);3727 const sri: Section.RelocationIndex = .wrap(old_num_relocations);
3732 const entry = sri.entry(coff, loc_sn).?;3728 const entry = sri.entry(coff, loc_sn).?;
3733 if (sti.unwrap()) |index| coff.targetStore(&entry.symbol_table_index, index);3729 if (sti.unwrap()) |index| coff.targetStore(&entry.symbol_table_index, index);
...@@ -4509,7 +4505,7 @@ fn loadObject(...@@ -4509,7 +4505,7 @@ fn loadObject(
4509 });4505 });
45104506
4511 // TODO: What if the same symbol is incorrectly defined twice in this obj?4507 // TODO: What if the same symbol is incorrectly defined twice in this obj?
4512 // TODO: Would need to mark this global as pending, or notice it later when .ni != none4508 // Would need to mark this global as pending, or notice it later when .ni != none
4513 if (!global_gop.found_existing or global_gop.value_ptr.get(coff).ni == .none) {4509 if (!global_gop.found_existing or global_gop.value_ptr.get(coff).ni == .none) {
4514 symbol.si = global_gop.value_ptr.*;4510 symbol.si = global_gop.value_ptr.*;
4515 break :comdat .include;4511 break :comdat .include;
...@@ -4554,9 +4550,7 @@ fn loadObject(...@@ -4554,9 +4550,7 @@ fn loadObject(
4554 const sym = si.get(coff);4550 const sym = si.get(coff);
4555 const existing_crc = switch (coff.getNode(sym.ni)) {4551 const existing_crc = switch (coff.getNode(sym.ni)) {
4556 .input_section => |isi| isi.inputSection(coff).crc,4552 .input_section => |isi| isi.inputSection(coff).crc,
4557 // TODO: Should this result be cached somewhere?4553 else => std.hash.crc.Crc32Jamcrc.hash(sym.ni.sliceConst(&coff.mf)),
4558 // TODO: Is this slice triggering has_content = true un-necessarily? Check section for init data flag.
4559 else => std.hash.crc.Crc32Jamcrc.hash(sym.ni.slice(&coff.mf)),
4560 };4554 };
45614555
4562 if (existing_crc == section.comdat_crc) {4556 if (existing_crc == section.comdat_crc) {
...@@ -4611,7 +4605,7 @@ fn loadObject(...@@ -4611,7 +4605,7 @@ fn loadObject(
4611 .pending => unreachable,4605 .pending => unreachable,
4612 }4606 }
46134607
4614 // TODO: Until we support sorting .pdata, we shouldn't merge these in, the result would be invalid4608 // Until we support sorting .pdata, we shouldn't merge these in, the result would be invalid
4615 const section_name = section.name.toSlice(coff);4609 const section_name = section.name.toSlice(coff);
4616 if (std.mem.startsWith(u8, section_name, ".pdata"))4610 if (std.mem.startsWith(u8, section_name, ".pdata"))
4617 continue;4611 continue;
...@@ -4995,7 +4989,6 @@ fn parseArchiveMemberHeader(...@@ -4995,7 +4989,6 @@ fn parseArchiveMemberHeader(
4995 };4989 };
4996}4990}
49974991
4998// TODO: Move to std.coff?
4999fn parseArchiveMemberHeaderInner(4992fn parseArchiveMemberHeaderInner(
5000 header: *const std.coff.ArchiveMemberHeader,4993 header: *const std.coff.ArchiveMemberHeader,
5001 opt_longnames: ?[]const u8,4994 opt_longnames: ?[]const u8,
...@@ -5274,7 +5267,6 @@ fn loadArchive(coff: *Coff, path: std.Build.Cache.Path, fr: *Io.File.Reader) Loa...@@ -5274,7 +5267,6 @@ fn loadArchive(coff: *Coff, path: std.Build.Cache.Path, fr: *Io.File.Reader) Loa
5274 };5267 };
5275 } else {5268 } else {
5276 member.content.object.size = res.size;5269 member.content.object.size = res.size;
5277 // TODO: If .UNKNOWN assert later that it contains no non-undef symbols?
5278 // Microsoft's CRT contains members that set .UNKNOWN but do have undef symbols5270 // Microsoft's CRT contains members that set .UNKNOWN but do have undef symbols
5279 if (machine != expected_machine and machine != .UNKNOWN) {5271 if (machine != expected_machine and machine != .UNKNOWN) {
5280 return diags.failParse(path, "machine mismatch in member header '{s}': expected {t}, found {t}", .{5272 return diags.failParse(path, "machine mismatch in member header '{s}': expected {t}, found {t}", .{
...@@ -5859,7 +5851,6 @@ pub fn flush(...@@ -5859,7 +5851,6 @@ pub fn flush(
5859 if (coff.isImage())5851 if (coff.isImage())
5860 try coff.reportUndefs(tid);5852 try coff.reportUndefs(tid);
58615853
5862 // Implib generation should instead be done via building a MappedFile progressively
5863 if (comp.emit_implib) |implib_file|5854 if (comp.emit_implib) |implib_file|
5864 coff.flushImplib(implib_file) catch |err|5855 coff.flushImplib(implib_file) catch |err|
5865 return comp.link_diags.fail("flushing implib '{s}' failed: {t}", .{ implib_file, err });5856 return comp.link_diags.fail("flushing implib '{s}' failed: {t}", .{ implib_file, err });
...@@ -6080,9 +6071,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6080,9 +6071,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6080 try coff.flushMember(pending_mi.key);6071 try coff.flushMember(pending_mi.key);
6081 break :task;6072 break :task;
6082 }6073 }
6083 // TODO: All the sort / shrink tasks ideally run only once - otherwise it's wasteful6074 if (coff.exports_complete and coff.export_table.pending_sort) {
6084 // Defer until exports_complete?
6085 if (coff.export_table.pending_sort) {
6086 defer coff.export_table.pending_sort = false;6075 defer coff.export_table.pending_sort = false;
6087 const sub_prog_node = coff.idleProgNode(6076 const sub_prog_node = coff.idleProgNode(
6088 tid,6077 tid,
...@@ -6098,7 +6087,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {...@@ -6098,7 +6087,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
6098 if (coff.input_sections.items.len > coff.input_section_pending_index) return true;6087 if (coff.input_sections.items.len > coff.input_section_pending_index) return true;
6099 if (coff.mf.updates.items.len > 0) return true;6088 if (coff.mf.updates.items.len > 0) return true;
6100 if (coff.pending_members.count() > 0) return true;6089 if (coff.pending_members.count() > 0) return true;
6101 if (coff.export_table.pending_sort) return true;6090 if (coff.exports_complete and coff.export_table.pending_sort) return true;
6102 return false;6091 return false;
6103}6092}
61046093
...@@ -6578,8 +6567,6 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool {...@@ -6578,8 +6567,6 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool {
6578 const iat_offset: u32 = @intCast(addr_info.size * iat_symbol_gop.value_ptr.*);6567 const iat_offset: u32 = @intCast(addr_info.size * iat_symbol_gop.value_ptr.*);
6579 switch (import.kind) {6568 switch (import.kind) {
6580 .iat_ptr => {6569 .iat_ptr => {
6581 // TODO: Currently the codegen is wrong for loading the address of these globals,
6582 // we generate lea [<iat_ptr>] when it should be mov [<iat_ptr>]
6583 const iat_sym = gop.value_ptr.import_address_table_si.get(coff);6570 const iat_sym = gop.value_ptr.import_address_table_si.get(coff);
6584 sym.section_number = iat_sym.section_number;6571 sym.section_number = iat_sym.section_number;
6585 sym.ni = iat_sym.ni;6572 sym.ni = iat_sym.ni;
...@@ -7166,7 +7153,6 @@ fn flushMember(coff: *Coff, mi: Member.Index) !void {...@@ -7166,7 +7153,6 @@ fn flushMember(coff: *Coff, mi: Member.Index) !void {
7166 };7153 };
71677154
7168 // TODO: Does this sort need to also sort by linker input order (if names equal)?7155 // TODO: Does this sort need to also sort by linker input order (if names equal)?
7169
7170 std.sort.pdqContext(0, coff.lib_string_table.items.len, Context{7156 std.sort.pdqContext(0, coff.lib_string_table.items.len, Context{
7171 .coff = coff,7157 .coff = coff,
7172 .indices = coff.secondLinkerMemberIndicesSlice(),7158 .indices = coff.secondLinkerMemberIndicesSlice(),
...@@ -7493,7 +7479,7 @@ pub fn deleteExport(coff: *Coff, exported: Zcu.Exported, name: InternPool.NullTe...@@ -7493,7 +7479,7 @@ pub fn deleteExport(coff: *Coff, exported: Zcu.Exported, name: InternPool.NullTe
7493 _ = exported;7479 _ = exported;
7494 _ = name;7480 _ = name;
74957481
7496 // TODO: Delete from first / second linker member table (remove swap?)7482 // TODO: Delete from first / second linker member table
7497 // TODO: Delete from symbol table inside section7483 // TODO: Delete from symbol table inside section
7498}7484}
74997485
...@@ -7609,7 +7595,6 @@ fn printNodeName(...@@ -7609,7 +7595,6 @@ fn printNodeName(
7609 .input_section => |isi| {7595 .input_section => |isi| {
7610 const ioi = isi.input(coff);7596 const ioi = isi.input(coff);
7611 const is = isi.inputSection(coff);7597 const is = isi.inputSection(coff);
7612 // TODO: Use only filename from these paths, they are long
7613 try w.print("({f}{f}, {s}", .{7598 try w.print("({f}{f}, {s}", .{
7614 ioi.path(coff).fmtEscapeString(),7599 ioi.path(coff).fmtEscapeString(),
7615 fmtMemberNameString(ioi.memberName(coff)),7600 fmtMemberNameString(ioi.memberName(coff)),