diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/trylink | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/scripts/trylink b/scripts/trylink index 6b74f092d..2255deee7 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
@@ -1,5 +1,6 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | #debug=true | ||
3 | debug=false | 4 | debug=false |
4 | 5 | ||
5 | # Linker flags used: | 6 | # Linker flags used: |
@@ -77,7 +78,13 @@ CFLAGS="$3" | |||
77 | LDFLAGS="$4" | 78 | LDFLAGS="$4" |
78 | O_FILES="$5" | 79 | O_FILES="$5" |
79 | A_FILES="$6" | 80 | A_FILES="$6" |
81 | # We try to drop libraries from LDLIBS if build works without them, | ||
82 | # but ones from CONFIG_EXTRA_LDLIBS are always linked in. | ||
83 | # (For example, musl has stub utmp implementation, and if you link with | ||
84 | # a real utmp library in LDLIBS, dropping it "works" but resulting binary | ||
85 | # does not work properly). | ||
80 | LDLIBS="$7" | 86 | LDLIBS="$7" |
87 | CONFIG_EXTRA_LDLIBS="$8" | ||
81 | 88 | ||
82 | # The --sort-section option is not supported by older versions of ld | 89 | # The --sort-section option is not supported by older versions of ld |
83 | SORT_SECTION="-Wl,--sort-section,alignment" | 90 | SORT_SECTION="-Wl,--sort-section,alignment" |
@@ -125,8 +132,8 @@ LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs` | |||
125 | # First link with all libs. If it fails, bail out | 132 | # First link with all libs. If it fails, bail out |
126 | echo "Trying libraries: $LDLIBS" | 133 | echo "Trying libraries: $LDLIBS" |
127 | # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" | 134 | # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" |
128 | l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` | 135 | l_list=`echo " $LDLIBS $CONFIG_EXTRA_LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g' -e 's/^ *//'` |
129 | test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" | 136 | test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" |
130 | try $CC $CFLAGS $LDFLAGS \ | 137 | try $CC $CFLAGS $LDFLAGS \ |
131 | -o $EXE \ | 138 | -o $EXE \ |
132 | $SORT_COMMON \ | 139 | $SORT_COMMON \ |
@@ -151,7 +158,7 @@ while test "$LDLIBS"; do | |||
151 | for one in $LDLIBS; do | 158 | for one in $LDLIBS; do |
152 | without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` | 159 | without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` |
153 | # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" | 160 | # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" |
154 | l_list=`echo " $without_one " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` | 161 | l_list=`echo " $without_one $CONFIG_EXTRA_LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g' -e 's/^ *//'` |
155 | test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" | 162 | test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" |
156 | $debug && echo "Trying -l options: '$l_list'" | 163 | $debug && echo "Trying -l options: '$l_list'" |
157 | try $CC $CFLAGS $LDFLAGS \ | 164 | try $CC $CFLAGS $LDFLAGS \ |
@@ -179,8 +186,8 @@ done | |||
179 | 186 | ||
180 | # Make the binary with final, minimal list of libs | 187 | # Make the binary with final, minimal list of libs |
181 | echo "Final link with: ${LDLIBS:-<none>}" | 188 | echo "Final link with: ${LDLIBS:-<none>}" |
182 | l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` | 189 | l_list=`echo " $LDLIBS $CONFIG_EXTRA_LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g' -e 's/^ *//'` |
183 | test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" | 190 | test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" |
184 | # --verbose gives us gobs of info to stdout (e.g. linker script used) | 191 | # --verbose gives us gobs of info to stdout (e.g. linker script used) |
185 | if ! test -f busybox_ldscript; then | 192 | if ! test -f busybox_ldscript; then |
186 | try $CC $CFLAGS $LDFLAGS \ | 193 | try $CC $CFLAGS $LDFLAGS \ |