authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-05 01:55:33-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-06-23 00:21:00-04:00
log2b48ec1e720b1def48c0a89b35e8f60f3edb38be
treec0e09665c58e451817a32d3f12204b8ac476f5db
parenta87fc47bc17ae28a8a0a90da4c64751a071bac44

- Only add the .edata section for images

- Write the image name into the export directory table

1 files changed, 10 insertions(+), 6 deletions(-)

src/link/Coff.zig+10-6
......@@ -789,6 +789,7 @@ fn create(
789789 minor_subsystem_version,
790790 magic,
791791 section_align,
792 std.fs.path.basename(path.sub_path),
792793 );
793794 return coff;
794795}
......@@ -823,6 +824,7 @@ fn initHeaders(
823824 minor_subsystem_version: u16,
824825 magic: std.coff.OptionalHeader.Magic,
825826 section_align: std.mem.Alignment,
827 file_name: []const u8,
826828) !void {
827829 const comp = coff.base.comp;
828830 const gpa = comp.gpa;
......@@ -1063,27 +1065,27 @@ fn initHeaders(
10631065 );
10641066 coff.nodes.appendAssumeCapacity(.import_directory_table);
10651067
1066 {
1067 // TODO: Could create this lazily when processing the first export instead?
1068 if (is_image) {
10681069 const edata_section_ni = (try coff.pseudoSectionMapIndex(
10691070 .@".edata",
10701071 .of(std.coff.ExportDirectoryTable),
10711072 .{ .read = true },
10721073 )).symbol(coff).node(coff);
10731074
1074 const name = "TODO_NAME.dll";
1075 const name_index = @sizeOf(std.coff.ExportDirectoryTable);
10761075 coff.export_table.ni = try coff.mf.addLastChildNode(
10771076 gpa,
10781077 edata_section_ni,
10791078 .{
1080 .size = @sizeOf(std.coff.ExportDirectoryTable) + name.len + 1,
1079 .size = @sizeOf(std.coff.ExportDirectoryTable) + file_name.len + 1,
10811080 .alignment = .of(std.coff.ExportDirectoryTable),
10821081 .fixed = true,
10831082 .moved = true,
10841083 },
10851084 );
1086 @memcpy(coff.export_table.ni.slice(&coff.mf)[name_index..][0 .. name.len + 1], name[0 .. name.len + 1]);
1085
1086 const name_index = @sizeOf(std.coff.ExportDirectoryTable);
1087 @memcpy(coff.export_table.ni.slice(&coff.mf)[name_index..][0..file_name.len], file_name[0..file_name.len]);
1088 @memset(coff.export_table.ni.slice(&coff.mf)[name_index + file_name.len ..], 0);
10871089
10881090 const export_address_table_ni = try coff.mf.addLastChildNode(gpa, edata_section_ni, .{
10891091 .alignment = .of(u32),
......@@ -2600,6 +2602,8 @@ fn updateExportsInner(
26002602 std.mem.byteSwapAllFields(std.coff.ImageDataDirectory, tls_directory);
26012603 }
26022604
2605 if (coff.export_table.ni == .none) continue;
2606
26032607 const entries_ctx = ExportTable.Adapter{ .coff = coff };
26042608 const gop = try coff.export_table.entries.getOrPutAdapted(
26052609 gpa,