From fdbda216b1864a23cb2582fa93793baa32821f46 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 30 Aug 2017 14:57:20 -0400 Subject: cc-wrapper: Clean up dynamic linking with x86 multilib It's better layering to do everything in ld-wrapper. Also, use numeric comparisons for `relocatable`. --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 4 ---- pkgs/build-support/cc-wrapper/ld-wrapper.sh | 33 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index e6f5a5a9f7d8..f1f56cf5cec4 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -61,10 +61,6 @@ while (( "$n" < "$nParams" )); do cppInclude=0 elif [ "${p:0:1}" != - ]; then nonFlagArgs=1 - elif [ "$p" = -m32 ]; then - if [ -e @out@/nix-support/dynamic-linker-m32 ]; then - NIX_@infixSalt@_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" - fi fi n+=1 done diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 355ea8818981..bbab3c43d6f8 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -67,12 +67,22 @@ fi extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER) +# Three tasks: +# +# 1. Find all -L... switches for rpath +# +# 2. Find relocatable flag for build id. +# +# 3. Choose 32-bit dynamic linker if needed declare -a libDirs declare -A libs -relocatable= +declare -i relocatable=0 link32=0 -# 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 +if + [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] \ + || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] \ + || [ -e @out@/nix-support/dynamic-linker-m32 ] +then prev= # Old bash thinks empty arrays are undefined, ugh. for p in \ @@ -87,6 +97,13 @@ if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_I -l) libs["lib${p}.so"]=1 ;; + -m) + # Presumably only the last `-m` flag has any effect. + case "$p" in + elf_i386) link32=1;; + *) link32=0;; + esac + ;; -dynamic-linker | -plugin) # Ignore this argument, or it will match *.so and be added to rpath. ;; @@ -112,6 +129,14 @@ if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_I done fi +if [ -e "@out@/nix-support/dynamic-linker-m32" ] && (( "$link32" )); then + # We have an alternate 32-bit linker and we're producing a 32-bit ELF, let's + # use it. + extraAfter+=( + '-dynamic-linker' + "$(< @out@/nix-support/dynamic-linker-m32)" + ) +fi # Add all used dynamic libraries to the rpath. if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then @@ -154,7 +179,7 @@ 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 +if [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] && ! (( "$relocatable" )); then extraAfter+=(--build-id) fi -- cgit 1.4.1