diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-25 12:12:22 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-25 12:12:22 +0200 |
commit | af7169b4a70eb3f60555ced17a40780f70aaaa5c (patch) | |
tree | 1633c3306b7d538fb44b12d27ec299e8db0f35fa | |
parent | e1a7c97ac640701973eea000007fc8b9f9dd7126 (diff) | |
download | busybox-w32-af7169b4a70eb3f60555ced17a40780f70aaaa5c.tar.gz busybox-w32-af7169b4a70eb3f60555ced17a40780f70aaaa5c.tar.bz2 busybox-w32-af7169b4a70eb3f60555ced17a40780f70aaaa5c.zip |
clang/llvm 9 fix - do not eliminate a store to a fake "const"
This is *much* better (9 kbytes better) than dropping "*const"
optimization trick.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/test.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 22 | ||||
-rw-r--r-- | libbb/appletlib.c | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 2 | ||||
-rw-r--r-- | shell/ash.c | 6 |
5 files changed, 27 insertions, 7 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index 868ffbecb..a08986130 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
@@ -411,7 +411,7 @@ extern struct test_statics *const test_ptr_to_statics; | |||
411 | #define leaving (S.leaving ) | 411 | #define leaving (S.leaving ) |
412 | 412 | ||
413 | #define INIT_S() do { \ | 413 | #define INIT_S() do { \ |
414 | (*(struct test_statics**)&test_ptr_to_statics) = xzalloc(sizeof(S)); \ | 414 | (*(struct test_statics**)not_const_pp(&test_ptr_to_statics)) = xzalloc(sizeof(S)); \ |
415 | barrier(); \ | 415 | barrier(); \ |
416 | } while (0) | 416 | } while (0) |
417 | #define DEINIT_S() do { \ | 417 | #define DEINIT_S() do { \ |
diff --git a/include/libbb.h b/include/libbb.h index 111d1b790..05a560977 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -2153,12 +2153,32 @@ struct globals; | |||
2153 | * Magic prevents ptr_to_globals from going into rodata. | 2153 | * Magic prevents ptr_to_globals from going into rodata. |
2154 | * If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */ | 2154 | * If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */ |
2155 | extern struct globals *const ptr_to_globals; | 2155 | extern struct globals *const ptr_to_globals; |
2156 | |||
2157 | #if defined(__clang_major__) && __clang_major__ >= 9 | ||
2158 | /* Clang/llvm drops assignment to "constant" storage. Silently. | ||
2159 | * Needs serious convincing to not eliminate the store. | ||
2160 | */ | ||
2161 | static ALWAYS_INLINE void* not_const_pp(const void *p) | ||
2162 | { | ||
2163 | void *pp; | ||
2164 | __asm__ __volatile__( | ||
2165 | "# forget that p points to const" | ||
2166 | : /*outputs*/ "=r" (pp) | ||
2167 | : /*inputs*/ "0" (p) | ||
2168 | ); | ||
2169 | return pp; | ||
2170 | } | ||
2171 | #else | ||
2172 | static ALWAYS_INLINE void* not_const_pp(const void *p) { return (void*)p; } | ||
2173 | #endif | ||
2174 | |||
2156 | /* At least gcc 3.4.6 on mipsel system needs optimization barrier */ | 2175 | /* At least gcc 3.4.6 on mipsel system needs optimization barrier */ |
2157 | #define barrier() __asm__ __volatile__("":::"memory") | 2176 | #define barrier() __asm__ __volatile__("":::"memory") |
2158 | #define SET_PTR_TO_GLOBALS(x) do { \ | 2177 | #define SET_PTR_TO_GLOBALS(x) do { \ |
2159 | (*(struct globals**)&ptr_to_globals) = (void*)(x); \ | 2178 | (*(struct globals**)not_const_pp(&ptr_to_globals)) = (void*)(x); \ |
2160 | barrier(); \ | 2179 | barrier(); \ |
2161 | } while (0) | 2180 | } while (0) |
2181 | |||
2162 | #define FREE_PTR_TO_GLOBALS() do { \ | 2182 | #define FREE_PTR_TO_GLOBALS() do { \ |
2163 | if (ENABLE_FEATURE_CLEAN_UP) { \ | 2183 | if (ENABLE_FEATURE_CLEAN_UP) { \ |
2164 | free(ptr_to_globals); \ | 2184 | free(ptr_to_globals); \ |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 9fa17cfa1..f842e73cc 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -304,7 +304,7 @@ void lbb_prepare(const char *applet | |||
304 | IF_FEATURE_INDIVIDUAL(, char **argv)) | 304 | IF_FEATURE_INDIVIDUAL(, char **argv)) |
305 | { | 305 | { |
306 | #ifdef __GLIBC__ | 306 | #ifdef __GLIBC__ |
307 | (*(int **)&bb_errno) = __errno_location(); | 307 | (*(int **)not_const_pp(&bb_errno)) = __errno_location(); |
308 | barrier(); | 308 | barrier(); |
309 | #endif | 309 | #endif |
310 | applet_name = applet; | 310 | applet_name = applet; |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index fbabc6c12..b1ec52b88 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -203,7 +203,7 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; | |||
203 | #define delbuf (S.delbuf ) | 203 | #define delbuf (S.delbuf ) |
204 | 204 | ||
205 | #define INIT_S() do { \ | 205 | #define INIT_S() do { \ |
206 | (*(struct lineedit_statics**)&lineedit_ptr_to_statics) = xzalloc(sizeof(S)); \ | 206 | (*(struct lineedit_statics**)not_const_pp(&lineedit_ptr_to_statics)) = xzalloc(sizeof(S)); \ |
207 | barrier(); \ | 207 | barrier(); \ |
208 | cmdedit_termw = 80; \ | 208 | cmdedit_termw = 80; \ |
209 | IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ | 209 | IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ |
diff --git a/shell/ash.c b/shell/ash.c index c5588ea66..4b5eafa7c 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -489,7 +489,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; | |||
489 | #define random_gen (G_misc.random_gen ) | 489 | #define random_gen (G_misc.random_gen ) |
490 | #define backgndpid (G_misc.backgndpid ) | 490 | #define backgndpid (G_misc.backgndpid ) |
491 | #define INIT_G_misc() do { \ | 491 | #define INIT_G_misc() do { \ |
492 | (*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \ | 492 | (*(struct globals_misc**)not_const_pp(&ash_ptr_to_globals_misc)) = xzalloc(sizeof(G_misc)); \ |
493 | barrier(); \ | 493 | barrier(); \ |
494 | curdir = nullstr; \ | 494 | curdir = nullstr; \ |
495 | physdir = nullstr; \ | 495 | physdir = nullstr; \ |
@@ -1542,7 +1542,7 @@ extern struct globals_memstack *BB_GLOBAL_CONST ash_ptr_to_globals_memstack; | |||
1542 | #define g_stacknleft (G_memstack.g_stacknleft) | 1542 | #define g_stacknleft (G_memstack.g_stacknleft) |
1543 | #define stackbase (G_memstack.stackbase ) | 1543 | #define stackbase (G_memstack.stackbase ) |
1544 | #define INIT_G_memstack() do { \ | 1544 | #define INIT_G_memstack() do { \ |
1545 | (*(struct globals_memstack**)&ash_ptr_to_globals_memstack) = xzalloc(sizeof(G_memstack)); \ | 1545 | (*(struct globals_memstack**)not_const_pp(&ash_ptr_to_globals_memstack)) = xzalloc(sizeof(G_memstack)); \ |
1546 | barrier(); \ | 1546 | barrier(); \ |
1547 | g_stackp = &stackbase; \ | 1547 | g_stackp = &stackbase; \ |
1548 | g_stacknxt = stackbase.space; \ | 1548 | g_stacknxt = stackbase.space; \ |
@@ -2165,7 +2165,7 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var; | |||
2165 | #endif | 2165 | #endif |
2166 | #define INIT_G_var() do { \ | 2166 | #define INIT_G_var() do { \ |
2167 | unsigned i; \ | 2167 | unsigned i; \ |
2168 | (*(struct globals_var**)&ash_ptr_to_globals_var) = xzalloc(sizeof(G_var)); \ | 2168 | (*(struct globals_var**)not_const_pp(&ash_ptr_to_globals_var)) = xzalloc(sizeof(G_var)); \ |
2169 | barrier(); \ | 2169 | barrier(); \ |
2170 | for (i = 0; i < ARRAY_SIZE(varinit_data); i++) { \ | 2170 | for (i = 0; i < ARRAY_SIZE(varinit_data); i++) { \ |
2171 | varinit[i].flags = varinit_data[i].flags; \ | 2171 | varinit[i].flags = varinit_data[i].flags; \ |