aboutsummaryrefslogtreecommitdiff
path: root/scripts/generate_BUFSIZ.sh
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-04-24 14:13:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-04-24 14:13:35 +0200
commit4c8fa34417fd2ccdda6a8ea508a3f1e7fb1d4ceb (patch)
treefde376fac7e18704042554013f9884f5d8c56253 /scripts/generate_BUFSIZ.sh
parent3e134ebf6afb5552b3619f98f6a2ffa01a07eebb (diff)
downloadbusybox-w32-4c8fa34417fd2ccdda6a8ea508a3f1e7fb1d4ceb.tar.gz
busybox-w32-4c8fa34417fd2ccdda6a8ea508a3f1e7fb1d4ceb.tar.bz2
busybox-w32-4c8fa34417fd2ccdda6a8ea508a3f1e7fb1d4ceb.zip
generate_BUFSIZ.sh: yet another tweak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'scripts/generate_BUFSIZ.sh')
-rwxr-xr-xscripts/generate_BUFSIZ.sh54
1 files changed, 41 insertions, 13 deletions
diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh
index 750fedbef..844261906 100755
--- a/scripts/generate_BUFSIZ.sh
+++ b/scripts/generate_BUFSIZ.sh
@@ -6,6 +6,7 @@
6. ./.config || exit 1 6. ./.config || exit 1
7 7
8debug=false 8debug=false
9#debug=true
9 10
10postcompile=false 11postcompile=false
11test x"$1" = x"--post" && { postcompile=true; shift; } 12test x"$1" = x"--post" && { postcompile=true; shift; }
@@ -62,6 +63,11 @@ generate_malloc_and_exit() {
62 $exitcmd 63 $exitcmd
63} 64}
64 65
66round_down_COMMON_BUFSIZE() {
67 COMMON_BUFSIZE=$(( ($1-32) & 0xfffffe0 ))
68 COMMON_BUFSIZE=$(( COMMON_BUFSIZE < 1024 ? 1024 : COMMON_BUFSIZE ))
69}
70
65# User does not want any funky stuff? 71# User does not want any funky stuff?
66test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit 72test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit
67 73
@@ -102,22 +108,43 @@ if $postcompile; then
102 108
103 # How much space between _end[] and next page? 109 # How much space between _end[] and next page?
104 PAGE_MASK=$((PAGE_SIZE-1)) 110 PAGE_MASK=$((PAGE_SIZE-1))
105 COMMON_BUFSIZE=$(( (-END) & PAGE_MASK )) 111 TAIL_SIZE=$(( (-END) & PAGE_MASK ))
106 echo "COMMON_BUFSIZE = $COMMON_BUFSIZE bytes" 112 $debug && echo "TAIL_SIZE:$TAIL_SIZE bytes"
107 113
108 if test x"$method" != x"malloc"; then 114 if test x"$method" = x"1k" || test x"$method" = x"big"; then
109 if test $COMMON_BUFSIZE -lt 1024; then 115 if test $TAIL_SIZE -lt 1024; then
110 # _end[] has no enough space for bb_common_bufsiz1[] 116 # _end[] has no enough space for bb_common_bufsiz1[]
117 echo "Warning! Space in _end[] is too small ($TAIL_SIZE bytes)!"
118 echo "Rerun make to build a binary which doesn't use it!"
111 rm -- "$common_bufsiz_h.1k.OK" 2>/dev/null 119 rm -- "$common_bufsiz_h.1k.OK" 2>/dev/null
112 { md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config; } >"$common_bufsiz_h.1k.FAIL" 120 { 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)!" 121 rm busybox_unstripped busybox 2>/dev/null
114 echo "Rerun make to build a binary which doesn't use it!" 122# Note: here we can do either a "malloc" or "std" build.
115 rm busybox_unstripped busybox 123# "malloc" gives a bit bigger code:
124# text bss filename
125# 804355 5385 busybox.std
126# 804618 4361 busybox.malloc
127# but may have a smaller .bss (not guaranteed!). Use "pmap -x" to verify.
116 exitcmd="exit 1" 128 exitcmd="exit 1"
129 generate_malloc_and_exit
117 else 130 else
131 PREV_SIZE=1024
132 test x"$method" = x"big" && PREV_SIZE=`cat -- "$common_bufsiz_h.1k.OK"`
133 round_down_COMMON_BUFSIZE $PREV_SIZE
134 PREV_BUFSIZE=$COMMON_BUFSIZE
135
118 rm -- "$common_bufsiz_h.1k.FAIL" 2>/dev/null 136 rm -- "$common_bufsiz_h.1k.FAIL" 2>/dev/null
119 echo $COMMON_BUFSIZE >"$common_bufsiz_h.1k.OK" 137 echo $TAIL_SIZE >"$common_bufsiz_h.1k.OK"
120 test $COMMON_BUFSIZE -gt $((1024+32)) && echo "Rerun make to use larger COMMON_BUFSIZE" 138 round_down_COMMON_BUFSIZE $TAIL_SIZE
139 # emit message only if COMMON_BUFSIZE is indeed larger
140 test $COMMON_BUFSIZE -gt $PREV_BUFSIZE \
141 && echo "Rerun make to use larger COMMON_BUFSIZE ($COMMON_BUFSIZE)"
142#TODO: test $PREV_BUFSIZE -lt $TAIL_SIZE && PANIC!!!
143#Code size with COMMON_BUFSIZE > 1024 may be bigger than code with COMMON_BUFSIZE = 1024!
144#(currently we just hope "-32 and round down to 32" saves us)
145
146 test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit
147 generate_big_and_exit $COMMON_BUFSIZE "big"
121 fi 148 fi
122 fi 149 fi
123fi 150fi
@@ -127,13 +154,12 @@ fi
127if test -f "$common_bufsiz_h.1k.OK"; then 154if test -f "$common_bufsiz_h.1k.OK"; then
128 # Previous build succeeded fitting 1k into _end[]. 155 # Previous build succeeded fitting 1k into _end[].
129 # Try bigger COMMON_BUFSIZE if possible. 156 # Try bigger COMMON_BUFSIZE if possible.
130 COMMON_BUFSIZE=`cat -- "$common_bufsiz_h.1k.OK"` 157 TAIL_SIZE=`cat -- "$common_bufsiz_h.1k.OK"`
131 # Round down a bit 158 round_down_COMMON_BUFSIZE $TAIL_SIZE
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 159 test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit
135 generate_big_and_exit $COMMON_BUFSIZE "big" 160 generate_big_and_exit $COMMON_BUFSIZE "big"
136fi 161fi
162
137if test -f "$common_bufsiz_h.1k.FAIL"; then 163if test -f "$common_bufsiz_h.1k.FAIL"; then
138 # Previous build FAILED to fit 1k into _end[]. 164 # Previous build FAILED to fit 1k into _end[].
139 # Was it with same .config? 165 # Was it with same .config?
@@ -142,6 +168,7 @@ if test -f "$common_bufsiz_h.1k.FAIL"; then
142 # If yes, then build a "malloced" version 168 # If yes, then build a "malloced" version
143 if test x"$oldcfg" = x"$curcfg"; then 169 if test x"$oldcfg" = x"$curcfg"; then
144 echo "Will not try 1k build, it failed before. Touch .config to override" 170 echo "Will not try 1k build, it failed before. Touch .config to override"
171# Note: here we can do either a "malloc" or "std" build.
145 generate_malloc_and_exit 172 generate_malloc_and_exit
146 fi 173 fi
147 # else: try 1k version 174 # else: try 1k version
@@ -149,5 +176,6 @@ if test -f "$common_bufsiz_h.1k.FAIL"; then
149 rm -- "$common_bufsiz_h.1k.FAIL" 176 rm -- "$common_bufsiz_h.1k.FAIL"
150 generate_1k_and_exit 177 generate_1k_and_exit
151fi 178fi
179
152# There was no 1k build yet. Try it. 180# There was no 1k build yet. Try it.
153generate_1k_and_exit 181generate_1k_and_exit