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 /include | |
| 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>
Diffstat (limited to 'include')
| -rw-r--r-- | include/libbb.h | 22 |
1 files changed, 21 insertions, 1 deletions
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); \ |
