aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-09 13:49:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-09 13:49:26 +0000
commit01f3b2c91a1b48fa730b3f0bd5da73b1210a5ac9 (patch)
treeb48778f931c79aa6705860436130a1443ecce790 /scripts
parentd19b87ece4add3dd24bea9d9d0b32946c219ef2c (diff)
downloadbusybox-01f3b2c91a1b48fa730b3f0bd5da73b1210a5ac9.tar.gz
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')
-rwxr-xr-xscripts/trylink114
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 @@
debug=false
+# Linker flags used:
+#
+# Informational:
+# --warn-common
+# -Map $EXE.map
+# --verbose
+#
+# Optimizations:
+# --sort-common reduces padding
+# --sort-section alignment reduces padding
+# --gc-sections throws out unused sections,
+# does not work for shared libs
+# -O Not used, maybe useful?
+#
+# List of files to link:
+# $l_list == --start-group -llib1 -llib2 --end-group
+# --start-group $O_FILES $A_FILES --end-group
+# or for shlib:
+# --start-group --whole-archive $A_FILES --no-whole-archive --end-group
+# otherwise we don't pull in all parts of *.a files. Now we pull in too much.
+# FIXME: make it work without --whole-archive, or better, with --gc-sections.
+#
+# Shared library link:
+# -shared self-explanatory
+# -fPIC position-independent code
+# -Wl,--enable-new-dtags ?
+# -Wl,-z,combreloc ?
+# -Wl,-soname="libbusybox.so.$BB_VER"
+# -static Not used, but may be useful! manpage:
+# "... This option can be used with -shared.
+# Doing so means that a shared library
+# is being created but that all of the library's
+# external references must be resolved by pulling
+# in entries from static libraries."
+
+
try() {
printf "%s\n" "Output of:" >$EXE.out
printf "%s\n" "$*" >>$EXE.out
@@ -28,8 +64,10 @@ echo "Trying libraries: $LDLIBS"
l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
try $CC $LDFLAGS \
- -o $EXE -Wl,-Map -Wl,$EXE.map \
- -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
+ -o $EXE \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--gc-sections \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
$l_list \
|| {
@@ -50,8 +88,10 @@ while test "$LDLIBS"; do
test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
$debug && echo "Trying -l options: '$l_list'"
try $CC $LDFLAGS \
- -o $EXE -Wl,-Map -Wl,$EXE.map \
- -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
+ -o $EXE \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--gc-sections \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
$l_list
if test $? = 0; then
@@ -77,10 +117,15 @@ test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
# --verbose gives us gobs of info to stdout (e.g. linker script used)
if ! test -f busybox_ldscript; then
try $CC $LDFLAGS \
- -o $EXE -Wl,-Map -Wl,$EXE.map \
- -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
+ -o $EXE \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--gc-sections \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
- $l_list -Wl,--verbose \
+ $l_list \
+ -Wl,--warn-common \
+ -Wl,-Map -Wl,$EXE.map \
+ -Wl,--verbose \
|| {
cat $EXE.out
exit 1
@@ -92,12 +137,18 @@ else
# *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*)
# *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*)
# This will eliminate most of the padding (~3kb).
+ # Hmm, "ld --sort-section alignment" should do it too.
try $CC $LDFLAGS \
- -o $EXE -Wl,-Map -Wl,$EXE.map \
- -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
- -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
- $l_list -Wl,--verbose \
+ -o $EXE \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--gc-sections \
-Wl,-T -Wl,busybox_ldscript \
+ -Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
+ $l_list \
+ -Wl,--warn-common \
+ -Wl,-Map -Wl,$EXE.map \
+ -Wl,--verbose \
|| {
cat $EXE.out
exit 1
@@ -118,12 +169,18 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then
EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped"
try $CC $LDFLAGS \
- -o $EXE -Wl,-Map -Wl,$EXE.map \
- -shared -fPIC -Wl,--enable-new-dtags \
- -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \
- $l_list -Wl,--verbose \
- -Wl,-soname="libbusybox.so.$BB_VER" \
- -Wl,-z,combreloc \
+ -o $EXE \
+ -shared -fPIC \
+ -Wl,--enable-new-dtags \
+ -Wl,-z,combreloc \
+ -Wl,-soname="libbusybox.so.$BB_VER" \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \
+ $l_list \
+ -Wl,--warn-common \
+ -Wl,-Map -Wl,$EXE.map \
+ -Wl,--verbose \
|| {
echo "Linking $EXE failed"
cat $EXE.out
@@ -137,11 +194,15 @@ fi
if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then
EXE="$sharedlib_dir/busybox_unstripped"
try $CC $LDFLAGS \
- -o $EXE -Wl,-Map -Wl,$EXE.map \
- -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
- -Wl,--start-group $O_FILES -Wl,--end-group \
- -Wl,--verbose \
- -L"$sharedlib_dir" -lbusybox \
+ -o $EXE \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--gc-sections \
+ -Wl,--start-group $O_FILES -Wl,--end-group \
+ -L"$sharedlib_dir" -lbusybox \
+ -Wl,--warn-common \
+ -Wl,-Map -Wl,$EXE.map \
+ -Wl,--verbose \
|| {
echo "Linking $EXE failed"
cat $EXE.out
@@ -174,9 +235,12 @@ int main(int argc, char **argv)
EXE="$sharedlib_dir/$name"
try $CC $LDFLAGS "$sharedlib_dir/applet.c" \
- -o $EXE \
- -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
- -L"$sharedlib_dir" -lbusybox \
+ -o $EXE \
+ -Wl,--sort-common \
+ -Wl,--sort-section -Wl,alignment \
+ -Wl,--gc-sections \
+ -L"$sharedlib_dir" -lbusybox \
+ -Wl,--warn-common \
|| {
echo "Linking $EXE failed"
cat $EXE.out