aboutsummaryrefslogtreecommitdiff
path: root/libbb/const_hack.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libbb/const_hack.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/libbb/const_hack.c b/libbb/const_hack.c
index 9575e6d67..1d175481b 100644
--- a/libbb/const_hack.c
+++ b/libbb/const_hack.c
@@ -9,8 +9,27 @@
9#include "libbb.h" 9#include "libbb.h"
10 10
11#if defined(__clang_major__) && __clang_major__ >= 9 11#if defined(__clang_major__) && __clang_major__ >= 9
12/* Clang/llvm drops assignment to "constant" storage. Silently.
13 * Needs serious convincing to not eliminate the store.
14 */
15static ALWAYS_INLINE void* not_const_pp(const void *p)
16{
17 void *pp;
18 asm volatile (
19 "# forget that p points to const"
20 : /*outputs*/ "=r" (pp)
21 : /*inputs*/ "0" (p)
22 );
23 return pp;
24}
25void FAST_FUNC ASSIGN_CONST_PTR(const void *pptr, void *v)
26{
27 *(void**)not_const_pp(pptr) = v;
28 barrier();
29}
12void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size) 30void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size)
13{ 31{
14 ASSIGN_CONST_PTR(pptr, xzalloc(size)); 32 *(void**)not_const_pp(pptr) = xzalloc(size);
33 barrier();
15} 34}
16#endif 35#endif