From 7047ba9ccbdf730d726c44de5e9182b4689b3f32 Mon Sep 17 00:00:00 2001 From: Peter Waller
Date: Fri, 15 Nov 2024 09:44:03 +0000 Subject: [PATCH] llvmPackages.clang: move add-nostdlibinc-flag.patch to cc-wrapper Remove a patch to decrease the divergence from upstream. Motivation is a continuation of trying to reduce the number of clang builds floating around. Wrapper builds are cheap, compiler builds are not. It's expected that this patch can be removed at some point and replaced with some other cc-wrapper logic. This will be a little bit easier with the logic already in the cc-wrapper. Ongoing discussion in #191152. It would be nice to drop this but we think it's probably needed at least on systems where /usr/include may be available to prevent the possibility of picking up unwanted includes. One potential method for eliminating nostdlibinc in the future is by providing a non-existent -sysroot but that was reverted in #213185, and remains a can of worms. Signed-off-by: Peter Waller
--- pkgs/build-support/cc-wrapper/default.nix | 14 ++++++++++++++ .../common/clang/add-nostdlibinc-flag.patch | 18 ------------------ .../compilers/llvm/common/default.nix | 17 ----------------- 3 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 pkgs/development/compilers/llvm/common/clang/add-nostdlibinc-flag.patch diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 001123fe3d85..6caf5103325a 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -629,6 +629,20 @@ stdenvNoCC.mkDerivation { echo " -L${libcxx_solib}" >> $out/nix-support/cc-ldflags '' + ## Prevent clang from seeing /usr/include. There is a desire to achieve this + ## through alternate means because it breaks -sysroot and related functionality. + # + # This flag prevents global system header directories from + # leaking through on non‐NixOS Linux. However, on macOS, the + # SDK path is used as the sysroot, and forcing `-nostdlibinc` + # breaks `-isysroot` with an unwrapped compiler. As macOS has + # no `/usr/include`, there’s essentially no risk to dropping + # the flag there. See discussion in NixOS/nixpkgs#191152. + # + + optionalString ((cc.isClang or false) && !targetPlatform.isDarwin) '' + echo " -nostdlibinc" >> $out/nix-support/cc-cflags + '' + ## ## Man page and info support ## diff --git a/pkgs/development/compilers/llvm/common/clang/add-nostdlibinc-flag.patch b/pkgs/development/compilers/llvm/common/clang/add-nostdlibinc-flag.patch deleted file mode 100644 index 80c2eb362383..000000000000 --- a/pkgs/development/compilers/llvm/common/clang/add-nostdlibinc-flag.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp -index 3f29afd35971..223d2769cdfc 100644 ---- a/lib/Driver/Driver.cpp -+++ b/lib/Driver/Driver.cpp -@@ -491,6 +491,13 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { - } - #endif - -+ { -+ Arg *A = DAL->MakeFlagArg(/*BaseArg=*/nullptr, -+ Opts.getOption(options::OPT_nostdlibinc)); -+ A->claim(); -+ DAL->append(A); -+ } -+ - return DAL; - } - diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix index 707bb91b875d..f0a3b054d700 100644 --- a/pkgs/development/compilers/llvm/common/default.nix +++ b/pkgs/development/compilers/llvm/common/default.nix @@ -529,23 +529,6 @@ let # mis-compilation in firefox. # See: https://bugzilla.mozilla.org/show_bug.cgi?id=1741454 (metadata.getVersionFile "clang/revert-malloc-alignment-assumption.patch") - # This patch prevents global system header directories from - # leaking through on non‐NixOS Linux. However, on macOS, the - # SDK path is used as the sysroot, and forcing `-nostdlibinc` - # breaks `-isysroot` with an unwrapped compiler. As macOS has - # no `/usr/include`, there’s essentially no risk to skipping - # the patch there. It’s possible that Homebrew headers in - # `/usr/local/include` might leak through to unwrapped - # compilers being used without an SDK set or something, but - # it hopefully shouldn’t matter. - # - # TODO: Figure out a better solution to this whole problem so - # that we won’t have to choose between breaking unwrapped - # compilers breaking libclang when we can do Linux‐to‐Darwin - # cross‐compilation again. - ++ lib.optional ( - !args.stdenv.hostPlatform.isDarwin || !args.stdenv.targetPlatform.isDarwin - ) ./clang/add-nostdlibinc-flag.patch ++ [ (substituteAll { src =