libbb: Prevent clang from reading the G pointer before it is assigned
No binary (build failed)
—
(log yok)
| @@ -2337,26 +2337,10 @@ extern struct globals *BB_GLOBAL_CONST ptr_to_globals; | |
| #define barrier() asm volatile ("":::"memory") | |
| #if defined(__clang_major__) && __clang_major__ >= 9 | |
| - | /* Clang/llvm drops assignment to "constant" storage. Silently. |
| - | * Needs serious convincing to not eliminate the store. |
| - | */ |
| - | static ALWAYS_INLINE void* not_const_pp(const void *p) |
| - | { |
| - | void *pp; |
| - | asm volatile ( |
| - | "# forget that p points to const" |
| - | : /*outputs*/ "=r" (pp) |
| - | : /*inputs*/ "0" (p) |
| - | ); |
| - | return pp; |
| - | } |
| - | # define ASSIGN_CONST_PTR(pptr, v) do { \ |
| - | *(void**)not_const_pp(pptr) = (void*)(v); \ |
| - | barrier(); \ |
| - | } while (0) |
| - | /* XZALLOC_CONST_PTR() is an out-of-line function to prevent |
| - | * clang from reading pointer before it is assigned. |
| + | /* {ASSIGN,XZALLOC}_CONST_PTR() are out-of-line functions |
| + | * to prevent clang from reading pointer before it is assigned. |
| */ | |
| + | void ASSIGN_CONST_PTR(const void *pptr, void *v) FAST_FUNC; |
| void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; | |
| #else | |
| # define ASSIGN_CONST_PTR(pptr, v) do { \ | |
| @@ -9,8 +9,27 @@ | |
| #include "libbb.h" | |
| #if defined(__clang_major__) && __clang_major__ >= 9 | |
| + | /* Clang/llvm drops assignment to "constant" storage. Silently. |
| + | * Needs serious convincing to not eliminate the store. |
| + | */ |
| + | static ALWAYS_INLINE void* not_const_pp(const void *p) |
| + | { |
| + | void *pp; |
| + | asm volatile ( |
| + | "# forget that p points to const" |
| + | : /*outputs*/ "=r" (pp) |
| + | : /*inputs*/ "0" (p) |
| + | ); |
| + | return pp; |
| + | } |
| + | void FAST_FUNC ASSIGN_CONST_PTR(const void *pptr, void *v) |
| + | { |
| + | *(void**)not_const_pp(pptr) = v; |
| + | barrier(); |
| + | } |
| void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size) | |
| { | |
| - | ASSIGN_CONST_PTR(pptr, xzalloc(size)); |
| + | *(void**)not_const_pp(pptr) = xzalloc(size); |
| + | barrier(); |
| } | |
| #endif | |