aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h22
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) */
2155extern struct globals *const ptr_to_globals; 2155extern 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 */
2161static 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
2172static 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); \