From 07674788d6932fe702117649b4cd16512d2da8a9 Mon Sep 17 00:00:00 2001 From: Orivej Desh Date: Tue, 1 Aug 2017 08:27:50 +0000 Subject: 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`. --- pkgs/build-support/cc-wrapper/ld-wrapper.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'pkgs/build-support/cc-wrapper') 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" -- cgit 1.4.1