Skip to content

Commit dd90a6f

Browse files
ojedaDarksonn
authored andcommitted
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]> Signed-off-by: Miguel Ojeda <[email protected]> Reviewed-by: Gary Guo <[email protected]>
1 parent de9c2c6 commit dd90a6f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rust/macros/module.rs

+12
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
256256
unsafe {{ __init() }}
257257
}}
258258
259+
#[cfg(MODULE)]
260+
#[doc(hidden)]
261+
#[used]
262+
#[link_section = \".init.data\"]
263+
static __UNIQUE_ID___addressable_init_module: unsafe extern \"C\" fn() -> i32 = init_module;
264+
259265
#[cfg(MODULE)]
260266
#[doc(hidden)]
261267
#[no_mangle]
@@ -269,6 +275,12 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
269275
unsafe {{ __exit() }}
270276
}}
271277
278+
#[cfg(MODULE)]
279+
#[doc(hidden)]
280+
#[used]
281+
#[link_section = \".exit.data\"]
282+
static __UNIQUE_ID___addressable_cleanup_module: extern \"C\" fn() = cleanup_module;
283+
272284
// Built-in modules are initialized through an initcall pointer
273285
// and the identifiers need to be unique.
274286
#[cfg(not(MODULE))]

0 commit comments

Comments
 (0)