From c6208369458208f097b8ce1ad1bb6c2bf40f211d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 4 Jun 2025 10:29:13 +0200 Subject: [PATCH] zig cc: Pass -f(no-)PIE to clang. Otherwise we rely on Clang's default which is known to not always match ours. --- src/Compilation.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Compilation.zig b/src/Compilation.zig index 8df018f224..790053ed4c 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6169,6 +6169,9 @@ pub fn addCCArgs( } if (target_util.supports_fpic(target)) { + // PIE needs to go before PIC because Clang interprets `-fno-PIE` to imply `-fno-PIC`, which + // we don't necessarily want. + try argv.append(if (comp.config.pie) "-fPIE" else "-fno-PIE"); try argv.append(if (mod.pic) "-fPIC" else "-fno-PIC"); }