* [PATCH] rust: Omit visibility pragma when calling bindgen
@ 2026-11-23 17:10 Ard Biesheuvel
0 siblings, 0 replies; only message in thread
From: Ard Biesheuvel @ 2026-11-23 17:10 UTC (permalink / raw)
To: rust-for-linux; +Cc: linux-efi, Ard Biesheuvel
bindgen is used to create Rust FFI definitions from Linux kernel
headers, so that Rust code can call into C code.
bindgen is a generic tool that is typically used on C library headers in
user space, where hidden ELF symbols are never part of the public
library API, and therefore ignored.
The situation in the kernel is different: hidden visibility is used when
using PIC codegen, to force the compiler to omit GOT slots for
references to symbols with global linkage (and to allow the "i" inline
asm constraint to be used with global objects).
So withhold the #pragma when __BINDGEN__ is defined, so that bindgen
does not disregard the kernel's hidden symbols.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
include/linux/hidden.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/include/linux/hidden.h b/include/linux/hidden.h
index 49a17b6b5962..e8d2844047d2 100644
--- a/include/linux/hidden.h
+++ b/include/linux/hidden.h
@@ -14,6 +14,11 @@
* Fortunately, there is a way to inform the compiler that such symbol
* references will be satisfied at link time rather than at load time, by
* giving them 'hidden' visibility.
+ *
+ * Hidden symbols are ignored by bindgen, on the basis that they are never part
+ * of a public API, but this is not the case for the kernel.
*/
+#ifndef __BINDGEN__
#pragma GCC visibility push(hidden)
+#endif
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-23 17:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 17:10 [PATCH] rust: Omit visibility pragma when calling bindgen Ard Biesheuvel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox