aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-07 17:05:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-07 17:05:22 +0000
commit3240474c23bf4f47536a854693b4cbacb54b9b04 (patch)
tree7736932b581341b317aea5bd208f9e648e895055
parente747f62ed69504825beb2c52b8f0448b3d3b72ed (diff)
downloadbusybox-w32-3240474c23bf4f47536a854693b4cbacb54b9b04.tar.gz
busybox-w32-3240474c23bf4f47536a854693b4cbacb54b9b04.tar.bz2
busybox-w32-3240474c23bf4f47536a854693b4cbacb54b9b04.zip
reviving libbusybox, adding CONFIG_INDIVIDUAL part 1
-rw-r--r--Makefile12
-rwxr-xr-xscripts/trylink97
2 files changed, 88 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 2dced88e4..5cc4ab291 100644
--- a/Makefile
+++ b/Makefile
@@ -568,11 +568,13 @@ busybox-all := $(core-y) $(libs-y)
568# Rule to link busybox - also used during CONFIG_KALLSYMS 568# Rule to link busybox - also used during CONFIG_KALLSYMS
569# May be overridden by arch/$(ARCH)/Makefile 569# May be overridden by arch/$(ARCH)/Makefile
570quiet_cmd_busybox__ ?= LINK $@ 570quiet_cmd_busybox__ ?= LINK $@
571 cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) \ 571 cmd_busybox__ ?= $(srctree)/scripts/trylink \
572 -o $@ -Wl,-Map -Wl,$@.map \ 572 "$@" \
573 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ 573 "$(CC)" \
574 -Wl,--start-group $(busybox-all) -Wl,--end-group \ 574 "$(LDFLAGS) $(EXTRA_LDFLAGS)" \
575 $(LDLIBS) 575 "$(core-y)" \
576 "$(libs-y)" \
577 "$(LDLIBS)"
576 578
577# Generate System.map 579# Generate System.map
578quiet_cmd_sysmap = SYSMAP 580quiet_cmd_sysmap = SYSMAP
diff --git a/scripts/trylink b/scripts/trylink
index 0b8f6c062..19b0ba715 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -3,24 +3,40 @@
3debug=false 3debug=false
4 4
5try() { 5try() {
6 added="$1" 6 printf "%s\n" "Output of:" >$EXE.out
7 shift 7 printf "%s\n" "$*" >>$EXE.out
8 $debug && echo "Trying: $* $added" 8 printf "%s\n" "==========" >>$EXE.out
9 "$@" $added 2>busybox_ld.err 9 $debug && echo "Trying: $*"
10 "$@" >>$EXE.out 2>&1
11 exitcode=$?
12 cat $EXE.out
13 return $exitcode
10} 14}
11 15
16EXE="$1"
17CC="$2"
18LDFLAGS="$3"
19O_FILES="$4"
20A_FILES="$5"
21LDLIBS="$6"
22
12# Sanitize lib list (dups, extra spaces etc) 23# Sanitize lib list (dups, extra spaces etc)
13#echo "BBOX_LIB_LIST=$BBOX_LIB_LIST"
14BBOX_LIB_LIST=`echo "$BBOX_LIB_LIST" | xargs -n1 | sort | uniq | xargs` 24BBOX_LIB_LIST=`echo "$BBOX_LIB_LIST" | xargs -n1 | sort | uniq | xargs`
15 25
16# First link with all libs. If it fails, bail out 26# First link with all libs. If it fails, bail out
17echo "Trying libraries: $BBOX_LIB_LIST" 27echo "Trying libraries: $BBOX_LIB_LIST"
28# "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
18l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` 29l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
19test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" 30test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
20try "$l_list" "$@" \ 31try $CC $LDFLAGS \
32 -o $EXE -Wl,-Map -Wl,$EXE.map \
33 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
34 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
35 $l_list \
36 >/dev/null \
21|| { 37|| {
22 echo "Failed: $* -Wl,--start-group $l_list -Wl,--end-group" 38 echo "Failed: $* $l_list"
23 cat busybox_ld.err 39 cat $EXE.out
24 exit 1 40 exit 1
25} 41}
26 42
@@ -31,15 +47,22 @@ while test "$BBOX_LIB_LIST"; do
31 all_needed=true 47 all_needed=true
32 for one in $BBOX_LIB_LIST; do 48 for one in $BBOX_LIB_LIST; do
33 without_one=`echo " $BBOX_LIB_LIST " | sed "s/ $one / /g" | xargs` 49 without_one=`echo " $BBOX_LIB_LIST " | sed "s/ $one / /g" | xargs`
50 # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
34 l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` 51 l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
35 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" 52 test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
36 $debug && echo "Trying -l options: '$l_list'" 53 $debug && echo "Trying -l options: '$l_list'"
37 if try "$l_list" "$@"; then 54 try $CC $LDFLAGS \
38 echo "Library $one is not needed" 55 -o $EXE -Wl,-Map -Wl,$EXE.map \
39 BBOX_LIB_LIST="$without_one" 56 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
40 all_needed=false 57 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
58 $l_list \
59 >/dev/null
60 if test $? = 0; then
61 echo "Library $one is not needed"
62 BBOX_LIB_LIST="$without_one"
63 all_needed=false
41 else 64 else
42 echo "Library $one is needed" 65 echo "Library $one is needed"
43 fi 66 fi
44 done 67 done
45 # All libs were needed, can't remove any 68 # All libs were needed, can't remove any
@@ -56,13 +79,55 @@ l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
56test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose" 79test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose"
57# --verbose gives us gobs of info to stdout (e.g. linker script used) 80# --verbose gives us gobs of info to stdout (e.g. linker script used)
58if ! test -f busybox_ldscript; then 81if ! test -f busybox_ldscript; then
59 try "$l_list -Wl,--verbose" "$@" >busybox_ld.out 82 try $CC $LDFLAGS \
83 -o $EXE -Wl,-Map -Wl,$EXE.map \
84 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
85 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
86 $l_list -Wl,--verbose \
87 >/dev/null
60else 88else
61 echo "Custom linker script 'busybox_ldscript' found, using it" 89 echo "Custom linker script 'busybox_ldscript' found, using it"
62 # Add SORT_BY_ALIGNMENT to linker script (found in busybox_ld.out): 90 # Add SORT_BY_ALIGNMENT to linker script (found in ${EXE}_ld.out):
63 # .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) } 91 # .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) }
64 # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) 92 # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*)
65 # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) 93 # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*)
66 # This will eliminate most of the data padding (~3kb). 94 # This will eliminate most of the data padding (~3kb).
67 try "$l_list -Wl,--verbose -Wl,-T -Wl,busybox_ldscript" "$@" >busybox_ld.out 95 try $CC $LDFLAGS \
96 -o $EXE -Wl,-Map -Wl,$EXE.map \
97 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
98 -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
99 $l_list -Wl,--verbose \
100 -Wl,-T -Wl,busybox_ldscript \
101 >/dev/null
68fi 102fi
103
104mkdir 0lib 2>/dev/null
105test -d 0lib || exit 1
106ln -s libbusybox.so.1.8.0 0lib/libbusybox.so 2>/dev/null
107
108EXE="0lib/libbusybox.so.1.8.0"
109try $CC $LDFLAGS \
110 -o $EXE -Wl,-Map -Wl,$EXE.map \
111 -shared -fPIC -Wl,--enable-new-dtags \
112 -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \
113 $l_list -Wl,--verbose \
114 -Wl,-soname="libbusybox.so.1.8.0" \
115 -Wl,-z,combreloc \
116 >/dev/null \
117|| {
118 echo "Linking $EXE failed"
119 exit 1
120}
121
122EXE="0lib/busybox"
123try $CC $LDFLAGS \
124 -o $EXE -Wl,-Map -Wl,$EXE.map \
125 -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
126 -Wl,--start-group $O_FILES -Wl,--end-group \
127 $l_list -Wl,--verbose \
128 -L"0lib" -lbusybox \
129 >/dev/null \
130|| {
131 echo "Linking $EXE failed"
132 exit 1
133}