Skip to content

Commit

Permalink
rust: module: add static pointer to {init,cleanup}_module()
Browse files Browse the repository at this point in the history
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, 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

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
ojeda committed Jul 23, 2024
1 parent b126341 commit 95053ff
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rust/macros/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
unsafe {{ __init() }}
}}
#[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]
Expand All @@ -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))]
Expand Down

0 comments on commit 95053ff

Please sign in to comment.