Skip to content

Commit 47821f1

Browse files
committedJul 25, 2017
cc-wrapper: More quadratic performance fixes
This eliminates the slow lookup of whether we've already seen an rpath / library path entry. Issue #27609.
1 parent aa4a92d commit 47821f1

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed
 

‎pkgs/build-support/cc-wrapper/ld-wrapper.sh

+21-23
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN)
6464
# Add all used dynamic libraries to the rpath.
6565
if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
6666

67-
libPath=""
67+
declare -A libDirsSeen
Has comments. Original line has comments.
68+
declare -a libDirs
69+
6870
addToLibPath() {
6971
local path="$1"
7072
if [ "${path:0:1}" != / ]; then return 0; fi
@@ -76,29 +78,27 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
7678
fi
7779
;;
7880
esac
79-
case $libPath in
80-
*\ $path\ *) return 0 ;;
81-
esac
82-
libPath+=" $path "
81+
if [[ -z ${libDirsSeen[$path]} ]]; then
82+
libDirs+=("$path")
83+
libDirsSeen[$path]=1
84+
fi
8385
}
8486

87+
declare -A rpathsSeen
88+
declare -a rpaths
89+
8590
addToRPath() {
8691
# If the path is not in the store, don't add it to the rpath.
8792
# This typically happens for libraries in /tmp that are later
8893
# copied to $out/lib. If not, we're screwed.
8994
if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
90-
case $rpath in
91-
*\ $1\ *) return 0 ;;
92-
esac
93-
rpath+=" $1 "
94-
}
95-
96-
libs=""
97-
addToLibs() {
98-
libs+=" $1"
95+
if [[ -z ${rpathsSeen[$1]} ]]; then
96+
rpaths+=("$1")
97+
rpathsSeen[$1]=1
98+
fi
9999
}
100100

101-
rpath=""
101+
declare -a libs
102102

103103
# First, find all -L... switches.
104104
allParams=("${params[@]}" ${extra[@]})
@@ -112,10 +112,10 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
112112
addToLibPath ${p2}
113113
n=$((n + 1))
114114
elif [ "$p" = -l ]; then
115-
addToLibs ${p2}
115+
libs+=(${p2})
116116
n=$((n + 1))
117117
elif [ "${p:0:2}" = -l ]; then
118-
addToLibs ${p:2}
118+
libs+=(${p:2})
119119
elif [ "$p" = -dynamic-linker ]; then
120120
# Ignore the dynamic linker argument, or it
121121
# will get into the next 'elif'. We don't want
@@ -135,20 +135,18 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
135135
# so, add the directory to the rpath.
136136
# It's important to add the rpath in the order of -L..., so
137137
# the link time chosen objects will be those of runtime linking.
138-
139-
for i in $libPath; do
140-
for j in $libs; do
138+
for i in ${libDirs[@]}; do
139+
for j in ${libs[@]}; do
141140
if [ -f "$i/lib$j.so" ]; then
142141
addToRPath $i
143142
break
144143
fi
145144
done
146145
done
147146

148-
149147
# Finally, add `-rpath' switches.
150-
for i in $rpath; do
151-
extra+=(-rpath $i)
148+
for i in ${rpaths[@]}; do
149+
extra+=(-rpath "$i")
152150
done
153151
fi
154152

0 commit comments

Comments
 (0)
Please sign in to comment.