diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-06-29 15:00:52 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-06-29 15:00:52 +0200 |
commit | 5b8c89d1f270909d1a0201478236de6ed89c8ca4 (patch) | |
tree | 3b6ff69877c1d7cb8d6b322fce147fa3ed5c0a3a /scripts/generate_BUFSIZ.sh | |
parent | 8f4faa1e3db91fc7b50d633e6f9b2f04bf978bb2 (diff) | |
download | busybox-w32-5b8c89d1f270909d1a0201478236de6ed89c8ca4.tar.gz busybox-w32-5b8c89d1f270909d1a0201478236de6ed89c8ca4.tar.bz2 busybox-w32-5b8c89d1f270909d1a0201478236de6ed89c8ca4.zip |
build system: make CONFIG_FEATURE_USE_BSS_TAIL less funky
CONFIG_FEATURE_USE_BSS_TAIL code was aliasing bb_common_bufsiz1 to _end.
This is unreliable: _end may be not sufficiently aligned.
Change code to simply enlarge COMMON_BUFSIZE when we detect that _end
has significant amount of space to the end of page.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'scripts/generate_BUFSIZ.sh')
-rwxr-xr-x | scripts/generate_BUFSIZ.sh | 100 |
1 files changed, 28 insertions, 72 deletions
diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh index 844261906..718788e0b 100755 --- a/scripts/generate_BUFSIZ.sh +++ b/scripts/generate_BUFSIZ.sh | |||
@@ -36,11 +36,10 @@ generate_std_and_exit() { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | generate_big_and_exit() { | 38 | generate_big_and_exit() { |
39 | $debug && echo "Configuring: bb_common_bufsiz1[] in _end[], COMMON_BUFSIZE = $1" | 39 | $debug && echo "Configuring: bb_common_bufsiz1[] in bss, COMMON_BUFSIZE = $1" |
40 | { | 40 | { |
41 | echo "enum { COMMON_BUFSIZE = $1 };" | 41 | echo "enum { COMMON_BUFSIZE = $1 };" |
42 | echo "extern char _end[]; /* linker-provided label */" | 42 | echo "extern char bb_common_bufsiz1[];" |
43 | echo "#define bb_common_bufsiz1 _end" | ||
44 | echo "#define setup_common_bufsiz() ((void)0)" | 43 | echo "#define setup_common_bufsiz() ((void)0)" |
45 | } | regenerate "$common_bufsiz_h" | 44 | } | regenerate "$common_bufsiz_h" |
46 | echo "$2" >"$common_bufsiz_h.method" | 45 | echo "$2" >"$common_bufsiz_h.method" |
@@ -51,20 +50,10 @@ generate_1k_and_exit() { | |||
51 | generate_big_and_exit 1024 "1k" | 50 | generate_big_and_exit 1024 "1k" |
52 | } | 51 | } |
53 | 52 | ||
54 | |||
55 | generate_malloc_and_exit() { | ||
56 | $debug && echo "Configuring: bb_common_bufsiz1[] is malloced" | ||
57 | { | ||
58 | echo "enum { COMMON_BUFSIZE = 1024 };" | ||
59 | echo "extern char *const bb_common_bufsiz1;" | ||
60 | echo "void setup_common_bufsiz(void);" | ||
61 | } | regenerate "$common_bufsiz_h" | ||
62 | echo "malloc" >"$common_bufsiz_h.method" | ||
63 | $exitcmd | ||
64 | } | ||
65 | |||
66 | round_down_COMMON_BUFSIZE() { | 53 | round_down_COMMON_BUFSIZE() { |
67 | COMMON_BUFSIZE=$(( ($1-32) & 0xfffffe0 )) | 54 | COMMON_BUFSIZE=1024 |
55 | test "$1" -le 32 && return | ||
56 | COMMON_BUFSIZE=$(( ($1-32) & 0x0ffffff0 )) | ||
68 | COMMON_BUFSIZE=$(( COMMON_BUFSIZE < 1024 ? 1024 : COMMON_BUFSIZE )) | 57 | COMMON_BUFSIZE=$(( COMMON_BUFSIZE < 1024 ? 1024 : COMMON_BUFSIZE )) |
69 | } | 58 | } |
70 | 59 | ||
@@ -104,77 +93,44 @@ if $postcompile; then | |||
104 | test x"$PAGE_SIZE" = x"" && exit 1 | 93 | test x"$PAGE_SIZE" = x"" && exit 1 |
105 | $debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))" | 94 | $debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))" |
106 | PAGE_SIZE=$((0x$PAGE_SIZE)) | 95 | PAGE_SIZE=$((0x$PAGE_SIZE)) |
107 | test $PAGE_SIZE -lt 512 && exit 1 | 96 | test $PAGE_SIZE -lt 1024 && exit 1 |
108 | 97 | ||
109 | # How much space between _end[] and next page? | 98 | # How much space between _end[] and next page? |
110 | PAGE_MASK=$((PAGE_SIZE-1)) | 99 | PAGE_MASK=$((PAGE_SIZE-1)) |
111 | TAIL_SIZE=$(( (-END) & PAGE_MASK )) | 100 | TAIL_SIZE=$(( (-END) & PAGE_MASK )) |
112 | $debug && echo "TAIL_SIZE:$TAIL_SIZE bytes" | 101 | $debug && echo "TAIL_SIZE:$TAIL_SIZE bytes" |
113 | 102 | ||
114 | if test x"$method" = x"1k" || test x"$method" = x"big"; then | 103 | if test x"$method" = x"1k"; then |
115 | if test $TAIL_SIZE -lt 1024; then | 104 | { |
116 | # _end[] has no enough space for bb_common_bufsiz1[] | 105 | echo $TAIL_SIZE |
117 | echo "Warning! Space in _end[] is too small ($TAIL_SIZE bytes)!" | 106 | md5sum <.config | cut -d' ' -f1 |
118 | echo "Rerun make to build a binary which doesn't use it!" | 107 | stat -c "%Y" .config |
119 | rm -- "$common_bufsiz_h.1k.OK" 2>/dev/null | 108 | } >"$common_bufsiz_h.1k.OK" |
120 | { md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config; } >"$common_bufsiz_h.1k.FAIL" | 109 | round_down_COMMON_BUFSIZE $((1024 + TAIL_SIZE)) |
121 | rm busybox_unstripped busybox 2>/dev/null | 110 | # emit message only if COMMON_BUFSIZE is indeed larger |
122 | # Note: here we can do either a "malloc" or "std" build. | 111 | test $COMMON_BUFSIZE -gt 1024 \ |
123 | # "malloc" gives a bit bigger code: | 112 | && echo "Rerun make to use larger COMMON_BUFSIZE ($COMMON_BUFSIZE)" |
124 | # text bss filename | 113 | test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit |
125 | # 804355 5385 busybox.std | 114 | generate_big_and_exit $COMMON_BUFSIZE "big" |
126 | # 804618 4361 busybox.malloc | ||
127 | # but may have a smaller .bss (not guaranteed!). Use "pmap -x" to verify. | ||
128 | exitcmd="exit 1" | ||
129 | generate_malloc_and_exit | ||
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 | |||
136 | rm -- "$common_bufsiz_h.1k.FAIL" 2>/dev/null | ||
137 | echo $TAIL_SIZE >"$common_bufsiz_h.1k.OK" | ||
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" | ||
148 | fi | ||
149 | fi | 115 | fi |
150 | fi | 116 | fi |
151 | 117 | ||
152 | # Based on past success/fail of 1k build, decide next build type | 118 | # Based on past success/fail of 1k build, decide next build type |
153 | 119 | ||
154 | if test -f "$common_bufsiz_h.1k.OK"; then | 120 | if test -f "$common_bufsiz_h.1k.OK"; then |
155 | # Previous build succeeded fitting 1k into _end[]. | 121 | # previous 1k build succeeded |
156 | # Try bigger COMMON_BUFSIZE if possible. | 122 | oldcfg=`tail -n2 -- "$common_bufsiz_h.1k.OK"` |
157 | TAIL_SIZE=`cat -- "$common_bufsiz_h.1k.OK"` | ||
158 | round_down_COMMON_BUFSIZE $TAIL_SIZE | ||
159 | test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit | ||
160 | generate_big_and_exit $COMMON_BUFSIZE "big" | ||
161 | fi | ||
162 | |||
163 | if test -f "$common_bufsiz_h.1k.FAIL"; then | ||
164 | # Previous build FAILED to fit 1k into _end[]. | ||
165 | # Was it with same .config? | ||
166 | oldcfg=`cat -- "$common_bufsiz_h.1k.FAIL"` | ||
167 | curcfg=`md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config` | 123 | curcfg=`md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config` |
168 | # If yes, then build a "malloced" version | 124 | # config did not change |
169 | if test x"$oldcfg" = x"$curcfg"; then | 125 | if test x"$oldcfg" = x"$curcfg"; then |
170 | echo "Will not try 1k build, it failed before. Touch .config to override" | 126 | # Try bigger COMMON_BUFSIZE if possible |
171 | # Note: here we can do either a "malloc" or "std" build. | 127 | TAIL_SIZE=`head -n1 -- "$common_bufsiz_h.1k.OK"` |
172 | generate_malloc_and_exit | 128 | round_down_COMMON_BUFSIZE $((1024 + TAIL_SIZE)) |
129 | test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit | ||
130 | generate_big_and_exit $COMMON_BUFSIZE "big" | ||
173 | fi | 131 | fi |
174 | # else: try 1k version | 132 | # config did change |
175 | echo "New .config, will try 1k build" | 133 | rm -rf -- "$common_bufsiz_h.1k.OK" |
176 | rm -- "$common_bufsiz_h.1k.FAIL" | ||
177 | generate_1k_and_exit | ||
178 | fi | 134 | fi |
179 | 135 | ||
180 | # There was no 1k build yet. Try it. | 136 | # There was no 1k build yet. Try it. |