diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-07-25 18:46:49 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-07-25 18:46:49 +0200 |
commit | 47821f1cf0cd853d3d3dfea9259e02fea2766327 (patch) | |
tree | 1d78bee26b66c34fc29b5f91f91b83a344f463d7 /pkgs/build-support | |
parent | aa4a92d2df0eebde3e0d832d2c60071f50fe4e9f (diff) | |
download | nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.tar nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.tar.gz nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.tar.bz2 nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.tar.lz nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.tar.xz nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.tar.zst nixlib-47821f1cf0cd853d3d3dfea9259e02fea2766327.zip |
cc-wrapper: More quadratic performance fixes
This eliminates the slow lookup of whether we've already seen an rpath / library path entry. Issue #27609.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/cc-wrapper/ld-wrapper.sh | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 4b3906a2e10f..240082b5dfdc 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -64,7 +64,9 @@ extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) # Add all used dynamic libraries to the rpath. if [ "$NIX_DONT_SET_RPATH" != 1 ]; then - libPath="" + declare -A libDirsSeen + declare -a libDirs + addToLibPath() { local path="$1" if [ "${path:0:1}" != / ]; then return 0; fi @@ -76,29 +78,27 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then fi ;; esac - case $libPath in - *\ $path\ *) return 0 ;; - esac - libPath+=" $path " + if [[ -z ${libDirsSeen[$path]} ]]; then + libDirs+=("$path") + libDirsSeen[$path]=1 + fi } + declare -A rpathsSeen + declare -a rpaths + addToRPath() { # 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. if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi - case $rpath in - *\ $1\ *) return 0 ;; - esac - rpath+=" $1 " - } - - libs="" - addToLibs() { - libs+=" $1" + if [[ -z ${rpathsSeen[$1]} ]]; then + rpaths+=("$1") + rpathsSeen[$1]=1 + fi } - rpath="" + declare -a libs # First, find all -L... switches. allParams=("${params[@]}" ${extra[@]}) @@ -112,10 +112,10 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then addToLibPath ${p2} n=$((n + 1)) elif [ "$p" = -l ]; then - addToLibs ${p2} + libs+=(${p2}) n=$((n + 1)) elif [ "${p:0:2}" = -l ]; then - addToLibs ${p:2} + libs+=(${p:2}) elif [ "$p" = -dynamic-linker ]; then # Ignore the dynamic linker argument, or it # will get into the next 'elif'. We don't want @@ -135,9 +135,8 @@ 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. - - for i in $libPath; do - for j in $libs; do + for i in ${libDirs[@]}; do + for j in ${libs[@]}; do if [ -f "$i/lib$j.so" ]; then addToRPath $i break @@ -145,10 +144,9 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then done done - # Finally, add `-rpath' switches. - for i in $rpath; do - extra+=(-rpath $i) + for i in ${rpaths[@]}; do + extra+=(-rpath "$i") done fi |