diff options
author | Frederik Rietdijk <fridh@fridh.nl> | 2017-08-30 21:07:07 +0200 |
---|---|---|
committer | Frederik Rietdijk <fridh@fridh.nl> | 2017-08-30 21:07:07 +0200 |
commit | 6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6 (patch) | |
tree | 37977913dee77c1804abc3915b218c05ab0419fd /pkgs/build-support | |
parent | 7cd46a05943bfd86a46a3d99a1d85a2a028d4d2c (diff) | |
parent | 2858c41823db1654f123c455cca2b145b8d8737b (diff) | |
download | nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.tar nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.tar.gz nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.tar.bz2 nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.tar.lz nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.tar.xz nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.tar.zst nixlib-6d4bd78fad1c2040cafe6f5fa30d8134dac3bdf6.zip |
Merge commit '2858c41' into HEAD
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 257 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/ld-wrapper.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/utils.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/expand-response-params/default.nix | 19 | ||||
-rw-r--r-- | pkgs/build-support/expand-response-params/expand-response-params.c (renamed from pkgs/build-support/cc-wrapper/expand-response-params.c) | 0 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper-old/default.nix | 2 |
6 files changed, 164 insertions, 118 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index b3971808a2b4..0114170b8ebc 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -66,7 +66,7 @@ let else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2" else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2" # ARM with a wildcard, which can be "" or "-armhf". - else if targetPlatform.isArm32 then "${libc_lib}/lib/ld-linux*.so.3" + else if targetPlatform.isArm then "${libc_lib}/lib/ld-linux*.so.3" else if targetPlatform.system == "aarch64-linux" then "${libc_lib}/lib/ld-linux-aarch64.so.1" else if targetPlatform.system == "powerpc-linux" then "${libc_lib}/lib/ld.so.1" else if targetPlatform.system == "mips64el-linux" then "${libc_lib}/lib/ld.so.1" @@ -74,18 +74,10 @@ let else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else null; - expand-response-params = if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null" - then buildPackages.stdenv.mkDerivation { - name = "expand-response-params"; - src = ./expand-response-params.c; - buildCommand = '' - # Work around "stdenv-darwin-boot-2 is not allowed to refer to path /nix/store/...-expand-response-params.c" - cp "$src" expand-response-params.c - "$CC" -std=c99 -O3 -o "$out" expand-response-params.c - strip -S $out - ${optionalString hostPlatform.isLinux "patchelf --shrink-rpath $out"} - ''; - } else ""; + expand-response-params = + if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null" + then import ../expand-response-params { inherit (buildPackages) stdenv; } + else ""; in @@ -120,8 +112,17 @@ stdenv.mkDerivation { ''; }; - buildCommand = + dontBuild = true; + dontConfigure = true; + + unpackPhase = '' + src=$PWD + ''; + + installPhase = '' + set -u + mkdir -p $out/bin $out/nix-support $man/nix-support wrap() { @@ -133,110 +134,16 @@ stdenv.mkDerivation { } '' - + optionalString (libc != null) ('' - if [[ -z ''${dynamicLinker+x} ]]; then - echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2 - dynamicLinker="${libc_lib}/lib/ld*.so.?" - fi - - # Expand globs to fill array of options - dynamicLinker=($dynamicLinker) - - case ''${#dynamicLinker[@]} in - 0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;; - 1) echo "Using dynamic linker: '$dynamicLinker'" >&2;; - *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;; - esac - - if [ -n "$dynamicLinker" ]; then - echo $dynamicLinker > $out/nix-support/dynamic-linker - - '' + (if targetPlatform.isDarwin then '' - printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook - '' else '' - if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then - echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 - fi - - ldflagsBefore=(-dynamic-linker "$dynamicLinker") - '') + '' - fi - - # The dynamic linker is passed in `ldflagsBefore' to allow - # explicit overrides of the dynamic linker by callers to gcc/ld - # (the *last* value counts, so ours should come first). - printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before - '') - - + optionalString (libc != null) '' - # The "-B${libc_lib}/lib/" flag is a quick hack to force gcc to link - # against the crt1.o from our own glibc, rather than the one in - # /usr/lib. (This is only an issue when using an `impure' - # compiler/linker, i.e., one that searches /usr/lib and so on.) - # - # Unfortunately, setting -B appears to override the default search - # path. Thus, the gcc-specific "../includes-fixed" directory is - # now longer searched and glibc's <limits.h> header fails to - # compile, because it uses "#include_next <limits.h>" to find the - # limits.h file in ../includes-fixed. To remedy the problem, - # another -idirafter is necessary to add that directory again. - echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include -idirafter ${cc}/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags - - echo "-L${libc_lib}/lib" > $out/nix-support/libc-ldflags - - echo "${libc_lib}" > $out/nix-support/orig-libc - echo "${libc_dev}" > $out/nix-support/orig-libc-dev - '' - + (if nativeTools then '' + echo ${if targetPlatform.isDarwin then cc else nativePrefix} > $out/nix-support/orig-cc + ccPath="${if targetPlatform.isDarwin then cc else nativePrefix}/bin" ldPath="${nativePrefix}/bin" '' else '' echo $cc > $out/nix-support/orig-cc - # GCC shows ${cc_solib}/lib in `gcc -print-search-dirs', but not - # ${cc_solib}/lib64 (even though it does actually search there...).. - # This confuses libtool. So add it to the compiler tool search - # path explicitly. - if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then - ccLDFlags+=" -L${cc_solib}/lib64" - ccCFlags+=" -B${cc_solib}/lib64" - fi - ccLDFlags+=" -L${cc_solib}/lib" - ccCFlags+=" -B${cc_solib}/lib" - - ${optionalString cc.langVhdl or false '' - ccLDFlags+=" -L${zlib.out}/lib" - ''} - - # Find the gcc libraries path (may work only without multilib). - ${optionalString cc.langAda or false '' - basePath=`echo ${cc_solib}/lib/*/*/*` - ccCFlags+=" -B$basePath -I$basePath/adainclude" - gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib" - echo "$gnatCFlags" > $out/nix-support/gnat-cflags - ''} - - if [ -e $ccPath/clang ]; then - # Need files like crtbegin.o from gcc - # It's unclear if these will ever be provided by an LLVM project - ccCFlags="$ccCFlags -B$basePath" - ccCFlags="$ccCFlags -isystem$cc/lib/clang/$ccVersion/include" - fi - - echo "$ccLDFlags" > $out/nix-support/cc-ldflags - echo "$ccCFlags" > $out/nix-support/cc-cflags - ccPath="${cc}/bin" ldPath="${binutils_bin}/bin" - - # Propagate the wrapped cc so that if you install the wrapper, - # you get tools like gcov, the manpages, etc. as well (including - # for binutils and Glibc). - printWords ${cc} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages - printWords ${cc.man or ""} > $man/nix-support/propagated-user-env-packages - - printWords ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs '' + optionalString (targetPlatform.isSunOS && nativePrefix != "") '' @@ -327,15 +234,129 @@ stdenv.mkDerivation { + optionalString cc.langVhdl or false '' ln -s $ccPath/${prefix}ghdl $out/bin/${prefix}ghdl + ''; + + propagatedBuildInputs = extraPackages; + + setupHook = ./setup-hook.sh; + + postFixup = + '' + set -u + '' + + + optionalString (libc != null) ('' + ## + ## General libc support + ## + + # The "-B${libc_lib}/lib/" flag is a quick hack to force gcc to link + # against the crt1.o from our own glibc, rather than the one in + # /usr/lib. (This is only an issue when using an `impure' + # compiler/linker, i.e., one that searches /usr/lib and so on.) + # + # Unfortunately, setting -B appears to override the default search + # path. Thus, the gcc-specific "../includes-fixed" directory is + # now longer searched and glibc's <limits.h> header fails to + # compile, because it uses "#include_next <limits.h>" to find the + # limits.h file in ../includes-fixed. To remedy the problem, + # another -idirafter is necessary to add that directory again. + echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include -idirafter ${cc}/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags + + echo "-L${libc_lib}/lib" > $out/nix-support/libc-ldflags + + echo "${libc_lib}" > $out/nix-support/orig-libc + echo "${libc_dev}" > $out/nix-support/orig-libc-dev + + ## + ## Dynamic linker support + ## + + if [[ -z ''${dynamicLinker+x} ]]; then + echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2 + local dynamicLinker="${libc_lib}/lib/ld*.so.?" + fi + + # Expand globs to fill array of options + dynamicLinker=($dynamicLinker) + + case ''${#dynamicLinker[@]} in + 0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;; + 1) echo "Using dynamic linker: '$dynamicLinker'" >&2;; + *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;; + esac + + if [ -n "$dynamicLinker" ]; then + echo $dynamicLinker > $out/nix-support/dynamic-linker + + '' + (if targetPlatform.isDarwin then '' + printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook + '' else '' + if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then + echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 + fi + + local ldflagsBefore=(-dynamic-linker "$dynamicLinker") + '') + '' + fi + + # The dynamic linker is passed in `ldflagsBefore' to allow + # explicit overrides of the dynamic linker by callers to gcc/ld + # (the *last* value counts, so ours should come first). + printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before + '') + + + optionalString (!nativeTools) '' + + ## + ## Initial CFLAGS + ## + + # GCC shows ${cc_solib}/lib in `gcc -print-search-dirs', but not + # ${cc_solib}/lib64 (even though it does actually search there...).. + # This confuses libtool. So add it to the compiler tool search + # path explicitly. + if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then + ccLDFlags+=" -L${cc_solib}/lib64" + ccCFlags+=" -B${cc_solib}/lib64" + fi + ccLDFlags+=" -L${cc_solib}/lib" + ccCFlags+=" -B${cc_solib}/lib" + + ${optionalString cc.langVhdl or false '' + ccLDFlags+=" -L${zlib.out}/lib" + ''} + + # Find the gcc libraries path (may work only without multilib). + ${optionalString cc.langAda or false '' + basePath=`echo ${cc_solib}/lib/*/*/*` + ccCFlags+=" -B$basePath -I$basePath/adainclude" + gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib" + echo "$gnatCFlags" > $out/nix-support/gnat-cflags + ''} + + echo "$ccLDFlags" > $out/nix-support/cc-ldflags + echo "$ccCFlags" > $out/nix-support/cc-cflags + + ## + ## User env support + ## + + # Propagate the wrapped cc so that if you install the wrapper, + # you get tools like gcov, the manpages, etc. as well (including + # for binutils and Glibc). + printWords ${cc} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages + printWords ${cc.man or ""} > $man/nix-support/propagated-user-env-packages '' + '' - substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook.tmp - cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook - rm $out/nix-support/setup-hook.tmp + + ## + ## Hardening support + ## # some linkers on some platforms don't support specific -z flags - hardening_unsupported_flags="" + export hardening_unsupported_flags="" if [[ "$($ldPath/${prefix}ld -z now 2>&1 || true)" =~ un(recognized|known)\ option ]]; then hardening_unsupported_flags+=" bindnow" fi @@ -352,12 +373,18 @@ stdenv.mkDerivation { substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh substituteAll ${./utils.sh} $out/nix-support/utils.sh + + ## + ## Extra custom steps + ## + '' + extraBuildCommands; inherit dynamicLinker expand-response-params; - expandResponseParams = expand-response-params; # for substitution in utils.sh + # for substitution in utils.sh + expandResponseParams = "${expand-response-params}/bin/expand-response-params"; crossAttrs = { shell = shell.crossDrv + shell.crossDrv.shellPath; diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index d5fdc837cf5f..a775b6da8237 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -121,7 +121,7 @@ if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then # It's important to add the rpath in the order of -L..., so # the link time chosen objects will be those of runtime linking. declare -A rpaths - for dir in "${libDirs[@]}"; do + for dir in ${libDirs+"${libDirs[@]}"}; do if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then dir="$dir2" fi diff --git a/pkgs/build-support/cc-wrapper/utils.sh b/pkgs/build-support/cc-wrapper/utils.sh index 7e9979f10ae8..c84a094e26b0 100644 --- a/pkgs/build-support/cc-wrapper/utils.sh +++ b/pkgs/build-support/cc-wrapper/utils.sh @@ -30,7 +30,7 @@ expandResponseParams() { if [[ "$arg" == @* ]]; then # phase separation makes this look useless # shellcheck disable=SC2157 - if [ -n "@expandResponseParams@" ]; then + if [ -x "@expandResponseParams@" ]; then # params is used by caller #shellcheck disable=SC2034 readarray -d '' params < <("@expandResponseParams@" "$@") diff --git a/pkgs/build-support/expand-response-params/default.nix b/pkgs/build-support/expand-response-params/default.nix new file mode 100644 index 000000000000..2a4bee74197b --- /dev/null +++ b/pkgs/build-support/expand-response-params/default.nix @@ -0,0 +1,19 @@ +{ stdenv }: + +stdenv.mkDerivation { + name = "expand-response-params"; + src = ./expand-response-params.c; + # Work around "stdenv-darwin-boot-2 is not allowed to refer to path + # /nix/store/...-expand-response-params.c" + unpackPhase = '' + cp "$src" expand-response-params.c + src=$PWD + ''; + buildPhase = '' + "$CC" -std=c99 -O3 -o "expand-response-params" expand-response-params.c + ''; + installPhase = '' + mkdir -p $prefix/bin + mv expand-response-params $prefix/bin/ + ''; +} diff --git a/pkgs/build-support/cc-wrapper/expand-response-params.c b/pkgs/build-support/expand-response-params/expand-response-params.c index 05b9c62b1e8d..05b9c62b1e8d 100644 --- a/pkgs/build-support/cc-wrapper/expand-response-params.c +++ b/pkgs/build-support/expand-response-params/expand-response-params.c diff --git a/pkgs/build-support/gcc-wrapper-old/default.nix b/pkgs/build-support/gcc-wrapper-old/default.nix index a37d94c36e06..8d28879fb06f 100644 --- a/pkgs/build-support/gcc-wrapper-old/default.nix +++ b/pkgs/build-support/gcc-wrapper-old/default.nix @@ -92,7 +92,7 @@ stdenv.mkDerivation { (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else # ARM with a wildcard, which can be "" or "-armhf". - if targetPlatform.isArm32 then "ld-linux*.so.3" else + if targetPlatform.isArm then "ld-linux*.so.3" else if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else if targetPlatform.system == "powerpc-linux" then "ld.so.1" else if targetPlatform.system == "mips64el-linux" then "ld.so.1" else |