diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-04-21 23:52:35 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-04-21 23:52:35 +0200 |
| commit | d7b502c05911e1cf1d4fc31be71f3abccd0927a5 (patch) | |
| tree | 29cf9754793c0bc4e9340af7b1f49a037621d7a3 /scripts | |
| parent | 93e1aaa1c7e5ed6d2704262700ec28837bdfc9b7 (diff) | |
| download | busybox-w32-d7b502c05911e1cf1d4fc31be71f3abccd0927a5.tar.gz busybox-w32-d7b502c05911e1cf1d4fc31be71f3abccd0927a5.tar.bz2 busybox-w32-d7b502c05911e1cf1d4fc31be71f3abccd0927a5.zip | |
build system: fix generate_BUFSIZ.sh to not alternate 1k and malloc builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/generate_BUFSIZ.sh | 180 |
1 files changed, 108 insertions, 72 deletions
diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh index 1914fa0f5..8aa0174a6 100755 --- a/scripts/generate_BUFSIZ.sh +++ b/scripts/generate_BUFSIZ.sh | |||
| @@ -7,11 +7,16 @@ | |||
| 7 | 7 | ||
| 8 | debug=false | 8 | debug=false |
| 9 | 9 | ||
| 10 | postcompile=false | ||
| 11 | test x"$1" = x"--post" && { postcompile=true; shift; } | ||
| 12 | |||
| 10 | common_bufsiz_h=$1 | 13 | common_bufsiz_h=$1 |
| 11 | 14 | ||
| 12 | test x"$NM" = x"" && NM="${CONFIG_CROSS_COMPILER_PREFIX}nm" | 15 | test x"$NM" = x"" && NM="${CONFIG_CROSS_COMPILER_PREFIX}nm" |
| 13 | test x"$CC" = x"" && CC="${CONFIG_CROSS_COMPILER_PREFIX}gcc" | 16 | test x"$CC" = x"" && CC="${CONFIG_CROSS_COMPILER_PREFIX}gcc" |
| 14 | 17 | ||
| 18 | exitcmd="exit 0" | ||
| 19 | |||
| 15 | regenerate() { | 20 | regenerate() { |
| 16 | cat >"$1.$$" | 21 | cat >"$1.$$" |
| 17 | test -f "$1" && diff "$1.$$" "$1" >/dev/null && rm "$1.$$" && return | 22 | test -f "$1" && diff "$1.$$" "$1" >/dev/null && rm "$1.$$" && return |
| @@ -19,99 +24,130 @@ regenerate() { | |||
| 19 | } | 24 | } |
| 20 | 25 | ||
| 21 | generate_std_and_exit() { | 26 | generate_std_and_exit() { |
| 22 | $debug && echo "Default: bb_common_bufsiz1[] in bss" | 27 | $debug && echo "Configuring: bb_common_bufsiz1[] in bss" |
| 23 | { | 28 | { |
| 24 | echo "enum { COMMON_BUFSIZE = 1024 };" | 29 | echo "enum { COMMON_BUFSIZE = 1024 };" |
| 25 | echo "extern char bb_common_bufsiz1[];" | 30 | echo "extern char bb_common_bufsiz1[];" |
| 26 | echo "#define setup_common_bufsiz() ((void)0)" | 31 | echo "#define setup_common_bufsiz() ((void)0)" |
| 27 | } | regenerate "$common_bufsiz_h" | 32 | } | regenerate "$common_bufsiz_h" |
| 28 | exit 0 | 33 | echo "std" >"$common_bufsiz_h.method" |
| 34 | $exitcmd | ||
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | # User does not want any funky stuff? | 37 | generate_big_and_exit() { |
| 32 | test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit | 38 | $debug && echo "Configuring: bb_common_bufsiz1[] in _end[], COMMON_BUFSIZE = $1" |
| 33 | |||
| 34 | test -f busybox_unstripped || { | ||
| 35 | # We did not try anything yet | ||
| 36 | $debug && echo "Will try to fit bb_common_bufsiz1[] into _end[]" | ||
| 37 | { | 39 | { |
| 38 | echo "enum { COMMON_BUFSIZE = 1024 };" | 40 | echo "enum { COMMON_BUFSIZE = $1 };" |
| 39 | echo "extern char _end[]; /* linker-provided label */" | 41 | echo "extern char _end[]; /* linker-provided label */" |
| 40 | echo "#define bb_common_bufsiz1 _end" | 42 | echo "#define bb_common_bufsiz1 _end" |
| 41 | echo "#define setup_common_bufsiz() ((void)0)" | 43 | echo "#define setup_common_bufsiz() ((void)0)" |
| 42 | } | regenerate "$common_bufsiz_h" | 44 | } | regenerate "$common_bufsiz_h" |
| 43 | echo 1024 >"$common_bufsiz_h.BUFSIZE" | 45 | echo "$2" >"$common_bufsiz_h.method" |
| 44 | exit 0 | 46 | $exitcmd |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 47 | # Get _end address | 49 | generate_1k_and_exit() { |
| 48 | END=`$NM busybox_unstripped | grep ' . _end$'| cut -d' ' -f1` | 50 | generate_big_and_exit 1024 "1k" |
| 49 | test x"$END" = x"" && generate_std_and_exit | 51 | } |
| 50 | $debug && echo "END:0x$END $((0x$END))" | 52 | |
| 51 | END=$((0x$END)) | 53 | |
| 52 | 54 | generate_malloc_and_exit() { | |
| 53 | # Get PAGE_SIZE | 55 | $debug && echo "Configuring: bb_common_bufsiz1[] is malloced" |
| 54 | echo "\ | ||
| 55 | #include <sys/user.h> | ||
| 56 | #if defined(PAGE_SIZE) && PAGE_SIZE > 0 | ||
| 57 | char page_size[PAGE_SIZE]; | ||
| 58 | #else | ||
| 59 | char page_size[1]; | ||
| 60 | #endif | ||
| 61 | " >page_size_$$.c | ||
| 62 | $CC -c "page_size_$$.c" || generate_std_and_exit | ||
| 63 | PAGE_SIZE=`$NM --size-sort "page_size_$$.o" | cut -d' ' -f1` | ||
| 64 | rm "page_size_$$.c" "page_size_$$.o" | ||
| 65 | test x"$PAGE_SIZE" = x"" && generate_std_and_exit | ||
| 66 | $debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))" | ||
| 67 | PAGE_SIZE=$((0x$PAGE_SIZE)) | ||
| 68 | test $PAGE_SIZE -lt 1024 && generate_std_and_exit | ||
| 69 | |||
| 70 | # How much space between _end[] and next page? | ||
| 71 | PAGE_MASK=$((PAGE_SIZE-1)) | ||
| 72 | REM=$(( (-END) & PAGE_MASK )) | ||
| 73 | $debug && echo "REM:$REM" | ||
| 74 | |||
| 75 | if test $REM -lt 1024; then | ||
| 76 | # _end[] has no enough space for bb_common_bufsiz1[], | ||
| 77 | # users will need to malloc it. | ||
| 78 | { | 56 | { |
| 79 | echo "enum { COMMON_BUFSIZE = 1024 };" | 57 | echo "enum { COMMON_BUFSIZE = 1024 };" |
| 80 | echo "extern char *const bb_common_bufsiz1;" | 58 | echo "extern char *const bb_common_bufsiz1;" |
| 81 | echo "void setup_common_bufsiz(void);" | 59 | echo "void setup_common_bufsiz(void);" |
| 82 | } | regenerate "$common_bufsiz_h" | 60 | } | regenerate "$common_bufsiz_h" |
| 83 | # Check that we aren't left with a buggy binary: | 61 | echo "malloc" >"$common_bufsiz_h.method" |
| 84 | if test -f "$common_bufsiz_h.BUFSIZE"; then | 62 | $exitcmd |
| 85 | rm "$common_bufsiz_h.BUFSIZE" | 63 | } |
| 86 | echo "Warning! Space in _end[] is too small ($REM bytes)!" | 64 | |
| 87 | echo "Rerun make to build a binary which doesn't use it!" | 65 | # User does not want any funky stuff? |
| 88 | exit 1 | 66 | test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit |
| 67 | |||
| 68 | # The script is run two times: before compilation, when it needs to | ||
| 69 | # (re)generate $common_bufsiz_h, and directly after successful build, | ||
| 70 | # when it needs to assess whether the build is ok to use at all (not buggy), | ||
| 71 | # and (re)generate $common_bufsiz_h for a future build. | ||
| 72 | |||
| 73 | if $postcompile; then | ||
| 74 | # Postcompile needs to create/delete OK/FAIL files | ||
| 75 | |||
| 76 | test -f busybox_unstripped || exit 1 | ||
| 77 | test -f "$common_bufsiz_h.method" || exit 1 | ||
| 78 | |||
| 79 | # How the build was done? | ||
| 80 | method=`cat -- "$common_bufsiz_h.method"` | ||
| 81 | |||
| 82 | # Get _end address | ||
| 83 | END=`$NM busybox_unstripped | grep ' . _end$'| cut -d' ' -f1` | ||
| 84 | test x"$END" = x"" && generate_std_and_exit | ||
| 85 | $debug && echo "END:0x$END $((0x$END))" | ||
| 86 | END=$((0x$END)) | ||
| 87 | |||
| 88 | # Get PAGE_SIZE | ||
| 89 | { | ||
| 90 | echo "#include <sys/user.h>" | ||
| 91 | echo "#if defined(PAGE_SIZE) && PAGE_SIZE > 0" | ||
| 92 | echo "char page_size[PAGE_SIZE];" | ||
| 93 | echo "#endif" | ||
| 94 | } >page_size_$$.c | ||
| 95 | $CC -c "page_size_$$.c" || exit 1 | ||
| 96 | PAGE_SIZE=`$NM --size-sort "page_size_$$.o" | cut -d' ' -f1` | ||
| 97 | rm "page_size_$$.c" "page_size_$$.o" | ||
| 98 | test x"$PAGE_SIZE" = x"" && exit 1 | ||
| 99 | $debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))" | ||
| 100 | PAGE_SIZE=$((0x$PAGE_SIZE)) | ||
| 101 | test $PAGE_SIZE -lt 512 && exit 1 | ||
| 102 | |||
| 103 | # How much space between _end[] and next page? | ||
| 104 | PAGE_MASK=$((PAGE_SIZE-1)) | ||
| 105 | COMMON_BUFSIZE=$(( (-END) & PAGE_MASK )) | ||
| 106 | echo "COMMON_BUFSIZE = $COMMON_BUFSIZE bytes" | ||
| 107 | |||
| 108 | if test x"$method" = x"1k"; then | ||
| 109 | if test $COMMON_BUFSIZE -lt 1024; then | ||
| 110 | # _end[] has no enough space for bb_common_bufsiz1[] | ||
| 111 | rm -- "$common_bufsiz_h.1k.OK" 2>/dev/null | ||
| 112 | { md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config; } >"$common_bufsiz_h.1k.FAIL" | ||
| 113 | echo "Warning! Space in _end[] is too small ($COMMON_BUFSIZE bytes)!" | ||
| 114 | echo "Rerun make to build a binary which doesn't use it!" | ||
| 115 | rm busybox_unstripped | ||
| 116 | exitcmd="exit 1" | ||
| 117 | else | ||
| 118 | rm -- "$common_bufsiz_h.1k.FAIL" 2>/dev/null | ||
| 119 | echo $COMMON_BUFSIZE >"$common_bufsiz_h.1k.OK" | ||
| 120 | test $COMMON_BUFSIZE -gt $((1024+32)) && echo "Rerun make to use larger COMMON_BUFSIZE" | ||
| 121 | fi | ||
| 89 | fi | 122 | fi |
| 90 | echo "COMMON_BUFSIZE = 1024 bytes, the buffer will be malloced" | ||
| 91 | exit 0 | ||
| 92 | fi | 123 | fi |
| 93 | 124 | ||
| 94 | # _end[] has REM bytes for bb_common_bufsiz1[] | 125 | # Based on past success/fail of 1k build, decide next build type |
| 95 | OLD=1024 | ||
| 96 | test -f "$common_bufsiz_h.BUFSIZE" && OLD=`cat "$common_bufsiz_h.BUFSIZE"` | ||
| 97 | $debug && echo "OLD:$OLD" | ||
| 98 | { | ||
| 99 | echo "enum { COMMON_BUFSIZE = $REM };" | ||
| 100 | echo "extern char _end[]; /* linker-provided label */" | ||
| 101 | echo "#define bb_common_bufsiz1 _end" | ||
| 102 | echo "#define setup_common_bufsiz() ((void)0)" | ||
| 103 | } | regenerate "$common_bufsiz_h" | ||
| 104 | echo $REM >"$common_bufsiz_h.BUFSIZE" | ||
| 105 | |||
| 106 | # Check that code did not grow too much and thus _end[] did not shrink: | ||
| 107 | if test $OLD -gt $REM; then | ||
| 108 | echo "Warning! Space in _end[] has decreased from $OLD to $REM bytes!" | ||
| 109 | echo "Rerun make!" | ||
| 110 | exit 1 | ||
| 111 | fi | ||
| 112 | 126 | ||
| 113 | if test $OLD != $REM; then | 127 | if test -f "$common_bufsiz_h.1k.OK"; then |
| 114 | echo "Space in _end[] is $REM bytes. Rerun make to use larger COMMON_BUFSIZE." | 128 | # Previous build succeeded fitting 1k into _end[]. |
| 115 | else | 129 | # Try bigger COMMON_BUFSIZE if possible. |
| 116 | echo "COMMON_BUFSIZE = $REM bytes" | 130 | COMMON_BUFSIZE=`cat -- "$common_bufsiz_h.1k.OK"` |
| 131 | # Round down a bit | ||
| 132 | COMMON_BUFSIZE=$(( (COMMON_BUFSIZE-32) & 0xfffffe0 )) | ||
| 133 | COMMON_BUFSIZE=$(( COMMON_BUFSIZE < 1024 ? 1024 : COMMON_BUFSIZE )) | ||
| 134 | test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit | ||
| 135 | generate_big_and_exit $COMMON_BUFSIZE "big" | ||
| 136 | fi | ||
| 137 | if test -f "$common_bufsiz_h.1k.FAIL"; then | ||
| 138 | # Previous build FAILED to fit 1k into _end[]. | ||
| 139 | # Was it with same .config? | ||
| 140 | oldcfg=`cat -- "$common_bufsiz_h.1k.FAIL"` | ||
| 141 | curcfg=`md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config` | ||
| 142 | # If yes, then build a "malloced" version | ||
| 143 | if test x"$oldcfg" = x"$curcfg"; then | ||
| 144 | echo "Will not try 1k build, it failed before. Touch .config to override" | ||
| 145 | generate_malloc_and_exit | ||
| 146 | fi | ||
| 147 | # else: try 1k version | ||
| 148 | echo "New .config, will try 1k build" | ||
| 149 | rm -- "$common_bufsiz_h.1k.FAIL" | ||
| 150 | generate_1k_and_exit | ||
| 117 | fi | 151 | fi |
| 152 | # There was no 1k build yet. Try it. | ||
| 153 | generate_1k_and_exit | ||
