mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
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
This commit is contained in:
parent
d19b87ece4
commit
01f3b2c91a
104
scripts/trylink
104
scripts/trylink
@ -2,6 +2,42 @@
|
|||||||
|
|
||||||
debug=false
|
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() {
|
try() {
|
||||||
printf "%s\n" "Output of:" >$EXE.out
|
printf "%s\n" "Output of:" >$EXE.out
|
||||||
printf "%s\n" "$*" >>$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$//'`
|
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"
|
test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
|
||||||
try $CC $LDFLAGS \
|
try $CC $LDFLAGS \
|
||||||
-o $EXE -Wl,-Map -Wl,$EXE.map \
|
-o $EXE \
|
||||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
-Wl,--sort-common \
|
||||||
|
-Wl,--sort-section -Wl,alignment \
|
||||||
|
-Wl,--gc-sections \
|
||||||
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
|
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
|
||||||
$l_list \
|
$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"
|
test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
|
||||||
$debug && echo "Trying -l options: '$l_list'"
|
$debug && echo "Trying -l options: '$l_list'"
|
||||||
try $CC $LDFLAGS \
|
try $CC $LDFLAGS \
|
||||||
-o $EXE -Wl,-Map -Wl,$EXE.map \
|
-o $EXE \
|
||||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
-Wl,--sort-common \
|
||||||
|
-Wl,--sort-section -Wl,alignment \
|
||||||
|
-Wl,--gc-sections \
|
||||||
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
|
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
|
||||||
$l_list
|
$l_list
|
||||||
if test $? = 0; then
|
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)
|
# --verbose gives us gobs of info to stdout (e.g. linker script used)
|
||||||
if ! test -f busybox_ldscript; then
|
if ! test -f busybox_ldscript; then
|
||||||
try $CC $LDFLAGS \
|
try $CC $LDFLAGS \
|
||||||
-o $EXE -Wl,-Map -Wl,$EXE.map \
|
-o $EXE \
|
||||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
-Wl,--sort-common \
|
||||||
|
-Wl,--sort-section -Wl,alignment \
|
||||||
|
-Wl,--gc-sections \
|
||||||
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
|
-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
|
cat $EXE.out
|
||||||
exit 1
|
exit 1
|
||||||
@ -92,12 +137,18 @@ else
|
|||||||
# *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*)
|
# *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*)
|
||||||
# *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*)
|
# *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*)
|
||||||
# This will eliminate most of the padding (~3kb).
|
# This will eliminate most of the padding (~3kb).
|
||||||
|
# Hmm, "ld --sort-section alignment" should do it too.
|
||||||
try $CC $LDFLAGS \
|
try $CC $LDFLAGS \
|
||||||
-o $EXE -Wl,-Map -Wl,$EXE.map \
|
-o $EXE \
|
||||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
-Wl,--sort-common \
|
||||||
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
|
-Wl,--sort-section -Wl,alignment \
|
||||||
$l_list -Wl,--verbose \
|
-Wl,--gc-sections \
|
||||||
-Wl,-T -Wl,busybox_ldscript \
|
-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
|
cat $EXE.out
|
||||||
exit 1
|
exit 1
|
||||||
@ -118,12 +169,18 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then
|
|||||||
|
|
||||||
EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped"
|
EXE="$sharedlib_dir/libbusybox.so.${BB_VER}_unstripped"
|
||||||
try $CC $LDFLAGS \
|
try $CC $LDFLAGS \
|
||||||
-o $EXE -Wl,-Map -Wl,$EXE.map \
|
-o $EXE \
|
||||||
-shared -fPIC -Wl,--enable-new-dtags \
|
-shared -fPIC \
|
||||||
-Wl,--start-group -Wl,--whole-archive $A_FILES -Wl,--no-whole-archive -Wl,--end-group \
|
-Wl,--enable-new-dtags \
|
||||||
$l_list -Wl,--verbose \
|
|
||||||
-Wl,-soname="libbusybox.so.$BB_VER" \
|
|
||||||
-Wl,-z,combreloc \
|
-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"
|
echo "Linking $EXE failed"
|
||||||
cat $EXE.out
|
cat $EXE.out
|
||||||
@ -137,11 +194,15 @@ fi
|
|||||||
if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then
|
if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then
|
||||||
EXE="$sharedlib_dir/busybox_unstripped"
|
EXE="$sharedlib_dir/busybox_unstripped"
|
||||||
try $CC $LDFLAGS \
|
try $CC $LDFLAGS \
|
||||||
-o $EXE -Wl,-Map -Wl,$EXE.map \
|
-o $EXE \
|
||||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
-Wl,--sort-common \
|
||||||
|
-Wl,--sort-section -Wl,alignment \
|
||||||
|
-Wl,--gc-sections \
|
||||||
-Wl,--start-group $O_FILES -Wl,--end-group \
|
-Wl,--start-group $O_FILES -Wl,--end-group \
|
||||||
-Wl,--verbose \
|
|
||||||
-L"$sharedlib_dir" -lbusybox \
|
-L"$sharedlib_dir" -lbusybox \
|
||||||
|
-Wl,--warn-common \
|
||||||
|
-Wl,-Map -Wl,$EXE.map \
|
||||||
|
-Wl,--verbose \
|
||||||
|| {
|
|| {
|
||||||
echo "Linking $EXE failed"
|
echo "Linking $EXE failed"
|
||||||
cat $EXE.out
|
cat $EXE.out
|
||||||
@ -175,8 +236,11 @@ int main(int argc, char **argv)
|
|||||||
EXE="$sharedlib_dir/$name"
|
EXE="$sharedlib_dir/$name"
|
||||||
try $CC $LDFLAGS "$sharedlib_dir/applet.c" \
|
try $CC $LDFLAGS "$sharedlib_dir/applet.c" \
|
||||||
-o $EXE \
|
-o $EXE \
|
||||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
-Wl,--sort-common \
|
||||||
|
-Wl,--sort-section -Wl,alignment \
|
||||||
|
-Wl,--gc-sections \
|
||||||
-L"$sharedlib_dir" -lbusybox \
|
-L"$sharedlib_dir" -lbusybox \
|
||||||
|
-Wl,--warn-common \
|
||||||
|| {
|
|| {
|
||||||
echo "Linking $EXE failed"
|
echo "Linking $EXE failed"
|
||||||
cat $EXE.out
|
cat $EXE.out
|
||||||
|
Loading…
Reference in New Issue
Block a user