diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-09 13:49:26 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-09 13:49:26 +0000 |
commit | 01f3b2c91a1b48fa730b3f0bd5da73b1210a5ac9 (patch) | |
tree | b48778f931c79aa6705860436130a1443ecce790 /scripts/trylink | |
parent | d19b87ece4add3dd24bea9d9d0b32946c219ef2c (diff) | |
download | busybox-w32-01f3b2c91a1b48fa730b3f0bd5da73b1210a5ac9.tar.gz busybox-w32-01f3b2c91a1b48fa730b3f0bd5da73b1210a5ac9.tar.bz2 busybox-w32-01f3b2c91a1b48fa730b3f0bd5da73b1210a5ac9.zip |
trylink: reformat link flags for readability
trylink: add --sort-section alignment:
text data bss dec hex filename
- 6557 428 3260 10245 2805 busybox
+ 6555 428 3260 10243 2803 busybox
- 909621 1076 12108 922805 e14b5 libbusybox.so.1.8.0.svn
+ 908868 1050 12016 921934 e114e libbusybox.so.1.8.0.svn
Diffstat (limited to 'scripts/trylink')
-rwxr-xr-x | scripts/trylink | 114 |
1 files changed, 89 insertions, 25 deletions
diff --git a/scripts/trylink b/scripts/trylink index 0829121ab..cbba9000a 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
@@ -2,6 +2,42 @@ | |||
2 | 2 | ||
3 | debug=false | 3 | debug=false |
4 | 4 | ||
5 | # Linker flags used: | ||
6 | # | ||
7 | # Informational: | ||
8 | # --warn-common | ||
9 | # -Map $EXE.map | ||
10 | # --verbose | ||
11 | # | ||
12 | # Optimizations: | ||
13 | # --sort-common reduces padding | ||
14 | # --sort-section alignment reduces padding | ||
15 | # --gc-sections throws out unused sections, | ||
16 | # does not work for shared libs | ||
17 | # -O Not used, maybe useful? | ||
18 | # | ||
19 | # List of files to link: | ||
20 | # $l_list == --start-group -llib1 -llib2 --end-group | ||
21 | # --start-group $O_FILES $A_FILES --end-group | ||
22 | # or for shlib: | ||
23 | # --start-group --whole-archive $A_FILES --no-whole-archive --end-group | ||
24 | # otherwise we don't pull in all parts of *.a files. Now we pull in too much. | ||
25 | # FIXME: make it work without --whole-archive, or better, with --gc-sections. | ||
26 | # | ||
27 | # Shared library link: | ||
28 | # -shared self-explanatory | ||
29 | # -fPIC position-independent code | ||
30 | # -Wl,--enable-new-dtags ? | ||
31 | # -Wl,-z,combreloc ? | ||
32 | # -Wl,-soname="libbusybox.so.$BB_VER" | ||
33 | # -static Not used, but may be useful! manpage: | ||
34 | # "... This option can be used with -shared. | ||
35 | # Doing so means that a shared library | ||
36 | # is being created but that all of the library's | ||
37 | # external references must be resolved by pulling | ||
38 | # in entries from static libraries." | ||
39 | |||
40 | |||
5 | try() { | 41 | try() { |
6 | printf "%s\n" "Output of:" >$EXE.out | 42 | printf "%s\n" "Output of:" >$EXE.out |
7 | printf "%s\n" "$*" >>$EXE.out | 43 | printf "%s\n" "$*" >>$EXE.out |
@@ -28,8 +64,10 @@ echo "Trying libraries: $LDLIBS" | |||
28 | l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` | 64 | l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` |
29 | test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" | 65 | test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" |
30 | try $CC $LDFLAGS \ | 66 | try $CC $LDFLAGS \ |
31 | -o $EXE -Wl,-Map -Wl,$EXE.map \ | 67 | -o $EXE \ |
32 | -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | 68 | -Wl,--sort-common \ |
69 | -Wl,--sort-section -Wl,alignment \ | ||
70 | -Wl,--gc-sections \ | ||
33 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 71 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
34 | $l_list \ | 72 | $l_list \ |
35 | || { | 73 | || { |
@@ -50,8 +88,10 @@ while test "$LDLIBS"; do | |||
50 | test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" | 88 | test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" |
51 | $debug && echo "Trying -l options: '$l_list'" | 89 | $debug && echo "Trying -l options: '$l_list'" |
52 | try $CC $LDFLAGS \ | 90 | try $CC $LDFLAGS \ |
53 | -o $EXE -Wl,-Map -Wl,$EXE.map \ | 91 | -o $EXE \ |
54 | -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | 92 | -Wl,--sort-common \ |
93 | -Wl,--sort-section -Wl,alignment \ | ||
94 | -Wl,--gc-sections \ | ||
55 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 95 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
56 | $l_list | 96 | $l_list |
57 | if test $? = 0; then | 97 | if test $? = 0; then |
@@ -77,10 +117,15 @@ test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" | |||
77 | # --verbose gives us gobs of info to stdout (e.g. linker script used) | 117 | # --verbose gives us gobs of info to stdout (e.g. linker script used) |
78 | if ! test -f busybox_ldscript; then | 118 | if ! test -f busybox_ldscript; then |
79 | try $CC $LDFLAGS \ | 119 | try $CC $LDFLAGS \ |
80 | -o $EXE -Wl,-Map -Wl,$EXE.map \ | 120 | -o $EXE \ |
81 | -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | 121 | -Wl,--sort-common \ |
122 | -Wl,--sort-section -Wl,alignment \ | ||
123 | -Wl,--gc-sections \ | ||
82 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 124 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ |
83 | $l_list -Wl,--verbose \ | 125 | $l_list \ |
126 | -Wl,--warn-common \ | ||
127 | -Wl,-Map -Wl,$EXE.map \ | ||
128 | -Wl,--verbose \ | ||
84 | || { | 129 | || { |
85 | cat $EXE.out | 130 | cat $EXE.out |
86 | exit 1 | 131 | exit 1 |
@@ -92,12 +137,18 @@ else | |||
92 | # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) | 137 | # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) |
93 | # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) | 138 | # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) |
94 | # This will eliminate most of the padding (~3kb). | 139 | # This will eliminate most of the padding (~3kb). |
140 | # Hmm, "ld --sort-section alignment" should do it too. | ||
95 | try $CC $LDFLAGS \ | 141 | try $CC $LDFLAGS \ |
96 | -o $EXE -Wl,-Map -Wl,$EXE.map \ | 142 | -o $EXE \ |
97 | -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | 143 | -Wl,--sort-common \ |
98 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | 144 | -Wl,--sort-section -Wl,alignment \ |
99 | $l_list -Wl,--verbose \ | 145 | -Wl,--gc-sections \ |
100 | -Wl,-T -Wl,busybox_ldscript \ | 146 | -Wl,-T -Wl,busybox_ldscript \ |
147 | -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \ | ||
148 | $l_list \ | ||
149 | -Wl,--warn-common \ | ||
150 | -Wl,-Map -Wl,$EXE.map \ | ||
151 | -Wl,--verbose \ | ||
101 | || { | 152 | || { |
102 | cat $EXE.out | 153 | cat $EXE.out |
103 | exit 1 | 154 | exit 1 |
@@ -118,12 +169,18 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then | |||
118 | 169 | ||
119 | EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped" | 170 | EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped" |
120 | try $CC $LDFLAGS \ | 171 | try $CC $LDFLAGS \ |
121 | -o $EXE -Wl,-Map -Wl,$EXE.map \ | 172 | -o $EXE \ |
122 | -shared -fPIC -Wl,--enable-new-dtags \ | 173 | -shared -fPIC \ |
123 | -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \ | 174 | -Wl,--enable-new-dtags \ |
124 | $l_list -Wl,--verbose \ | 175 | -Wl,-z,combreloc \ |
125 | -Wl,-soname="libbusybox.so.$BB_VER" \ | 176 | -Wl,-soname="libbusybox.so.$BB_VER" \ |
126 | -Wl,-z,combreloc \ | 177 | -Wl,--sort-common \ |
178 | -Wl,--sort-section -Wl,alignment \ | ||
179 | -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \ | ||
180 | $l_list \ | ||
181 | -Wl,--warn-common \ | ||
182 | -Wl,-Map -Wl,$EXE.map \ | ||
183 | -Wl,--verbose \ | ||
127 | || { | 184 | || { |
128 | echo "Linking $EXE failed" | 185 | echo "Linking $EXE failed" |
129 | cat $EXE.out | 186 | cat $EXE.out |
@@ -137,11 +194,15 @@ fi | |||
137 | if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then | 194 | if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then |
138 | EXE="$sharedlib_dir/busybox_unstripped" | 195 | EXE="$sharedlib_dir/busybox_unstripped" |
139 | try $CC $LDFLAGS \ | 196 | try $CC $LDFLAGS \ |
140 | -o $EXE -Wl,-Map -Wl,$EXE.map \ | 197 | -o $EXE \ |
141 | -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | 198 | -Wl,--sort-common \ |
142 | -Wl,--start-group $O_FILES -Wl,--end-group \ | 199 | -Wl,--sort-section -Wl,alignment \ |
143 | -Wl,--verbose \ | 200 | -Wl,--gc-sections \ |
144 | -L"$sharedlib_dir" -lbusybox \ | 201 | -Wl,--start-group $O_FILES -Wl,--end-group \ |
202 | -L"$sharedlib_dir" -lbusybox \ | ||
203 | -Wl,--warn-common \ | ||
204 | -Wl,-Map -Wl,$EXE.map \ | ||
205 | -Wl,--verbose \ | ||
145 | || { | 206 | || { |
146 | echo "Linking $EXE failed" | 207 | echo "Linking $EXE failed" |
147 | cat $EXE.out | 208 | cat $EXE.out |
@@ -174,9 +235,12 @@ int main(int argc, char **argv) | |||
174 | 235 | ||
175 | EXE="$sharedlib_dir/$name" | 236 | EXE="$sharedlib_dir/$name" |
176 | try $CC $LDFLAGS "$sharedlib_dir/applet.c" \ | 237 | try $CC $LDFLAGS "$sharedlib_dir/applet.c" \ |
177 | -o $EXE \ | 238 | -o $EXE \ |
178 | -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ | 239 | -Wl,--sort-common \ |
179 | -L"$sharedlib_dir" -lbusybox \ | 240 | -Wl,--sort-section -Wl,alignment \ |
241 | -Wl,--gc-sections \ | ||
242 | -L"$sharedlib_dir" -lbusybox \ | ||
243 | -Wl,--warn-common \ | ||
180 | || { | 244 | || { |
181 | echo "Linking $EXE failed" | 245 | echo "Linking $EXE failed" |
182 | cat $EXE.out | 246 | cat $EXE.out |