]> Git Repo - J-linux.git/commitdiff
samples: rust: fix `rust_print` build making it a combined module
authorMiguel Ojeda <[email protected]>
Mon, 11 Nov 2024 22:08:05 +0000 (23:08 +0100)
committerSteven Rostedt (Google) <[email protected]>
Tue, 12 Nov 2024 14:21:48 +0000 (09:21 -0500)
The `rust_print` module, when built as a module, fails to build with:

    ERROR: modpost: missing MODULE_LICENSE() in samples/rust/rust_print_events.o
    ERROR: modpost: "__tracepoint_rust_sample_loaded" [samples/rust/rust_print.ko] undefined!
    ERROR: modpost: "rust_do_trace_rust_sample_loaded" [samples/rust/rust_print.ko] undefined!

Fix it by building it as a combined one.

Cc: Masami Hiramatsu <[email protected]>
Cc: Alex Gaynor <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Boqun Feng <[email protected]>
Cc: Gary Guo <[email protected]>
Cc: Björn Roy Baron <[email protected]>
Cc: Benno Lossin <[email protected]>
Cc: Andreas Hindborg <[email protected]>
Cc: Alice Ryhl <[email protected]>
Cc: Trevor Gross <[email protected]>
Cc: "Linux Next Mailing List" <[email protected]>
Link: https://lore.kernel.org/[email protected]
Reported-by: Stephen Rothwell <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Fixes: 91d39024e1b0 ("rust: samples: add tracepoint to Rust sample")
Signed-off-by: Miguel Ojeda <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
samples/rust/Makefile
samples/rust/rust_print.rs [deleted file]
samples/rust/rust_print_main.rs [new file with mode: 0644]

index f29280ec482083aad1b52227305d58d2a6accda2..c1a5c16553955b1cfc59d77e85e1d60b06242967 100644 (file)
@@ -2,6 +2,8 @@
 ccflags-y += -I$(src)                          # needed for trace events
 
 obj-$(CONFIG_SAMPLE_RUST_MINIMAL)              += rust_minimal.o
-obj-$(CONFIG_SAMPLE_RUST_PRINT)                        += rust_print.o rust_print_events.o
+obj-$(CONFIG_SAMPLE_RUST_PRINT)                        += rust_print.o
+
+rust_print-y := rust_print_main.o rust_print_events.o
 
 subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS)         += hostprogs
diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs
deleted file mode 100644 (file)
index 6d14b08..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-//! Rust printing macros sample.
-
-use kernel::pr_cont;
-use kernel::prelude::*;
-
-module! {
-    type: RustPrint,
-    name: "rust_print",
-    author: "Rust for Linux Contributors",
-    description: "Rust printing macros sample",
-    license: "GPL",
-}
-
-struct RustPrint;
-
-fn arc_print() -> Result {
-    use kernel::sync::*;
-
-    let a = Arc::new(1, GFP_KERNEL)?;
-    let b = UniqueArc::new("hello, world", GFP_KERNEL)?;
-
-    // Prints the value of data in `a`.
-    pr_info!("{}", a);
-
-    // Uses ":?" to print debug fmt of `b`.
-    pr_info!("{:?}", b);
-
-    let a: Arc<&str> = b.into();
-    let c = a.clone();
-
-    // Uses `dbg` to print, will move `c` (for temporary debugging purposes).
-    dbg!(c);
-
-    // Pretty-prints the debug formatting with lower-case hexadecimal integers.
-    pr_info!("{:#x?}", a);
-
-    Ok(())
-}
-
-impl kernel::Module for RustPrint {
-    fn init(_module: &'static ThisModule) -> Result<Self> {
-        pr_info!("Rust printing macros sample (init)\n");
-
-        pr_emerg!("Emergency message (level 0) without args\n");
-        pr_alert!("Alert message (level 1) without args\n");
-        pr_crit!("Critical message (level 2) without args\n");
-        pr_err!("Error message (level 3) without args\n");
-        pr_warn!("Warning message (level 4) without args\n");
-        pr_notice!("Notice message (level 5) without args\n");
-        pr_info!("Info message (level 6) without args\n");
-
-        pr_info!("A line that");
-        pr_cont!(" is continued");
-        pr_cont!(" without args\n");
-
-        pr_emerg!("{} message (level {}) with args\n", "Emergency", 0);
-        pr_alert!("{} message (level {}) with args\n", "Alert", 1);
-        pr_crit!("{} message (level {}) with args\n", "Critical", 2);
-        pr_err!("{} message (level {}) with args\n", "Error", 3);
-        pr_warn!("{} message (level {}) with args\n", "Warning", 4);
-        pr_notice!("{} message (level {}) with args\n", "Notice", 5);
-        pr_info!("{} message (level {}) with args\n", "Info", 6);
-
-        pr_info!("A {} that", "line");
-        pr_cont!(" is {}", "continued");
-        pr_cont!(" with {}\n", "args");
-
-        arc_print()?;
-
-        trace::trace_rust_sample_loaded(42);
-
-        Ok(RustPrint)
-    }
-}
-
-impl Drop for RustPrint {
-    fn drop(&mut self) {
-        pr_info!("Rust printing macros sample (exit)\n");
-    }
-}
-
-mod trace {
-    use core::ffi::c_int;
-
-    kernel::declare_trace! {
-        /// # Safety
-        ///
-        /// Always safe to call.
-        unsafe fn rust_sample_loaded(magic: c_int);
-    }
-
-    pub(crate) fn trace_rust_sample_loaded(magic: i32) {
-        // SAFETY: Always safe to call.
-        unsafe { rust_sample_loaded(magic as c_int) }
-    }
-}
diff --git a/samples/rust/rust_print_main.rs b/samples/rust/rust_print_main.rs
new file mode 100644 (file)
index 0000000..6d14b08
--- /dev/null
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Rust printing macros sample.
+
+use kernel::pr_cont;
+use kernel::prelude::*;
+
+module! {
+    type: RustPrint,
+    name: "rust_print",
+    author: "Rust for Linux Contributors",
+    description: "Rust printing macros sample",
+    license: "GPL",
+}
+
+struct RustPrint;
+
+fn arc_print() -> Result {
+    use kernel::sync::*;
+
+    let a = Arc::new(1, GFP_KERNEL)?;
+    let b = UniqueArc::new("hello, world", GFP_KERNEL)?;
+
+    // Prints the value of data in `a`.
+    pr_info!("{}", a);
+
+    // Uses ":?" to print debug fmt of `b`.
+    pr_info!("{:?}", b);
+
+    let a: Arc<&str> = b.into();
+    let c = a.clone();
+
+    // Uses `dbg` to print, will move `c` (for temporary debugging purposes).
+    dbg!(c);
+
+    // Pretty-prints the debug formatting with lower-case hexadecimal integers.
+    pr_info!("{:#x?}", a);
+
+    Ok(())
+}
+
+impl kernel::Module for RustPrint {
+    fn init(_module: &'static ThisModule) -> Result<Self> {
+        pr_info!("Rust printing macros sample (init)\n");
+
+        pr_emerg!("Emergency message (level 0) without args\n");
+        pr_alert!("Alert message (level 1) without args\n");
+        pr_crit!("Critical message (level 2) without args\n");
+        pr_err!("Error message (level 3) without args\n");
+        pr_warn!("Warning message (level 4) without args\n");
+        pr_notice!("Notice message (level 5) without args\n");
+        pr_info!("Info message (level 6) without args\n");
+
+        pr_info!("A line that");
+        pr_cont!(" is continued");
+        pr_cont!(" without args\n");
+
+        pr_emerg!("{} message (level {}) with args\n", "Emergency", 0);
+        pr_alert!("{} message (level {}) with args\n", "Alert", 1);
+        pr_crit!("{} message (level {}) with args\n", "Critical", 2);
+        pr_err!("{} message (level {}) with args\n", "Error", 3);
+        pr_warn!("{} message (level {}) with args\n", "Warning", 4);
+        pr_notice!("{} message (level {}) with args\n", "Notice", 5);
+        pr_info!("{} message (level {}) with args\n", "Info", 6);
+
+        pr_info!("A {} that", "line");
+        pr_cont!(" is {}", "continued");
+        pr_cont!(" with {}\n", "args");
+
+        arc_print()?;
+
+        trace::trace_rust_sample_loaded(42);
+
+        Ok(RustPrint)
+    }
+}
+
+impl Drop for RustPrint {
+    fn drop(&mut self) {
+        pr_info!("Rust printing macros sample (exit)\n");
+    }
+}
+
+mod trace {
+    use core::ffi::c_int;
+
+    kernel::declare_trace! {
+        /// # Safety
+        ///
+        /// Always safe to call.
+        unsafe fn rust_sample_loaded(magic: c_int);
+    }
+
+    pub(crate) fn trace_rust_sample_loaded(magic: i32) {
+        // SAFETY: Always safe to call.
+        unsafe { rust_sample_loaded(magic as c_int) }
+    }
+}
This page took 0.055462 seconds and 4 git commands to generate.