diff options
| author | Miguel Ojeda <[email protected]> | 2024-07-25 18:33:18 +0000 |
|---|---|---|
| committer | Miguel Ojeda <[email protected]> | 2024-08-18 21:34:37 +0000 |
| commit | 289088d54623a1a50bb3ff79f7331bbe501ea591 (patch) | |
| tree | 458a4cb8718b03743eca2e0342f06552d811ea7e /rust/macros/module.rs | |
| parent | rust: kbuild: split up helpers.c (diff) | |
| download | kernel-289088d54623a1a50bb3ff79f7331bbe501ea591.tar.gz kernel-289088d54623a1a50bb3ff79f7331bbe501ea591.zip | |
rust: module: add static pointer to `{init,cleanup}_module()`
Add the equivalent of the `___ADDRESSABLE()` annotation in the
`module_{init,exit}` macros to the Rust `module!` macro.
Without this, `objtool` would complain if enabled for Rust (under IBT
builds), e.g.:
samples/rust/rust_print.o: warning: objtool: cleanup_module(): not an indirect call target
samples/rust/rust_print.o: warning: objtool: init_module(): not an indirect call target
Tested-by: Alice Ryhl <[email protected]>
Tested-by: Benno Lossin <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/macros/module.rs')
| -rw-r--r-- | rust/macros/module.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 411dc103d82e..571ffa2e189c 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -258,6 +258,12 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { #[cfg(MODULE)] #[doc(hidden)] + #[used] + #[link_section = \".init.data\"] + static __UNIQUE_ID___addressable_init_module: unsafe extern \"C\" fn() -> i32 = init_module; + + #[cfg(MODULE)] + #[doc(hidden)] #[no_mangle] pub extern \"C\" fn cleanup_module() {{ // SAFETY: @@ -269,6 +275,12 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { unsafe {{ __exit() }} }} + #[cfg(MODULE)] + #[doc(hidden)] + #[used] + #[link_section = \".exit.data\"] + static __UNIQUE_ID___addressable_cleanup_module: extern \"C\" fn() = cleanup_module; + // Built-in modules are initialized through an initcall pointer // and the identifiers need to be unique. #[cfg(not(MODULE))] |
