diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2017-08-28 14:56:08 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2017-09-01 11:44:55 -0400 |
commit | 40e9b2a7e6490eef782e5c34703a99e61fae7017 (patch) | |
tree | cc0689349b7aa170428058ee29033ac69f4ac4fb /pkgs/build-support/cc-wrapper | |
parent | fbb7d335db6cee4130314c15cac457e506db79a7 (diff) | |
download | nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.tar nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.tar.gz nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.tar.bz2 nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.tar.lz nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.tar.xz nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.tar.zst nixpkgs-40e9b2a7e6490eef782e5c34703a99e61fae7017.zip |
binutils-wrapper: Init
Factor a binutils wrapper out of cc-wrapper. While only LD is wrapped, the setup hook defines environment variables on behalf of other utilites.
Diffstat (limited to 'pkgs/build-support/cc-wrapper')
-rw-r--r-- | pkgs/build-support/cc-wrapper/add-flags.sh | 19 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/add-hardening.sh | 10 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/cc-wrapper.sh | 6 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 139 | ||||
-rwxr-xr-x | pkgs/build-support/cc-wrapper/ld-solaris-wrapper.sh | 25 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/ld-wrapper.sh | 189 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash | 106 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/setup-hook.sh | 23 |
8 files changed, 37 insertions, 480 deletions
diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh index 978041fb4d8..fb6e38302a5 100644 --- a/pkgs/build-support/cc-wrapper/add-flags.sh +++ b/pkgs/build-support/cc-wrapper/add-flags.sh @@ -10,15 +10,8 @@ var_templates_list=( NIX+CXXSTDLIB_COMPILE NIX+CXXSTDLIB_LINK NIX+GNATFLAGS_COMPILE - NIX+IGNORE_LD_THROUGH_GCC - NIX+LDFLAGS - NIX+LDFLAGS_BEFORE - NIX+LDFLAGS_AFTER ) - var_templates_bool=( - NIX+SET_BUILD_ID - NIX+DONT_SET_RPATH NIX+ENFORCE_NO_NATIVE ) @@ -62,17 +55,13 @@ if [ -e @out@/nix-support/gnat-cflags ]; then NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE" fi -if [ -e @out@/nix-support/libc-ldflags ]; then - NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)" -fi - if [ -e @out@/nix-support/cc-ldflags ]; then + # We don't import this above, but just tack this on know. binutils-wrapper's + # add-flags will not clobber it. + # + # TODO(@Ericson2314): Consider `NIX_@infixSalt@_CFLAGS_LINK` instead NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)" fi -if [ -e @out@/nix-support/libc-ldflags-before ]; then - NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE" -fi - # That way forked processes will not extend these environment variables again. export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1 diff --git a/pkgs/build-support/cc-wrapper/add-hardening.sh b/pkgs/build-support/cc-wrapper/add-hardening.sh index 34358e04194..3983e866ee1 100644 --- a/pkgs/build-support/cc-wrapper/add-hardening.sh +++ b/pkgs/build-support/cc-wrapper/add-hardening.sh @@ -6,7 +6,6 @@ if [[ -v hardeningEnable[@] ]]; then hardeningFlags+=(${hardeningEnable[@]}) fi hardeningCFlags=() -hardeningLDFlags=() declare -A hardeningDisableMap @@ -44,7 +43,6 @@ if [[ -z "${hardeningDisableMap[all]:-}" ]]; then if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi hardeningCFlags+=('-pie') - hardeningLDFlags+=('-pie') fi ;; pic) @@ -59,14 +57,6 @@ if [[ -z "${hardeningDisableMap[all]:-}" ]]; then if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling format >&2; fi hardeningCFlags+=('-Wformat' '-Wformat-security' '-Werror=format-security') ;; - relro) - if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling relro >&2; fi - hardeningLDFlags+=('-z' 'relro') - ;; - bindnow) - if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling bindnow >&2; fi - hardeningLDFlags+=('-z' 'now') - ;; *) # Ignore unsupported. Checked in Nix that at least *some* # tool supports each flag. diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 3a471c293cc..524e5309847 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -13,6 +13,12 @@ fi source @out@/nix-support/utils.sh +# Flirting with a layer violation here. +if [ -z "${NIX_BINUTILS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then + source @binutils@/nix-support/add-flags.sh +fi + +# Put this one second so libc ldflags take priority. if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then source @out@/nix-support/add-flags.sh fi diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 0114170b8eb..c9820c27ea5 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -11,7 +11,7 @@ , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null , buildPackages ? {} , useMacosReexportHack ? false -}: +} @ args: with stdenv.lib; @@ -21,14 +21,23 @@ assert !nativeTools -> assert !(nativeLibc && noLibc); assert (noLibc || nativeLibc) == (libc == null); -assert stdenv.targetPlatform != stdenv.hostPlatform -> runCommand != null; - # For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper. assert cc.langVhdl or false -> zlib != null; let inherit (stdenv) hostPlatform targetPlatform; + binutils = import ../binutils-wrapper { + inherit (args) binutils; + inherit # name + stdenv nativeTools noLibc nativeLibc nativePrefix + libc + coreutils shell gnugrep + extraPackages extraBuildCommands + buildPackages + useMacosReexportHack; + }; + # Prefix for binaries. Customarily ends with a dash separator. # # TODO(@Ericson2314) Make unconditional, or optional but always true by @@ -43,7 +52,6 @@ let libc_dev = if libc == null then null else getDev libc; libc_lib = if libc == null then null else getLib libc; cc_solib = getLib cc; - binutils_bin = if nativeTools then "" else getBin binutils; # The wrapper scripts use 'cat' and 'grep', so we may need coreutils. coreutils_bin = if nativeTools then "" else getBin coreutils; @@ -59,21 +67,6 @@ let # unstable implementation detail, however. infixSalt = dashlessTarget; - # The dynamic linker has different names on different platforms. This is a - # shell glob that ought to match it. - dynamicLinker = - /**/ if libc == null then null - 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.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" - else if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" - 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 import ../expand-response-params { inherit (buildPackages) stdenv; } @@ -88,7 +81,7 @@ stdenv.mkDerivation { preferLocalBuild = true; - inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin; + inherit cc shell libc_bin libc_dev libc_lib binutils coreutils_bin; gnugrep_bin = if nativeTools then "" else gnugrep; binPrefix = prefix; @@ -102,13 +95,11 @@ stdenv.mkDerivation { emacsBufferSetup = pkgs: '' ; We should handle propagation here too - (mapc (lambda (arg) - (when (file-directory-p (concat arg "/include")) - (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include"))) - (when (file-directory-p (concat arg "/lib")) - (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib"))) - (when (file-directory-p (concat arg "/lib64")) - (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) + (mapc + (lambda (arg) + (when (file-directory-p (concat arg "/include")) + (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include")))) + '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) ''; }; @@ -138,45 +129,18 @@ stdenv.mkDerivation { 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 ccPath="${cc}/bin" - ldPath="${binutils_bin}/bin" - '' - - + optionalString (targetPlatform.isSunOS && nativePrefix != "") '' - # Solaris needs an additional ld wrapper. - ldPath="${nativePrefix}/bin" - exec="$ldPath/${prefix}ld" - wrap ld-solaris ${./ld-solaris-wrapper.sh} '') + '' - # Create a symlink to as (the assembler). This is useful when a - # cc-wrapper is installed in a user environment, as it ensures that - # the right assembler is called. - if [ -e $ldPath/${prefix}as ]; then - ln -s $ldPath/${prefix}as $out/bin/${prefix}as - fi - - '' + (if !useMacosReexportHack then '' - wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld} - '' else '' - ldInner="${prefix}ld-reexport-delegate" - wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld} - wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner" - unset ldInner - '') + '' - - if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then - wrap ${prefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold - fi - - if [ -e ${binutils_bin}/bin/ld.bfd ]; then - wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd - fi + # Create symlinks to everything in the binutils wrapper. + for bbin in $binutils/bin/*; do + mkdir -p "$out/bin" + ln -s "$bbin" "$out/bin/$(basename $bbin)" + done # We export environment variables pointing to the wrapped nonstandard # cmds, lest some lousy configure script use those to guess compiler @@ -236,7 +200,7 @@ stdenv.mkDerivation { ln -s $ccPath/${prefix}ghdl $out/bin/${prefix}ghdl ''; - propagatedBuildInputs = extraPackages; + propagatedBuildInputs = [ binutils ] ++ extraPackages; setupHook = ./setup-hook.sh; @@ -245,7 +209,7 @@ stdenv.mkDerivation { set -u '' - + optionalString (libc != null) ('' + + optionalString (libc != null) '' ## ## General libc support ## @@ -263,48 +227,9 @@ stdenv.mkDerivation { # 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) '' @@ -345,7 +270,6 @@ stdenv.mkDerivation { # 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 '' @@ -355,14 +279,7 @@ stdenv.mkDerivation { ## Hardening support ## - # some linkers on some platforms don't support specific -z flags export hardening_unsupported_flags="" - if [[ "$($ldPath/${prefix}ld -z now 2>&1 || true)" =~ un(recognized|known)\ option ]]; then - hardening_unsupported_flags+=" bindnow" - fi - if [[ "$($ldPath/${prefix}ld -z relro 2>&1 || true)" =~ un(recognized|known)\ option ]]; then - hardening_unsupported_flags+=" relro" - fi '' + optionalString hostPlatform.isCygwin '' @@ -381,7 +298,7 @@ stdenv.mkDerivation { '' + extraBuildCommands; - inherit dynamicLinker expand-response-params; + inherit expand-response-params; # for substitution in utils.sh expandResponseParams = "${expand-response-params}/bin/expand-response-params"; @@ -396,7 +313,5 @@ stdenv.mkDerivation { { description = stdenv.lib.attrByPath ["meta" "description"] "System C compiler" cc_ + " (wrapper script)"; - } // optionalAttrs useMacosReexportHack { - platforms = stdenv.lib.platforms.darwin; }; } diff --git a/pkgs/build-support/cc-wrapper/ld-solaris-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-solaris-wrapper.sh deleted file mode 100755 index 72c999ff8bc..00000000000 --- a/pkgs/build-support/cc-wrapper/ld-solaris-wrapper.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!@shell@ -set -eu -o pipefail -shopt -s nullglob - -declare -a args=("$@") -# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'( -# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3 -# but still no success. -declare -a argsBefore=(-z ignore) argsAfter=() - -# This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library. -# GNU binutils does not have this problem: -# http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter -while (( $# )); do - case "${args[$i]}" in - -L) argsBefore+=("$1" "$2"); shift ;; - -L?*) argsBefore+=("$1") ;; - *) argsAfter+=("$1") ;; - esac - shift -done - -# Trace: -set -x -exec "@ld@" "${argsBefore[@]}" "${argsAfter[@]}" diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh deleted file mode 100644 index 97e4e45decf..00000000000 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ /dev/null @@ -1,189 +0,0 @@ -#! @shell@ -set -eu -o pipefail -shopt -s nullglob - -path_backup="$PATH" - -# phase separation makes this look useless -# shellcheck disable=SC2157 -if [ -n "@coreutils_bin@" ]; then - PATH="@coreutils_bin@/bin" -fi - -source @out@/nix-support/utils.sh - -if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then - source @out@/nix-support/add-flags.sh -fi - - -# Optionally filter out paths not refering to the store. -expandResponseParams "$@" -if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}" - && ( -z "$NIX_@infixSalt@_IGNORE_LD_THROUGH_GCC" || -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ) ]]; then - rest=() - 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" = -rpath ] && badPath "$p2"; then - n+=1; skip "$p2" - elif [ "$p" = -dynamic-linker ] && badPath "$p2"; then - n+=1; skip "$p2" - elif [ "${p:0:1}" = / ] && badPath "$p"; then - # We cannot skip this; barf. - echo "impure path \`$p' used in link" >&2 - exit 1 - elif [ "${p:0:9}" = --sysroot ]; then - # Our ld is not built with sysroot support (Can we fix that?) - : - else - rest+=("$p") - fi - n+=1 - done - # Old bash empty array hack - params=(${rest+"${rest[@]}"}) -fi - -source @out@/nix-support/add-hardening.sh - -extraAfter=("${hardeningLDFlags[@]}") -extraBefore=() - -if [ -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ]; then - extraAfter+=($NIX_@infixSalt@_LDFLAGS) - extraBefore+=($NIX_@infixSalt@_LDFLAGS_BEFORE) -fi - -extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER) - -# Choose 32-bit dynamic linker if needed -if [ -e @out@/nix-support/dynamic-linker-m32 ]; then - prev= - for p in ${params+"${params[@]}"}; do - if [[ "$prev" = "-m" && "$p" = "elf_i386" ]]; then - extraAfter+=( - '-dynamic-linker' - "$(< @out@/nix-support/dynamic-linker-m32)" - ) - break - fi - prev="$p" - done -fi - -declare -a libDirs -declare -A libs -relocatable= - -# Find all -L... switches for rpath, and relocatable flags for build id. -if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then - prev= - # Old bash thinks empty arrays are undefined, ugh. - for p in \ - ${extraBefore+"${extraBefore[@]}"} \ - ${params+"${params[@]}"} \ - ${extraAfter+"${extraAfter[@]}"} - do - case "$prev" in - -L) - libDirs+=("$p") - ;; - -l) - libs["lib${p}.so"]=1 - ;; - -dynamic-linker | -plugin) - # Ignore this argument, or it will match *.so and be added to rpath. - ;; - *) - case "$p" in - -L/*) - libDirs+=("${p:2}") - ;; - -l?*) - libs["lib${p:2}.so"]=1 - ;; - "${NIX_STORE:-}"/*.so | "${NIX_STORE:-}"/*.so.*) - # This is a direct reference to a shared library. - libDirs+=("${p%/*}") - libs["${p##*/}"]=1 - ;; - -r | --relocatable | -i) - relocatable=1 - esac - ;; - esac - prev="$p" - done -fi - - -# Add all used dynamic libraries to the rpath. -if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then - # For each directory in the library search path (-L...), - # see if it contains a dynamic library used by a -l... flag. If - # so, add the directory to the rpath. - # 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+"${libDirs[@]}"}; do - if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then - dir="$dir2" - fi - if [ -n "${rpaths[$dir]:-}" ] || [[ "$dir" != "${NIX_STORE:-}"/* ]]; then - # If the path is not in the store, don't add it to the rpath. - # This typically happens for libraries in /tmp that are later - # copied to $out/lib. If not, we're screwed. - continue - fi - for path in "$dir"/*; do - file="${path##*/}" - if [ "${libs[$file]:-}" ]; then - # This library may have been provided by a previous directory, - # but if that library file is inside an output of the current - # derivation, it can be deleted after this compilation and - # should be found in a later directory, so we add all - # directories that contain any of the libraries to rpath. - rpaths["$dir"]=1 - extraAfter+=(-rpath "$dir") - break - fi - done - done - - if [ -n "${NIX_COREFOUNDATION_RPATH:-}" ]; then - extraAfter+=(-rpath $NIX_COREFOUNDATION_RPATH) - fi -fi - - -# Only add --build-id if this is a final link. FIXME: should build gcc -# with --enable-linker-build-id instead? -if [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then - extraAfter+=(--build-id) -fi - - -# Optionally print debug info. -if [ -n "${NIX_DEBUG:-}" ]; then - # Old bash workaround, see above. - echo "extra flags before to @prog@:" >&2 - printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2 - echo "original flags to @prog@:" >&2 - printf " %q\n" ${params+"${params[@]}"} >&2 - echo "extra flags after to @prog@:" >&2 - printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 -fi - -PATH="$path_backup" -# Old bash workaround, see above. -exec @prog@ \ - ${extraBefore+"${extraBefore[@]}"} \ - ${params+"${params[@]}"} \ - ${extraAfter+"${extraAfter[@]}"} diff --git a/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash b/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash deleted file mode 100644 index b7aa7ea5c09..00000000000 --- a/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash +++ /dev/null @@ -1,106 +0,0 @@ -#! @shell@ - -set -eu -o pipefail - -path_backup="$PATH" -if [ -n "@coreutils_bin@" ]; then - PATH="@coreutils_bin@/bin" -fi - -declare -r recurThreshold=300 - -declare overflowCount=0 -for ((n=0; n < $#; ++n)); do - case "${!n}" in - -l*) let overflowCount+=1 ;; - -reexport-l*) let overflowCount+=1 ;; - *) ;; - esac -done - -declare -a allArgs=() - -if (( "$overflowCount" <= "$recurThreshold" )); then - allArgs=("$@") -else - declare -a childrenLookup=() childrenLink=() - - while (( $# )); do - case "$1" in - -L/*) - childrenLookup+=("$1") - allArgs+=("$1") - ;; - -L) - echo "cctools LD does not support '-L foo' or '-l foo'" >&2 - exit 1 - ;; - -l) - echo "cctools LD does not support '-L foo' or '-l foo'" >&2 - exit 1 - ;; - -lazy_library | -lazy_framework | -lto_library) - # We aren't linking any "azy_library", "to_library", etc. - allArgs+=("$1") - ;; - -lazy-l | -weak-l) allArgs+=("$1") ;; - # We can't so easily prevent header issues from these. - -lSystem) allArgs+=("$1") ;; - # Special case as indirection seems like a bad idea for something - # so fundamental. Can be removed for simplicity. - -l?* | -reexport-l?*) childrenLink+=("$1") ;; - *) allArgs+=("$1") ;; - esac - - shift - done - - declare n=0 - while (( $n < "${#childrenLink[@]}" )); do - if [[ "${childrenLink[n]}" = -l* ]]; then - childrenLink[n]="-reexport${childrenLink[n]}" - fi - let ++n - done - unset n - - declare -r outputNameLibless=$(basename $( \ - if [[ -z "${outputName:+isUndefined}" ]]; then - echo unnamed - elif [[ "${outputName:0:3}" = lib ]]; then - echo "${outputName:3}" - else - echo "${outputName}" - fi)) - declare -ra children=("$outputNameLibless-reexport-delegate-0" \ - "$outputNameLibless-reexport-delegate-1") - - mkdir -p "$out/lib" - - PATH="$PATH:@out@/bin" - - symbolBloatObject=$outputNameLibless-symbol-hack.o - if [[ ! -e $symbolBloatObject ]]; then - printf '.private_extern _______child_hack_foo\nchild_hack_foo:\n' \ - | @binPrefix@as -- -o $symbolBloatObject - fi - - # first half of libs - @binPrefix@ld -macosx_version_min $MACOSX_DEPLOYMENT_TARGET -arch x86_64 -dylib \ - -o "$out/lib/lib${children[0]}.dylib" \ - -install_name "$out/lib/lib${children[0]}.dylib" \ - "${childrenLookup[@]}" "$symbolBloatObject" \ - "${childrenLink[@]:0:$((${#childrenLink[@]} / 2 ))}" - - # second half of libs - @binPrefix@ld -macosx_version_min $MACOSX_DEPLOYMENT_TARGET -arch x86_64 -dylib \ - -o "$out/lib/lib${children[1]}.dylib" \ - -install_name "$out/lib/lib${children[1]}.dylib" \ - "${childrenLookup[@]}" "$symbolBloatObject" \ - "${childrenLink[@]:$((${#childrenLink[@]} / 2 ))}" - - allArgs+=("-L$out/lib" "-l${children[0]}" "-l${children[1]}") -fi - -PATH="$path_backup" -exec @prog@ "${allArgs[@]}" diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index e43c1609edb..9273f50c667 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -74,14 +74,6 @@ ccWrapper_addCVars () { export NIX_${role}CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" fi - if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then - export NIX_${role}LDFLAGS+=" -L$1/lib64" - fi - - if [[ -d "$1/lib" ]]; then - export NIX_${role}LDFLAGS+=" -L$1/lib" - fi - if [[ -d "$1/Library/Frameworks" ]]; then export NIX_${role}CFLAGS_COMPILE+=" -F$1/Library/Frameworks" fi @@ -117,11 +109,6 @@ if [ -n "@cc@" ]; then fi # shellcheck disable=SC2157 -if [ -n "@binutils_bin@" ]; then - addToSearchPath _PATH @binutils_bin@/bin -fi - -# shellcheck disable=SC2157 if [ -n "@libc_bin@" ]; then addToSearchPath _PATH @libc_bin@/bin fi @@ -138,15 +125,5 @@ export NIX_${role}CC=@out@ export ${role}CC=@named_cc@ export ${role}CXX=@named_cxx@ -for CMD in \ - ar as nm objcopy ranlib strip strings size ld windres -do - if - PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null - then - export "${role}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}"; - fi -done - # No local scope in sourced file unset role |