diff options
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 84811c4f2..0aa44eb37 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -2218,12 +2218,32 @@ struct globals; | |||
2218 | * Magic prevents ptr_to_globals from going into rodata. | 2218 | * Magic prevents ptr_to_globals from going into rodata. |
2219 | * If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */ | 2219 | * If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */ |
2220 | extern struct globals *const ptr_to_globals; | 2220 | extern struct globals *const ptr_to_globals; |
2221 | |||
2222 | #if defined(__clang_major__) && __clang_major__ >= 9 | ||
2223 | /* Clang/llvm drops assignment to "constant" storage. Silently. | ||
2224 | * Needs serious convincing to not eliminate the store. | ||
2225 | */ | ||
2226 | static ALWAYS_INLINE void* not_const_pp(const void *p) | ||
2227 | { | ||
2228 | void *pp; | ||
2229 | __asm__ __volatile__( | ||
2230 | "# forget that p points to const" | ||
2231 | : /*outputs*/ "=r" (pp) | ||
2232 | : /*inputs*/ "0" (p) | ||
2233 | ); | ||
2234 | return pp; | ||
2235 | } | ||
2236 | #else | ||
2237 | static ALWAYS_INLINE void* not_const_pp(const void *p) { return (void*)p; } | ||
2238 | #endif | ||
2239 | |||
2221 | /* At least gcc 3.4.6 on mipsel system needs optimization barrier */ | 2240 | /* At least gcc 3.4.6 on mipsel system needs optimization barrier */ |
2222 | #define barrier() __asm__ __volatile__("":::"memory") | 2241 | #define barrier() __asm__ __volatile__("":::"memory") |
2223 | #define SET_PTR_TO_GLOBALS(x) do { \ | 2242 | #define SET_PTR_TO_GLOBALS(x) do { \ |
2224 | (*(struct globals**)&ptr_to_globals) = (void*)(x); \ | 2243 | (*(struct globals**)not_const_pp(&ptr_to_globals)) = (void*)(x); \ |
2225 | barrier(); \ | 2244 | barrier(); \ |
2226 | } while (0) | 2245 | } while (0) |
2246 | |||
2227 | #define FREE_PTR_TO_GLOBALS() do { \ | 2247 | #define FREE_PTR_TO_GLOBALS() do { \ |
2228 | if (ENABLE_FEATURE_CLEAN_UP) { \ | 2248 | if (ENABLE_FEATURE_CLEAN_UP) { \ |
2229 | free(ptr_to_globals); \ | 2249 | free(ptr_to_globals); \ |