[PATCH 1/2] compiler.h: Use the symbol's own pointer type in __ADDRESSABLE()

From: Ard Biesheuvel

Date: Fri Nov 27 2026 - 09:24:11 EST


From: Ard Biesheuvel <ardb@xxxxxxxxxx>

Casting the address of a variable in a named address space to void * is
rejected by GCC, which is why it is currently cast via uintptr_t. Clang
folds that into an addrspacecast, which it cannot emit in a static
initializer, preventing such variables from being exported.

Use a pointer of the symbol's own type instead, which needs no cast at
all.

Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
---
include/linux/compiler.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 0ea7150dba7b..9983f8eed085 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -286,8 +286,8 @@ static inline void *offset_to_ptr(const int *off)
* visible to the compiler.
*/
#define ___ADDRESSABLE(sym, __attrs) \
- static void * __used __attrs \
- __UNIQUE_ID(__PASTE(addressable_, sym)) = (void *)(uintptr_t)&sym;
+ static typeof(&sym) __used __attrs \
+ __UNIQUE_ID(__PASTE(addressable_, sym)) = &sym;

#define __ADDRESSABLE(sym) \
___ADDRESSABLE(sym, __section(".discard.addressable"))
--
2.56.1.839.g22a8290db9-goog