diff options
author | Orivej Desh <orivej@gmx.fr> | 2017-08-01 08:27:50 +0000 |
---|---|---|
committer | Robin Gloster <mail@glob.in> | 2017-08-01 11:57:33 +0200 |
commit | 07674788d6932fe702117649b4cd16512d2da8a9 (patch) | |
tree | 1d5d6e213efc578fd45f50dddaa4e5f0f4debb5d /pkgs/build-support/cc-wrapper | |
parent | 6341cc91014142e17e58dbcd64907889c9895eb8 (diff) | |
download | nixlib-07674788d6932fe702117649b4cd16512d2da8a9.tar nixlib-07674788d6932fe702117649b4cd16512d2da8a9.tar.gz nixlib-07674788d6932fe702117649b4cd16512d2da8a9.tar.bz2 nixlib-07674788d6932fe702117649b4cd16512d2da8a9.tar.lz nixlib-07674788d6932fe702117649b4cd16512d2da8a9.tar.xz nixlib-07674788d6932fe702117649b4cd16512d2da8a9.tar.zst nixlib-07674788d6932fe702117649b4cd16512d2da8a9.zip |
Respect NIX_DONT_SET_RPATH when .so appears in the command line
Unified processing of command line arguments in ld-wrapper broke support for `NIX_DONT_SET_RPATH` and revealed that ld-wrapper adds the directory of its `-plugin` argument to runpath. This pull request fixes that. It treats `dir/libname.so` as `-L dir -l name`, because this is how `ld.so` interprets resulting binary: with `dir` in `RUNPATH` and the bare `libname.so` (without `dir`) in `NEEDED`, it looks for `libname.so` in each `RUNPATH` and chooses the first, even when the linker was invoked with an absolute path to `.so`.
Diffstat (limited to 'pkgs/build-support/cc-wrapper')
-rw-r--r-- | pkgs/build-support/cc-wrapper/ld-wrapper.sh | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 283a6fb3ef94..72c0be304acb 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -62,7 +62,6 @@ fi extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) -declare -A rpaths declare -a libDirs declare -A libs relocatable= @@ -78,9 +77,8 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then -l) libs["lib${p}.so"]=1 ;; - -dynamic-linker) - # Ignore the dynamic linker argument, or it - # will match *.so and be added to rpath. + -dynamic-linker | -plugin) + # Ignore this argument, or it will match *.so and be added to rpath. ;; *) case "$p" in @@ -91,13 +89,9 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then libs["lib${p:2}.so"]=1 ;; "$NIX_STORE"/*.so | "$NIX_STORE"/*.so.*) - # This is a direct reference to a shared library, so add - # its directory to the rpath. - dir="${p%/*}" - if [ ! "${rpaths[$dir]}" ]; then - rpaths["$dir"]=1 - extra+=(-rpath "$dir") - fi + # This is a direct reference to a shared library. + libDirs+=("${p%/*}") + libs["${p##*/}"]=1 ;; -r | --relocatable | -i) relocatable=1 @@ -116,6 +110,7 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then # 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[@]}"; do if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then dir="$dir2" |