← Commit list

244f5c479

Bin Meng
Bin Meng
2025-07-01
SUCCESS Duration: 155s

Subject

libbb: Prevent clang from reading the G pointer before it is assigned

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

include/libbb.h+3 -19
@@ -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 { \
libbb/const_hack.c+20 -1
@@ -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