diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-28 17:04:42 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-28 17:04:42 +0000 |
| commit | 3f9c84857617b0cf0d1824664e371fb6a4cac2e3 (patch) | |
| tree | c073e77c0c0362246ce7eaccb3c846b15b8d2417 /scripts | |
| parent | ddc865fb0ddee9ed75467a164f27472c2234910a (diff) | |
| download | busybox-w32-3f9c84857617b0cf0d1824664e371fb6a4cac2e3.tar.gz busybox-w32-3f9c84857617b0cf0d1824664e371fb6a4cac2e3.tar.bz2 busybox-w32-3f9c84857617b0cf0d1824664e371fb6a4cac2e3.zip | |
trylink: instead of build error, disable --gc-sections if GLIBC && STATIC
nameif: glibc build fixlet
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/trylink | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/scripts/trylink b/scripts/trylink index f57a8a160..283edfdbb 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
| @@ -47,13 +47,30 @@ try() { | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | check_cc() { | 49 | check_cc() { |
| 50 | if $CC $1 -shared -o /dev/null -xc /dev/null > /dev/null 2>&1; then | 50 | if $CC $1 -shared -o /dev/null -xc /dev/null >/dev/null 2>&1; then |
| 51 | echo "$1"; | 51 | echo "$1"; |
| 52 | else | 52 | else |
| 53 | echo "$2"; | 53 | echo "$2"; |
| 54 | fi | 54 | fi |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | check_libc_is_glibc() { | ||
| 58 | local tempname="/tmp/temp.$$.$RANDOM.c" | ||
| 59 | echo "\ | ||
| 60 | #include <stdlib.h> | ||
| 61 | /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ | ||
| 62 | #if defined(__GLIBC__) && !defined(__UCLIBC__) | ||
| 63 | syntax error here | ||
| 64 | #endif | ||
| 65 | " >"$tempname" | ||
| 66 | if $CC "$tempname" -c -o /dev/null >/dev/null 2>&1; then | ||
| 67 | echo "$2"; | ||
| 68 | else | ||
| 69 | echo "$1"; | ||
| 70 | fi | ||
| 71 | rm "$tempname" | ||
| 72 | } | ||
| 73 | |||
| 57 | EXE="$1" | 74 | EXE="$1" |
| 58 | CC="$2" | 75 | CC="$2" |
| 59 | LDFLAGS="$3" | 76 | LDFLAGS="$3" |
| @@ -64,6 +81,20 @@ LDLIBS="$6" | |||
| 64 | # The -Wl,--sort-section option is not supported by older versions of ld | 81 | # The -Wl,--sort-section option is not supported by older versions of ld |
| 65 | SORT_SECTION=`check_cc "-Wl,--sort-section -Wl,alignment" ""` | 82 | SORT_SECTION=`check_cc "-Wl,--sort-section -Wl,alignment" ""` |
| 66 | 83 | ||
| 84 | # Static linking against glibc produces buggy executables | ||
| 85 | # (glibc does not cope well with ld --gc-sections). | ||
| 86 | # See sources.redhat.com/bugzilla/show_bug.cgi?id=3400 | ||
| 87 | # Note that glibc is unsuitable for static linking anyway. | ||
| 88 | # We are removing -Wl,--gc-sections from link command line. | ||
| 89 | GC_SECTION=`( | ||
| 90 | . ./.config | ||
| 91 | if test x"$CONFIG_STATIC" = x"y"; then | ||
| 92 | check_libc_is_glibc "" "-Wl,--gc-sections" | ||
| 93 | else | ||
| 94 | echo "-Wl,--gc-sections" | ||
| 95 | fi | ||
| 96 | )` | ||
| 97 | |||
| 67 | # Sanitize lib list (dups, extra spaces etc) | 98 | # Sanitize lib list (dups, extra spaces etc) |
| 68 | LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs` | 99 | LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs` |
| 69 | 100 | ||
| @@ -76,7 +107,7 @@ try $CC $LDFLAGS \ | |||
| 76 | -o $EXE \ | 107 | -o $EXE \ |
| 77 | -Wl,--sort-common \ | 108 | -Wl,--sort-common \ |
| 78 | $SORT_SECTION \ | 109 | $SORT_SECTION \ |
| 79 | -Wl,--gc-sections \ | 110 | $GC_SECTION \ |
| 80 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 111 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
| 81 | $l_list \ | 112 | $l_list \ |
| 82 | || { | 113 | || { |
| @@ -100,7 +131,7 @@ while test "$LDLIBS"; do | |||
| 100 | -o $EXE \ | 131 | -o $EXE \ |
| 101 | -Wl,--sort-common \ | 132 | -Wl,--sort-common \ |
| 102 | $SORT_SECTION \ | 133 | $SORT_SECTION \ |
| 103 | -Wl,--gc-sections \ | 134 | $GC_SECTION \ |
| 104 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 135 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
| 105 | $l_list | 136 | $l_list |
| 106 | if test $? = 0; then | 137 | if test $? = 0; then |
| @@ -129,7 +160,7 @@ if ! test -f busybox_ldscript; then | |||
| 129 | -o $EXE \ | 160 | -o $EXE \ |
| 130 | -Wl,--sort-common \ | 161 | -Wl,--sort-common \ |
| 131 | $SORT_SECTION \ | 162 | $SORT_SECTION \ |
| 132 | -Wl,--gc-sections \ | 163 | $GC_SECTION \ |
| 133 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 164 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
| 134 | $l_list \ | 165 | $l_list \ |
| 135 | -Wl,--warn-common \ | 166 | -Wl,--warn-common \ |
| @@ -151,7 +182,7 @@ else | |||
| 151 | -o $EXE \ | 182 | -o $EXE \ |
| 152 | -Wl,--sort-common \ | 183 | -Wl,--sort-common \ |
| 153 | $SORT_SECTION \ | 184 | $SORT_SECTION \ |
| 154 | -Wl,--gc-sections \ | 185 | $GC_SECTION \ |
| 155 | -Wl,-T -Wl,busybox_ldscript \ | 186 | -Wl,-T -Wl,busybox_ldscript \ |
| 156 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 187 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
| 157 | $l_list \ | 188 | $l_list \ |
| @@ -207,7 +238,7 @@ if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then | |||
| 207 | -o $EXE \ | 238 | -o $EXE \ |
| 208 | -Wl,--sort-common \ | 239 | -Wl,--sort-common \ |
| 209 | $SORT_SECTION \ | 240 | $SORT_SECTION \ |
| 210 | -Wl,--gc-sections \ | 241 | $GC_SECTION \ |
| 211 | -Wl,--start-group $O_FILES -Wl,--end-group \ | 242 | -Wl,--start-group $O_FILES -Wl,--end-group \ |
| 212 | -L"$sharedlib_dir" -lbusybox \ | 243 | -L"$sharedlib_dir" -lbusybox \ |
| 213 | -Wl,--warn-common \ | 244 | -Wl,--warn-common \ |
| @@ -246,7 +277,7 @@ int main(int argc, char **argv) | |||
| 246 | -o $EXE \ | 277 | -o $EXE \ |
| 247 | -Wl,--sort-common \ | 278 | -Wl,--sort-common \ |
| 248 | $SORT_SECTION \ | 279 | $SORT_SECTION \ |
| 249 | -Wl,--gc-sections \ | 280 | $GC_SECTION \ |
| 250 | -L"$sharedlib_dir" -lbusybox \ | 281 | -L"$sharedlib_dir" -lbusybox \ |
| 251 | -Wl,--warn-common \ | 282 | -Wl,--warn-common \ |
| 252 | || { | 283 | || { |
