Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/scripts/trylink
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/scripts/trylink
r3232 r3621 47 47 48 48 check_cc() { 49 local tempname="/tmp/temp.$$.$RANDOM" 49 local tempname="$(mktemp)" 50 local r 51 echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c 50 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. 52 if $CC $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then 53 echo "$1"; 54 else 55 echo "$2"; 56 fi 57 rm "$tempname".o 2>/dev/null 53 # Was using "-xc /dev/null", but we need a valid C program. 54 # "eval" may be needed if CFLAGS can contain 55 # '... -D"BB_VER=KBUILD_STR(1.N.M)" ...' 56 # and we need shell to process quotes! 57 $CC $CFLAGS $LDFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1 58 r=$? 59 rm -f "$tempname" "$tempname".c "$tempname".o 60 return $r 58 61 } 59 62 60 63 check_libc_is_glibc() { 61 local tempname="/tmp/temp.$$.$RANDOM" 64 local tempname="$(mktemp)" 65 local r 62 66 echo "\ 63 67 #include <stdlib.h> … … 67 71 #endif 68 72 " >"$tempname".c 69 if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then 70 echo "$2"; 71 else 72 echo "$1"; 73 fi 74 rm "$tempname".c "$tempname".o 2>/dev/null 73 ! $CC $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1 74 r=$? 75 rm -f "$tempname" "$tempname".c "$tempname".o 76 return $r 75 77 } 76 78 … … 84 86 85 87 # The --sort-section option is not supported by older versions of ld 86 SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""` 88 SORT_SECTION="-Wl,--sort-section,alignment" 89 if ! check_cc "-Wl,--sort-section,alignment"; then 90 echo "Your linker does not support --sort-section,alignment" 91 SORT_SECTION="" 92 fi 87 93 88 94 START_GROUP="-Wl,--start-group" … … 91 97 92 98 # gold may not support --sort-common (yet) 93 SORT_COMMON=`check_cc "-Wl,--sort-common" ""` 99 SORT_COMMON="-Wl,--sort-common" 100 if ! check_cc "-Wl,--sort-common"; then 101 echo "Your linker does not support --sort-common" 102 SORT_COMMON="" 103 fi 94 104 95 105 # Static linking against glibc produces buggy executables … … 98 108 # Note that glibc is unsuitable for static linking anyway. 99 109 # We are removing -Wl,--gc-sections from link command line. 100 GC_SECTIONS=`( 101 . ./.config 102 if test x"$CONFIG_STATIC" = x"y"; then 103 check_libc_is_glibc "" "-Wl,--gc-sections" 104 else 105 echo "-Wl,--gc-sections" 106 fi 107 )` 108 110 GC_SECTIONS="-Wl,--gc-sections" 111 if (. ./.config && test x"$CONFIG_STATIC" = x"y") then 112 if check_libc_is_glibc; then 113 echo "Static linking against glibc, can't use --gc-sections" 114 GC_SECTIONS="" 115 fi 116 fi 109 117 # The --gc-sections option is not supported by older versions of ld 110 118 if 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 112 123 fi 113 124 … … 118 129 echo "Trying libraries: $LDLIBS" 119 130 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" 120 l_list=`echo " $LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`131 l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` 121 132 test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" 122 133 try $CC $CFLAGS $LDFLAGS \ … … 130 141 echo "Failed: $l_list" 131 142 cat $EXE.out 143 echo 'Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.' 144 echo 'Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"' 132 145 exit 1 133 146 } … … 142 155 without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` 143 156 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" 144 l_list=`echo " $without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`157 l_list=`echo " $without_one " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` 145 158 test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" 146 159 $debug && echo "Trying -l options: '$l_list'" … … 173 186 # Make the binary with final, minimal list of libs 174 187 echo "Final link with: ${LDLIBS:-<none>}" 175 l_list=`echo " $LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`188 l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` 176 189 test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" 177 190 # --verbose gives us gobs of info to stdout (e.g. linker script used) … … 197 210 # This will eliminate most of the padding (~3kb). 198 211 # Hmm, "ld --sort-section alignment" should do it too. 212 # 213 # There is a ld hack which is meant to decrease disk usage 214 # at the cost of more RAM usage (??!!) in standard ld script: 215 # /* Adjust the address for the data segment. We want to adjust up to 216 # the same address within the page on the next page up. */ 217 # . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000); 218 # Replace it with: 219 # . = ALIGN (0x1000); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000); 220 # to unconditionally align .data to the next page boundary, 221 # instead of "next page, plus current offset in this page" 199 222 try $CC $CFLAGS $LDFLAGS \ 200 223 -o $EXE \ … … 269 292 if test "$CONFIG_FEATURE_INDIVIDUAL" = y; then 270 293 echo "Linking individual applets against libbusybox (see $sharedlib_dir/*)" 271 gcc -DNAME_MAIN _CNAME-E -include include/autoconf.h include/applets.h \294 gcc -DNAME_MAIN -E -include include/autoconf.h include/applets.h \ 272 295 | grep -v "^#" \ 273 | grep -v "^ $" \296 | grep -v "^ *$" \ 274 297 > applet_lst.tmp 275 298 while read name main junk; do … … 301 324 rm -- "$sharedlib_dir/applet.c" $EXE.out 302 325 $STRIP -s --remove-section=.note --remove-section=.comment $EXE 326 # Let user see that we do something - list the names of created binaries: 327 echo "$EXE" 303 328 304 329 done <applet_lst.tmp
Note:
See TracChangeset
for help on using the changeset viewer.