From 0a77be4e003797ceb86b4dc7d2d9ee316df42de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 3 Nov 2024 15:32:33 +0100 Subject: [PATCH] link.Coff: Pass -lldmingw to LLD earlier and regardless of -lc. The -lldmingw option affects a lot of logic throughout LLD. We need to pass it for *-windows-gnu even when we're not actually linking MinGW since we're still using the MinGW ABI with all that that entails. (One particular problem we would run into is missing handling of stdcall-decorated symbols for 32-bit x86.) Also, various other LLD options are sensitive to this option, so it's best to pass it as early as possible. Closes #11817. --- src/link/Coff.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/link/Coff.zig b/src/link/Coff.zig index a52892409ac9..cf691c4f122d 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1832,6 +1832,10 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: const linker_command = "lld-link"; try argv.appendSlice(&[_][]const u8{ comp.self_exe_path.?, linker_command }); + if (target.isMinGW()) { + try argv.append("-lldmingw"); + } + try argv.append("-ERRORLIMIT:0"); try argv.append("-NOLOGO"); if (comp.config.debug_format != .strip) { @@ -2053,8 +2057,6 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: .win32 => { if (link_in_crt) { if (target.abi.isGnu()) { - try argv.append("-lldmingw"); - if (target.cpu.arch == .x86) { try argv.append("-ALTERNATENAME:__image_base__=___ImageBase"); } else {