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(...@@ -789,6 +789,7 @@ fn create(
789 minor_subsystem_version,789 minor_subsystem_version,
790 magic,790 magic,
791 section_align,791 section_align,
792 std.fs.path.basename(path.sub_path),
792 );793 );
793 return coff;794 return coff;
794}795}
...@@ -823,6 +824,7 @@ fn initHeaders(...@@ -823,6 +824,7 @@ fn initHeaders(
823 minor_subsystem_version: u16,824 minor_subsystem_version: u16,
824 magic: std.coff.OptionalHeader.Magic,825 magic: std.coff.OptionalHeader.Magic,
825 section_align: std.mem.Alignment,826 section_align: std.mem.Alignment,
827 file_name: []const u8,
826) !void {828) !void {
827 const comp = coff.base.comp;829 const comp = coff.base.comp;
828 const gpa = comp.gpa;830 const gpa = comp.gpa;
...@@ -1063,27 +1065,27 @@ fn initHeaders(...@@ -1063,27 +1065,27 @@ fn initHeaders(
1063 );1065 );
1064 coff.nodes.appendAssumeCapacity(.import_directory_table);1066 coff.nodes.appendAssumeCapacity(.import_directory_table);
10651067
1066 {1068 if (is_image) {
1067 // TODO: Could create this lazily when processing the first export instead?
1068 const edata_section_ni = (try coff.pseudoSectionMapIndex(1069 const edata_section_ni = (try coff.pseudoSectionMapIndex(
1069 .@".edata",1070 .@".edata",
1070 .of(std.coff.ExportDirectoryTable),1071 .of(std.coff.ExportDirectoryTable),
1071 .{ .read = true },1072 .{ .read = true },
1072 )).symbol(coff).node(coff);1073 )).symbol(coff).node(coff);
10731074
1074 const name = "TODO_NAME.dll";
1075 const name_index = @sizeOf(std.coff.ExportDirectoryTable);
1076 coff.export_table.ni = try coff.mf.addLastChildNode(1075 coff.export_table.ni = try coff.mf.addLastChildNode(
1077 gpa,1076 gpa,
1078 edata_section_ni,1077 edata_section_ni,
1079 .{1078 .{
1080 .size = @sizeOf(std.coff.ExportDirectoryTable) + name.len + 1,1079 .size = @sizeOf(std.coff.ExportDirectoryTable) + file_name.len + 1,
1081 .alignment = .of(std.coff.ExportDirectoryTable),1080 .alignment = .of(std.coff.ExportDirectoryTable),
1082 .fixed = true,1081 .fixed = true,
1083 .moved = true,1082 .moved = true,
1084 },1083 },
1085 );1084 );
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
1088 const export_address_table_ni = try coff.mf.addLastChildNode(gpa, edata_section_ni, .{1090 const export_address_table_ni = try coff.mf.addLastChildNode(gpa, edata_section_ni, .{
1089 .alignment = .of(u32),1091 .alignment = .of(u32),
...@@ -2600,6 +2602,8 @@ fn updateExportsInner(...@@ -2600,6 +2602,8 @@ fn updateExportsInner(
2600 std.mem.byteSwapAllFields(std.coff.ImageDataDirectory, tls_directory);2602 std.mem.byteSwapAllFields(std.coff.ImageDataDirectory, tls_directory);
2601 }2603 }
26022604
2605 if (coff.export_table.ni == .none) continue;
2606
2603 const entries_ctx = ExportTable.Adapter{ .coff = coff };2607 const entries_ctx = ExportTable.Adapter{ .coff = coff };
2604 const gop = try coff.export_table.entries.getOrPutAdapted(2608 const gop = try coff.export_table.entries.getOrPutAdapted(
2605 gpa,2609 gpa,