diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-12-06 19:57:55 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-02-08 13:48:30 +0000 |
commit | bf3aadfdd39aa197e18bade671fab6726349ffa4 (patch) | |
tree | 698567af766ed441d757b57a7b21e68d4a342a2b /nixpkgs/pkgs/build-support/cc-wrapper | |
parent | f4afc5a01d9539ce09e47494e679c51f80723d07 (diff) | |
parent | 99665eb45f58d959d2cb9e49ddb960c79d596f33 (diff) | |
download | nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.gz nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.bz2 nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.lz nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.xz nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.tar.zst nixlib-bf3aadfdd39aa197e18bade671fab6726349ffa4.zip |
Merge commit '99665eb45f58d959d2cb9e49ddb960c79d596f33'
Diffstat (limited to 'nixpkgs/pkgs/build-support/cc-wrapper')
4 files changed, 81 insertions, 60 deletions
diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh b/nixpkgs/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh new file mode 100644 index 000000000000..f943b8504683 --- /dev/null +++ b/nixpkgs/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh @@ -0,0 +1,11 @@ +needsTarget=true + +for p in "${params[@]}"; do + case "$p" in + -target | --target=*) needsTarget=false ;; + esac +done + +if $needsTarget; then + extraBefore+=(-target @defaultTarget@) +fi diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 1220841162c3..83b6817798f2 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -38,36 +38,23 @@ nParams=${#params[@]} while (( "$n" < "$nParams" )); do p=${params[n]} p2=${params[n+1]:-} # handle `p` being last one - if [ "$p" = -c ]; then - dontLink=1 - elif [ "$p" = -S ]; then - dontLink=1 - elif [ "$p" = -E ]; then - dontLink=1 - elif [ "$p" = -E ]; then - dontLink=1 - elif [ "$p" = -M ]; then - dontLink=1 - elif [ "$p" = -MM ]; then - dontLink=1 - elif [[ "$p" = -x && "$p2" = *-header ]]; then - dontLink=1 - elif [[ "$p" = -x && "$p2" = c++* && "$isCxx" = 0 ]]; then - isCxx=1 - elif [ "$p" = -nostdlib ]; then - cxxLibrary=0 - elif [ "$p" = -nostdinc ]; then - cInclude=0 - cxxInclude=0 - elif [ "$p" = -nostdinc++ ]; then - cxxInclude=0 - elif [[ "$p" != -?* ]]; then - # A dash alone signifies standard input; it is not a flag - nonFlagArgs=1 - elif [ "$p" = -cc1 ]; then - cc1=1 - fi n+=1 + + case "$p" in + -[cSEM] | -MM) dontLink=1 ;; + -cc1) cc1=1 ;; + -nostdinc) cInclude=0 cxxInclude=0 ;; + -nostdinc++) cxxInclude=0 ;; + -nostdlib) cxxLibrary=0 ;; + -x) + case "$p2" in + *-header) dontLink=1 ;; + c++*) isCxx=1 ;; + esac + ;; + -?*) ;; + *) nonFlagArgs=1 ;; # Includes a solitary dash (`-`) which signifies standard input; it is not a flag + esac done # If we pass a flag like -Wl, then gcc will call the linker unless it @@ -81,29 +68,31 @@ fi # Optionally filter out paths not refering to the store. if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then - rest=() + kept=() nParams=${#params[@]} declare -i n=0 while (( "$n" < "$nParams" )); do p=${params[n]} p2=${params[n+1]:-} # handle `p` being last one - if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then - skip "${p:2}" - elif [ "$p" = -L ] && badPath "$p2"; then - n+=1; skip "$p2" - elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then - skip "${p:2}" - elif [ "$p" = -I ] && badPath "$p2"; then - n+=1; skip "$p2" - elif [ "$p" = -isystem ] && badPath "$p2"; then - n+=1; skip "$p2" - else - rest+=("$p") - fi n+=1 + + skipNext=false + path="" + case "$p" in + -[IL]/*) path=${p:2} ;; + -[IL] | -isystem) path=$p2 skipNext=true ;; + esac + + if [[ -n $path ]] && badPath "$path"; then + skip "$path" + $skipNext && n+=1 + continue + fi + + kept+=("$p") done # Old bash empty array hack - params=(${rest+"${rest[@]}"}) + params=(${kept+"${kept[@]}"}) fi # Flirting with a layer violation here. @@ -118,17 +107,17 @@ fi # Clear march/mtune=native -- they bring impurity. if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then - rest=() + kept=() # Old bash empty array hack for p in ${params+"${params[@]}"}; do if [[ "$p" = -m*=native ]]; then skip "$p" else - rest+=("$p") + kept+=("$p") fi done # Old bash empty array hack - params=(${rest+"${rest[@]}"}) + params=(${kept+"${kept[@]}"}) fi if [[ "$isCxx" = 1 ]]; then @@ -170,6 +159,10 @@ if [ "$dontLink" != 1 ]; then export NIX_LINK_TYPE_@suffixSalt@=$linkType fi +if [[ -e @out@/nix-support/add-local-cc-cflags-before.sh ]]; then + source @out@/nix-support/add-local-cc-cflags-before.sh +fi + # As a very special hack, if the arguments are just `-v', then don't # add anything. This is to prevent `gcc -v' (which normally prints # out the version number and returns exit code 0) from printing out diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/default.nix b/nixpkgs/pkgs/build-support/cc-wrapper/default.nix index 3738f628b187..047cdf6a4911 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/default.nix +++ b/nixpkgs/pkgs/build-support/cc-wrapper/default.nix @@ -14,6 +14,7 @@ , nativeTools, noLibc ? false, nativeLibc, nativePrefix ? "" , propagateDoc ? cc != null && cc ? man , extraTools ? [], extraPackages ? [], extraBuildCommands ? "" +, nixSupport ? {} , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null , buildPackages ? {} , libcxx ? null @@ -155,10 +156,13 @@ stdenv.mkDerivation { (setenv "NIX_CFLAGS_COMPILE_${suffixSalt}" (concat (getenv "NIX_CFLAGS_COMPILE_${suffixSalt}") " -isystem " arg "/include")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) ''; + + inherit nixSupport; }; dontBuild = true; dontConfigure = true; + enableParallelBuilding = true; unpackPhase = '' src=$PWD @@ -245,12 +249,19 @@ stdenv.mkDerivation { wrap ${targetPrefix}gdc $wrapper $ccPath/${targetPrefix}gdc '' - + optionalString cc.langFortran or false '' + + optionalString cc.langFortran or false ('' wrap ${targetPrefix}gfortran $wrapper $ccPath/${targetPrefix}gfortran ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}g77 ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}f77 export named_fc=${targetPrefix}gfortran '' + # Darwin aarch64 fortran compilations seem to fail otherwise, see: + # https://github.com/NixOS/nixpkgs/issues/140041 + + (if (stdenvNoCC.isDarwin && stdenvNoCC.isAarch64) then '' + export fortran_hardening="pic strictoverflow relro bindnow" + '' else '' + export fortran_hardening="pic strictoverflow relro bindnow stackprotector" + '')) + optionalString cc.langJava or false '' wrap ${targetPrefix}gcj $wrapper $ccPath/${targetPrefix}gcj @@ -294,14 +305,6 @@ stdenv.mkDerivation { '' ## - ## General Clang support - ## - + optionalString isClang '' - - echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags - '' - - ## ## GCC libs for non-GCC support ## + optionalString useGccForLibs '' @@ -378,7 +381,6 @@ stdenv.mkDerivation { + optionalString (libcxx.isLLVM or false) ('' echo "-isystem ${lib.getDev libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags - '' + lib.optionalString stdenv.targetPlatform.isLinux '' echo "-lc++abi" >> $out/nix-support/libcxx-ldflags '') @@ -478,7 +480,7 @@ stdenv.mkDerivation { hardening_unsupported_flags+=" stackprotector fortify" '' + optionalString targetPlatform.isAvr '' hardening_unsupported_flags+=" stackprotector pic" - '' + optionalString (targetPlatform.libc == "newlib") '' + '' + optionalString (targetPlatform.libc == "newlib" || targetPlatform.libc == "newlib-nano") '' hardening_unsupported_flags+=" stackprotector fortify pie pic" '' + optionalString (targetPlatform.libc == "musl" && targetPlatform.isx86_32) '' hardening_unsupported_flags+=" stackprotector" @@ -488,6 +490,8 @@ stdenv.mkDerivation { hardening_unsupported_flags+=" format stackprotector strictoverflow" '' + optionalString cc.langD or false '' hardening_unsupported_flags+=" format" + '' + optionalString cc.langFortran or false '' + hardening_unsupported_flags+=" format" '' + optionalString targetPlatform.isWasm '' hardening_unsupported_flags+=" stackprotector fortify pie pic" '' @@ -519,9 +523,22 @@ stdenv.mkDerivation { '' ## + ## General Clang support + ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script + ## + + optionalString isClang '' + export defaultTarget=${targetPlatform.config} + substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh + '' + + ## ## Extra custom steps ## - + extraBuildCommands; + + extraBuildCommands + + lib.strings.concatStringsSep "; " + (lib.attrsets.mapAttrsToList + (name: value: "echo ${toString value} >> $out/nix-support/${name}") + nixSupport); inherit expand-response-params; diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/fortran-hook.sh b/nixpkgs/pkgs/build-support/cc-wrapper/fortran-hook.sh index d72f314c01ce..59e493e1836d 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/fortran-hook.sh +++ b/nixpkgs/pkgs/build-support/cc-wrapper/fortran-hook.sh @@ -5,7 +5,7 @@ export FC${role_post}=@named_fc@ # If unset, assume the default hardening flags. # These are different for fortran. -: ${NIX_HARDENING_ENABLE="stackprotector pic strictoverflow relro bindnow"} +: ${NIX_HARDENING_ENABLE="@fortran_hardening@"} export NIX_HARDENING_ENABLE unset -v role_post |