diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-17 20:39:27 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-07-17 20:39:27 +0000 |
| commit | 150d2fa114d626761a67e529959433226793e733 (patch) | |
| tree | aa2f46682b3bf49fb7f4d746f8f68d43f7223980 | |
| parent | c5f24268381e462a688ae29193deb6857a9db485 (diff) | |
| download | busybox-w32-150d2fa114d626761a67e529959433226793e733.tar.gz busybox-w32-150d2fa114d626761a67e529959433226793e733.tar.bz2 busybox-w32-150d2fa114d626761a67e529959433226793e733.zip | |
Modify method of linking against libs. Now we fisrt try all
specified libs, and if it succeeds, we try to remove them
one-by-one. If link succeeds, then library is thrown out.
Should solve the problem with SELinux linking in libsepol
even when not needed.
| -rw-r--r-- | Makefile.flags | 13 | ||||
| -rwxr-xr-x | scripts/trylink | 52 |
2 files changed, 54 insertions, 11 deletions
diff --git a/Makefile.flags b/Makefile.flags index b54679047..d8817bed6 100644 --- a/Makefile.flags +++ b/Makefile.flags | |||
| @@ -59,18 +59,25 @@ ifeq ($(CONFIG_STATIC),y) | |||
| 59 | LDFLAGS += -static | 59 | LDFLAGS += -static |
| 60 | endif | 60 | endif |
| 61 | 61 | ||
| 62 | BBOX_LIB_LIST = m crypt | ||
| 62 | ifeq ($(CONFIG_SELINUX),y) | 63 | ifeq ($(CONFIG_SELINUX),y) |
| 63 | LDLIBS += -lselinux -lsepol | 64 | #LDLIBS += -lselinux -lsepol |
| 65 | BBOX_LIB_LIST += selinux sepol | ||
| 64 | endif | 66 | endif |
| 65 | 67 | ||
| 66 | ifeq ($(CONFIG_EFENCE),y) | 68 | ifeq ($(CONFIG_EFENCE),y) |
| 67 | LDLIBS += -lefence | 69 | #LDLIBS += -lefence |
| 70 | BBOX_LIB_LIST += efence | ||
| 68 | endif | 71 | endif |
| 69 | 72 | ||
| 70 | ifeq ($(CONFIG_DMALLOC),y) | 73 | ifeq ($(CONFIG_DMALLOC),y) |
| 71 | LDLIBS += -ldmalloc | 74 | #LDLIBS += -ldmalloc |
| 75 | BBOX_LIB_LIST += dmalloc | ||
| 72 | endif | 76 | endif |
| 73 | 77 | ||
| 78 | # For scripts/trylink | ||
| 79 | export BBOX_LIB_LIST | ||
| 80 | |||
| 74 | #LDFLAGS += -nostdlib | 81 | #LDFLAGS += -nostdlib |
| 75 | 82 | ||
| 76 | LDFLAGS_ELF2FLT = -Wl,-elf2flt | 83 | LDFLAGS_ELF2FLT = -Wl,-elf2flt |
diff --git a/scripts/trylink b/scripts/trylink index 52931b01c..ddd7fb179 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
| @@ -6,13 +6,49 @@ try() { | |||
| 6 | added="$1" | 6 | added="$1" |
| 7 | shift | 7 | shift |
| 8 | $debug && echo "Trying: $* $added" | 8 | $debug && echo "Trying: $* $added" |
| 9 | "$@" $added >busybox.map 2>busybox_ld.err \ | 9 | "$@" $added >busybox.map 2>busybox_ld.err |
| 10 | && { rm busybox_ld.err; exit 0; } | ||
| 11 | } | 10 | } |
| 12 | 11 | ||
| 13 | try "" "$@" | 12 | # Sanitize lib list (dups, extra spaces etc) |
| 14 | try "-lm" "$@" | 13 | #echo "BBOX_LIB_LIST=$BBOX_LIB_LIST" |
| 15 | try "-lcrypt" "$@" | 14 | BBOX_LIB_LIST=`echo "$BBOX_LIB_LIST" | xargs -n1 | sort | uniq | xargs` |
| 16 | try "-Wl,--start-group -lcrypt -lm -Wl,--end-group" "$@" | 15 | |
| 17 | # It failed. Let people see the error messages | 16 | # First link with all libs. If it fails, bail out |
| 18 | cat busybox_ld.err | 17 | l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/'` |
| 18 | echo "Trying libraries: $BBOX_LIB_LIST" | ||
| 19 | try "-Wl,--start-group $l_list -Wl,--end-group" "$@" \ | ||
| 20 | || { | ||
| 21 | echo "Failed: $* -Wl,--start-group $l_list -Wl,--end-group" | ||
| 22 | cat busybox_ld.err | ||
| 23 | exit 1 | ||
| 24 | } | ||
| 25 | |||
| 26 | # Now try to remove each lib and build without. | ||
| 27 | # Stop when no lib can be removed. | ||
| 28 | while test "$BBOX_LIB_LIST"; do | ||
| 29 | $debug && echo "Trying libraries: $BBOX_LIB_LIST" | ||
| 30 | all_needed=true | ||
| 31 | for one in $BBOX_LIB_LIST; do | ||
| 32 | without_one=`echo " $BBOX_LIB_LIST " | sed "s/ $one / /g" | xargs` | ||
| 33 | l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/'` | ||
| 34 | $debug && echo "Trying -l options: $l_list" | ||
| 35 | if try "-Wl,--start-group $l_list -Wl,--end-group" "$@"; then | ||
| 36 | echo "Library $one is not needed" | ||
| 37 | BBOX_LIB_LIST="$without_one" | ||
| 38 | all_needed=false | ||
| 39 | else | ||
| 40 | echo "Library $one is needed" | ||
| 41 | fi | ||
| 42 | done | ||
| 43 | # All libs were needed, can't remove any | ||
| 44 | $all_needed && break | ||
| 45 | # If there is no space, the list has just one lib. | ||
| 46 | # I'm not sure that in this case lib really is 100% needed. | ||
| 47 | # Let's try linking without it anyway... thus commented out. | ||
| 48 | #echo "$BBOX_LIB_LIST" | grep -q ' ' || break | ||
| 49 | done | ||
| 50 | |||
| 51 | # Ok, make the binary | ||
| 52 | echo "Final link with: $BBOX_LIB_LIST" | ||
| 53 | l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/'` | ||
| 54 | try "-Wl,--start-group $l_list -Wl,--end-group" "$@" | ||
