aboutsummaryrefslogtreecommitdiff
path: root/scripts/trylink
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/trylink')
-rwxr-xr-xscripts/trylink59
1 files changed, 35 insertions, 24 deletions
diff --git a/scripts/trylink b/scripts/trylink
index 48c487bcd..357aa6277 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -47,18 +47,22 @@ try() {
47 47
48check_cc() { 48check_cc() {
49 local tempname="$(mktemp)" 49 local tempname="$(mktemp)"
50 local r
51 echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c
50 # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :( 52 # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :(
51 # "-xc": C language. "/dev/null" is an empty source file. 53 # Was using "-xc /dev/null", but we need a valid C program.
52 if $CC $CPPFLAGS $CFLAGS $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then 54 # "eval" may be needed if CFLAGS can contain
53 echo "$1"; 55 # '... -D"BB_VER=KBUILD_STR(1.N.M)" ...'
54 else 56 # and we need shell to process quotes!
55 echo "$2"; 57 $CC $CFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1
56 fi 58 r=$?
57 rm -f "$tempname" "$tempname".o 59 rm -f "$tempname" "$tempname".c "$tempname".o
60 return $r
58} 61}
59 62
60check_libc_is_glibc() { 63check_libc_is_glibc() {
61 local tempname="$(mktemp)" 64 local tempname="$(mktemp)"
65 local r
62 echo "\ 66 echo "\
63 #include <stdlib.h> 67 #include <stdlib.h>
64 /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ 68 /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
@@ -66,12 +70,10 @@ check_libc_is_glibc() {
66 syntax error here 70 syntax error here
67 #endif 71 #endif
68 " >"$tempname".c 72 " >"$tempname".c
69 if $CC $CPPFLAGS $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then 73 ! $CC $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1
70 echo "$2"; 74 r=$?
71 else 75 rm -f "$tempname" "$tempname".c "$tempname".o
72 echo "$1"; 76 return $r
73 fi
74 rm -f "$tempname" "$tempname".[co]
75} 77}
76 78
77EXE="$1" 79EXE="$1"
@@ -83,32 +85,41 @@ A_FILES="$6"
83LDLIBS="$7" 85LDLIBS="$7"
84 86
85# The --sort-section option is not supported by older versions of ld 87# The --sort-section option is not supported by older versions of ld
86SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""` 88SORT_SECTION="-Wl,--sort-section,alignment"
89if ! check_cc "-Wl,--sort-section,alignment"; then
90 echo "Your linker does not support --sort-section,alignment"
91 SORT_SECTION=""
92fi
87 93
88START_GROUP="-Wl,--start-group" 94START_GROUP="-Wl,--start-group"
89END_GROUP="-Wl,--end-group" 95END_GROUP="-Wl,--end-group"
90INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" 96INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose"
91 97
92# gold may not support --sort-common (yet) 98# gold may not support --sort-common (yet)
93SORT_COMMON=`check_cc "-Wl,--sort-common" ""` 99SORT_COMMON="-Wl,--sort-common"
100if ! check_cc "-Wl,--sort-common"; then
101 echo "Your linker does not support --sort-common"
102 SORT_COMMON=""
103fi
94 104
95# Static linking against glibc produces buggy executables 105# Static linking against glibc produces buggy executables
96# (glibc does not cope well with ld --gc-sections). 106# (glibc does not cope well with ld --gc-sections).
97# See sources.redhat.com/bugzilla/show_bug.cgi?id=3400 107# See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
98# Note that glibc is unsuitable for static linking anyway. 108# Note that glibc is unsuitable for static linking anyway.
99# We are removing -Wl,--gc-sections from link command line. 109# We are removing -Wl,--gc-sections from link command line.
100GC_SECTIONS=`( 110GC_SECTIONS="-Wl,--gc-sections"
101. ./.config 111if (. ./.config && test x"$CONFIG_STATIC" = x"y") then
102if test x"$CONFIG_STATIC" = x"y"; then 112 if check_libc_is_glibc; then
103 check_libc_is_glibc "" "-Wl,--gc-sections" 113 echo "Static linking against glibc, can't use --gc-sections"
104else 114# GC_SECTIONS=""
105 echo "-Wl,--gc-sections" 115 fi
106fi 116fi
107)`
108
109# The --gc-sections option is not supported by older versions of ld 117# The --gc-sections option is not supported by older versions of ld
110if test -n "$GC_SECTIONS"; then 118if test -n "$GC_SECTIONS"; then
111 GC_SECTIONS=`check_cc "$GC_SECTIONS" ""` 119 if ! check_cc "$GC_SECTIONS"; then
120 echo "Your linker does not support $GC_SECTIONS"
121 GC_SECTIONS=""
122 fi
112fi 123fi
113 124
114# Sanitize lib list (dups, extra spaces etc) 125# Sanitize lib list (dups, extra spaces etc)