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) {
199199 relocation_table: Symbol.SectionNumber,
200200 relocation_table_entry: Reloc.Index,
201201
202 image_section: Symbol.Index, // TODO: rename image_section -> section
202 image_section: Symbol.Index,
203203
204204 /// Images only
205205 import_directory_table,
......@@ -603,7 +603,7 @@ pub const LongNamesTable = struct {
603603 coff: *Coff,
604604
605605 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 this
606 assert(adapter.coff.isArchive());
607607 const longnames_slice = Node.known.longnames_member.slice(&adapter.coff.mf);
608608 const rhs = adapter.coff.long_names_table.entries.values()[rhs_index];
609609 return std.mem.eql(u8, longnames_slice[rhs.offset..][0..rhs.len], lhs_key);
......@@ -763,7 +763,6 @@ pub const ImportTable = struct {
763763};
764764
765765pub const String = enum(u32) {
766 // TODO: Re-order
767766 @".data" = 0,
768767 @".idata" = 6,
769768 @".rdata" = 13,
......@@ -943,7 +942,6 @@ pub const Symbol = struct {
943942 // The size of the symbol
944943 size: u32,
945944 /// 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`?
947945 isli: Node.InputSection.LocalIndex,
948946 /// The next symbol in the list of aliases of this symbol.
949947 next_alias_si: Symbol.Index,
......@@ -2919,7 +2917,6 @@ fn addMemberAssumeCapacity(coff: *Coff, kind: std.coff.ArchiveMemberHeader.Kind,
29192917 const gpa = comp.gpa;
29202918
29212919 // TODO: These two nodes could to be inside a movable node if kind == .coff|.import
2922
29232920 const header_ni = try coff.mf.addLastChildNode(gpa, Node.known.file, .{
29242921 .size = @sizeOf(std.coff.ArchiveMemberHeader),
29252922 .alignment = .@"2",
......@@ -3573,7 +3570,6 @@ fn objectSectionMapIndex(
35733570 return osmi;
35743571}
35753572
3576// TODO: Include align in attrs and verify the current align is >= requested
35773573fn verifyParentSectionAttributes(
35783574 coff: *Coff,
35793575 parent: Symbol.SectionNumber,
......@@ -3727,7 +3723,7 @@ fn addRelocAssumeCapacity(
37273723 if (coff.symbolTableSectionAuxEntryPtr(loc_sn.symbol(coff).sti(coff))) |aux_ptr|
37283724 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
37313727 const sri: Section.RelocationIndex = .wrap(old_num_relocations);
37323728 const entry = sri.entry(coff, loc_sn).?;
37333729 if (sti.unwrap()) |index| coff.targetStore(&entry.symbol_table_index, index);
......@@ -4509,7 +4505,7 @@ fn loadObject(
45094505 });
45104506
45114507 // 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 != none
4508 // Would need to mark this global as pending, or notice it later when .ni != none
45134509 if (!global_gop.found_existing or global_gop.value_ptr.get(coff).ni == .none) {
45144510 symbol.si = global_gop.value_ptr.*;
45154511 break :comdat .include;
......@@ -4554,9 +4550,7 @@ fn loadObject(
45544550 const sym = si.get(coff);
45554551 const existing_crc = switch (coff.getNode(sym.ni)) {
45564552 .input_section => |isi| isi.inputSection(coff).crc,
4557 // TODO: Should this result be cached somewhere?
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)),
4553 else => std.hash.crc.Crc32Jamcrc.hash(sym.ni.sliceConst(&coff.mf)),
45604554 };
45614555
45624556 if (existing_crc == section.comdat_crc) {
......@@ -4611,7 +4605,7 @@ fn loadObject(
46114605 .pending => unreachable,
46124606 }
46134607
4614 // TODO: Until we support sorting .pdata, we shouldn't merge these in, the result would be invalid
4608 // Until we support sorting .pdata, we shouldn't merge these in, the result would be invalid
46154609 const section_name = section.name.toSlice(coff);
46164610 if (std.mem.startsWith(u8, section_name, ".pdata"))
46174611 continue;
......@@ -4995,7 +4989,6 @@ fn parseArchiveMemberHeader(
49954989 };
49964990}
49974991
4998// TODO: Move to std.coff?
49994992fn parseArchiveMemberHeaderInner(
50004993 header: *const std.coff.ArchiveMemberHeader,
50014994 opt_longnames: ?[]const u8,
......@@ -5274,7 +5267,6 @@ fn loadArchive(coff: *Coff, path: std.Build.Cache.Path, fr: *Io.File.Reader) Loa
52745267 };
52755268 } else {
52765269 member.content.object.size = res.size;
5277 // TODO: If .UNKNOWN assert later that it contains no non-undef symbols?
52785270 // Microsoft's CRT contains members that set .UNKNOWN but do have undef symbols
52795271 if (machine != expected_machine and machine != .UNKNOWN) {
52805272 return diags.failParse(path, "machine mismatch in member header '{s}': expected {t}, found {t}", .{
......@@ -5859,7 +5851,6 @@ pub fn flush(
58595851 if (coff.isImage())
58605852 try coff.reportUndefs(tid);
58615853
5862 // Implib generation should instead be done via building a MappedFile progressively
58635854 if (comp.emit_implib) |implib_file|
58645855 coff.flushImplib(implib_file) catch |err|
58655856 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 {
60806071 try coff.flushMember(pending_mi.key);
60816072 break :task;
60826073 }
6083 // TODO: All the sort / shrink tasks ideally run only once - otherwise it's wasteful
6084 // Defer until exports_complete?
6085 if (coff.export_table.pending_sort) {
6074 if (coff.exports_complete and coff.export_table.pending_sort) {
60866075 defer coff.export_table.pending_sort = false;
60876076 const sub_prog_node = coff.idleProgNode(
60886077 tid,
......@@ -6098,7 +6087,7 @@ pub fn idle(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
60986087 if (coff.input_sections.items.len > coff.input_section_pending_index) return true;
60996088 if (coff.mf.updates.items.len > 0) return true;
61006089 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;
61026091 return false;
61036092}
61046093
......@@ -6578,8 +6567,6 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool {
65786567 const iat_offset: u32 = @intCast(addr_info.size * iat_symbol_gop.value_ptr.*);
65796568 switch (import.kind) {
65806569 .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>]
65836570 const iat_sym = gop.value_ptr.import_address_table_si.get(coff);
65846571 sym.section_number = iat_sym.section_number;
65856572 sym.ni = iat_sym.ni;
......@@ -7166,7 +7153,6 @@ fn flushMember(coff: *Coff, mi: Member.Index) !void {
71667153 };
71677154
71687155 // TODO: Does this sort need to also sort by linker input order (if names equal)?
7169
71707156 std.sort.pdqContext(0, coff.lib_string_table.items.len, Context{
71717157 .coff = coff,
71727158 .indices = coff.secondLinkerMemberIndicesSlice(),
......@@ -7493,7 +7479,7 @@ pub fn deleteExport(coff: *Coff, exported: Zcu.Exported, name: InternPool.NullTe
74937479 _ = exported;
74947480 _ = name;
74957481
7496 // TODO: Delete from first / second linker member table (remove swap?)
7482 // TODO: Delete from first / second linker member table
74977483 // TODO: Delete from symbol table inside section
74987484}
74997485
......@@ -7609,7 +7595,6 @@ fn printNodeName(
76097595 .input_section => |isi| {
76107596 const ioi = isi.input(coff);
76117597 const is = isi.inputSection(coff);
7612 // TODO: Use only filename from these paths, they are long
76137598 try w.print("({f}{f}, {s}", .{
76147599 ioi.path(coff).fmtEscapeString(),
76157600 fmtMemberNameString(ioi.memberName(coff)),