authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-18 04:40:22+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-18 10:58:52+01:00
log074dd4d083b8ddefc370425568b61c890efe905d
tree098fb0b0bd29588fae3e1e12288593b0e795f816
parent2a4e06bcb30f71e83b14026bcbade6aac3aece84

mingw: Rename mingw32.lib to libmingw32.lib.

LLD expects the library file name (minus extension) to be exactly libmingw32. By calling it mingw32 previously, we prevented it from being detected as being in LLD's list of libraries that are excluded from the MinGW-specific auto-export mechanism. https://github.com/llvm/llvm-project/blob/b9d27ac252265839354fffeacaa8f39377ed7424/lld/COFF/MinGW.cpp#L30-L56 As a result, a DLL built for *-windows-gnu with Zig would export a bunch of internal MinGW symbols. This sometimes worked out fine, but it could break at link or run time when linking an EXE with a DLL, where both are targeting *-windows-gnu and thus linking separate copies of mingw32.lib. In #23204, this manifested as the linker getting confused about _gnu_exception_handler() because it was incorrectly exported by the DLL while also being defined in the mingw32.lib that was being linked into the EXE. Closes #23204.

3 files changed, 6 insertions(+), 6 deletions(-)

src/Compilation.zig+2-2
......@@ -827,7 +827,7 @@ pub const MiscTask = enum {
827827
828828 @"mingw-w64 crt2.o",
829829 @"mingw-w64 dllcrt2.o",
830 @"mingw-w64 mingw32.lib",
830 @"mingw-w64 libmingw32.lib",
831831};
832832
833833pub const MiscError = struct {
......@@ -1886,7 +1886,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18861886
18871887 const main_crt_file: mingw.CrtFile = if (is_dyn_lib) .dllcrt2_o else .crt2_o;
18881888 comp.queued_jobs.mingw_crt_file[@intFromEnum(main_crt_file)] = true;
1889 comp.queued_jobs.mingw_crt_file[@intFromEnum(mingw.CrtFile.mingw32_lib)] = true;
1889 comp.queued_jobs.mingw_crt_file[@intFromEnum(mingw.CrtFile.libmingw32_lib)] = true;
18901890 comp.remaining_prelink_tasks += 2;
18911891
18921892 // When linking mingw-w64 there are some import libs we always need.
src/link/Coff.zig+1-1
......@@ -2104,7 +2104,7 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
21042104 try argv.append(try comp.crtFileAsString(arena, "crt2.obj"));
21052105 }
21062106
2107 try argv.append(try comp.crtFileAsString(arena, "mingw32.lib"));
2107 try argv.append(try comp.crtFileAsString(arena, "libmingw32.lib"));
21082108 } else {
21092109 const lib_str = switch (comp.config.link_mode) {
21102110 .dynamic => "",
src/mingw.zig+3-3
......@@ -14,7 +14,7 @@ const dev = @import("dev.zig");
1414pub const CrtFile = enum {
1515 crt2_o,
1616 dllcrt2_o,
17 mingw32_lib,
17 libmingw32_lib,
1818};
1919
2020/// TODO replace anyerror with explicit error set, recording user-friendly errors with
......@@ -69,7 +69,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
6969 });
7070 },
7171
72 .mingw32_lib => {
72 .libmingw32_lib => {
7373 var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
7474
7575 {
......@@ -173,7 +173,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
173173 }
174174 }
175175
176 return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{
176 return comp.build_crt_file("libmingw32", .Lib, .@"mingw-w64 libmingw32.lib", prog_node, c_source_files.items, .{
177177 .unwind_tables = unwind_tables,
178178 // https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611
179179 .allow_lto = false,