rust: Omit visibility pragma when calling bindgen
Ard Biesheuvel
maintainerPATCH 1/1 rust: Omit visibility pragma when calling bindgen
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 <[email protected]>
--- include/linux/hidden.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/hidden.h +5 -0
@@ -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
Signature · 1 line
2.53.0