Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/scripts/trylink


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/scripts/trylink

    r3232 r3621  
    4747
    4848check_cc() {
    49     local tempname="/tmp/temp.$$.$RANDOM"
     49    local tempname="$(mktemp)"
     50    local r
     51    echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c
    5052    # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :(
    51     # "-xc": C language. "/dev/null" is an empty source file.
    52     if $CC $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then
    53     echo "$1";
    54     else
    55     echo "$2";
    56     fi
    57     rm "$tempname".o 2>/dev/null
     53    # Was using "-xc /dev/null", but we need a valid C program.
     54    # "eval" may be needed if CFLAGS can contain
     55    # '... -D"BB_VER=KBUILD_STR(1.N.M)" ...'
     56    # and we need shell to process quotes!
     57    $CC $CFLAGS $LDFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1
     58    r=$?
     59    rm -f "$tempname" "$tempname".c "$tempname".o
     60    return $r
    5861}
    5962
    6063check_libc_is_glibc() {
    61     local tempname="/tmp/temp.$$.$RANDOM"
     64    local tempname="$(mktemp)"
     65    local r
    6266    echo "\
    6367    #include <stdlib.h>
     
    6771    #endif
    6872    " >"$tempname".c
    69     if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then
    70     echo "$2";
    71     else
    72     echo "$1";
    73     fi
    74     rm "$tempname".c "$tempname".o 2>/dev/null
     73    ! $CC $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1
     74    r=$?
     75    rm -f "$tempname" "$tempname".c "$tempname".o
     76    return $r
    7577}
    7678
     
    8486
    8587# The --sort-section option is not supported by older versions of ld
    86 SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""`
     88SORT_SECTION="-Wl,--sort-section,alignment"
     89if ! check_cc "-Wl,--sort-section,alignment"; then
     90    echo "Your linker does not support --sort-section,alignment"
     91    SORT_SECTION=""
     92fi
    8793
    8894START_GROUP="-Wl,--start-group"
     
    9197
    9298# gold may not support --sort-common (yet)
    93 SORT_COMMON=`check_cc "-Wl,--sort-common" ""`
     99SORT_COMMON="-Wl,--sort-common"
     100if ! check_cc "-Wl,--sort-common"; then
     101    echo "Your linker does not support --sort-common"
     102    SORT_COMMON=""
     103fi
    94104
    95105# Static linking against glibc produces buggy executables
     
    98108# Note that glibc is unsuitable for static linking anyway.
    99109# We are removing -Wl,--gc-sections from link command line.
    100 GC_SECTIONS=`(
    101 . ./.config
    102 if test x"$CONFIG_STATIC" = x"y"; then
    103     check_libc_is_glibc "" "-Wl,--gc-sections"
    104 else
    105     echo "-Wl,--gc-sections"
    106 fi
    107 )`
    108 
     110GC_SECTIONS="-Wl,--gc-sections"
     111if (. ./.config && test x"$CONFIG_STATIC" = x"y") then
     112    if check_libc_is_glibc; then
     113    echo "Static linking against glibc, can't use --gc-sections"
     114    GC_SECTIONS=""
     115    fi
     116fi
    109117# The --gc-sections option is not supported by older versions of ld
    110118if test -n "$GC_SECTIONS"; then
    111     GC_SECTIONS=`check_cc "$GC_SECTIONS" ""`
     119    if ! check_cc "$GC_SECTIONS"; then
     120    echo "Your linker does not support $GC_SECTIONS"
     121    GC_SECTIONS=""
     122    fi
    112123fi
    113124
     
    118129echo "Trying libraries: $LDLIBS"
    119130# "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
    120 l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
     131l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'`
    121132test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP"
    122133try $CC $CFLAGS $LDFLAGS \
     
    130141    echo "Failed: $l_list"
    131142    cat $EXE.out
     143    echo 'Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.'
     144    echo 'Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"'
    132145    exit 1
    133146}
     
    142155    without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs`
    143156    # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3"
    144     l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
     157    l_list=`echo " $without_one " | sed -e 's: \([^- ][^ ]*\): -l\1:g'`
    145158    test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP"
    146159    $debug && echo "Trying -l options: '$l_list'"
     
    173186# Make the binary with final, minimal list of libs
    174187echo "Final link with: ${LDLIBS:-<none>}"
    175 l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'`
     188l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'`
    176189test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP"
    177190# --verbose gives us gobs of info to stdout (e.g. linker script used)
     
    197210    # This will eliminate most of the padding (~3kb).
    198211    # Hmm, "ld --sort-section alignment" should do it too.
     212    #
     213    # There is a ld hack which is meant to decrease disk usage
     214    # at the cost of more RAM usage (??!!) in standard ld script:
     215    #  /* Adjust the address for the data segment.  We want to adjust up to
     216    #     the same address within the page on the next page up.  */
     217    #  . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
     218    # Replace it with:
     219    #  . = ALIGN (0x1000); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000);
     220    # to unconditionally align .data to the next page boundary,
     221    # instead of "next page, plus current offset in this page"
    199222    try $CC $CFLAGS $LDFLAGS \
    200223        -o $EXE \
     
    269292if test "$CONFIG_FEATURE_INDIVIDUAL" = y; then
    270293    echo "Linking individual applets against libbusybox (see $sharedlib_dir/*)"
    271     gcc -DNAME_MAIN_CNAME -E -include include/autoconf.h include/applets.h \
     294    gcc -DNAME_MAIN -E -include include/autoconf.h include/applets.h \
    272295    | grep -v "^#" \
    273     | grep -v "^$" \
     296    | grep -v "^ *$" \
    274297    > applet_lst.tmp
    275298    while read name main junk; do
     
    301324    rm -- "$sharedlib_dir/applet.c" $EXE.out
    302325    $STRIP -s --remove-section=.note --remove-section=.comment $EXE
     326    # Let user see that we do something - list the names of created binaries:
     327    echo "$EXE"
    303328
    304329    done <applet_lst.tmp
Note: See TracChangeset for help on using the changeset viewer.