[PATCH v2] rust: macros: document emit_base in ModInfoBuilder
From: Ivan Tverdokhleb
Date: Fri Nov 20 2026 - 03:20:34 EST
Add documentation for the emit_base method within the ModInfoBuilder
struct. Explain its role in formatting metadata strings, handling the
differentiation between built-in and loadable modules, and managing
linker sections and conditional compilation.
Signed-off-by: Ivan Tverdokhleb <mbkchelofficialdev@xxxxxxxxx>
---
Changes in v2:
- Fixed the typo in my last name in the From and Signed-off-by lines.
- Reworded the documentation: dropped an unverified claim about the
reason for the module name prefix, and documented the `param`
argument.
v1: https://lore.kernel.org/rust-for-linux/20261028155005.174417-1-mbkchelofficialdev@xxxxxxxxx/
rust/macros/module.rs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 0a7b9e24c..6f4aacfe7 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -49,6 +49,20 @@ fn new(module: &'a str) -> Self {
}
}
+ /// Emits a single metadata entry into the module information table.
+ ///
+ /// This method formats a `field=content\0` byte string and places it into the
+ /// `.modinfo` linker section, except on macOS where `link_section` is omitted.
+ /// For built-in modules (`builtin == true`), the string is prefixed with
+ /// `<module>.`; for loadable modules, it is emitted without a prefix.
+ ///
+ /// The `param` flag selects which token stream receives the generated item: when
+ /// `true`, the entry is appended to `param_ts` (used for module parameters via
+ /// [`Self::emit_param`] and placed inside `mod module_parameters`); when
+ /// `false`, it is appended to `ts` in the main generated module code.
+ ///
+ /// The method also generates a unique static identifier using an internal counter
+ /// and applies `#[cfg(not(MODULE))]` or `#[cfg(MODULE)]` based on `builtin`.
fn emit_base(&mut self, field: &str, content: &str, builtin: bool, param: bool) {
let string = if builtin {
// Built-in modules prefix their modinfo strings by `module.`.
--
2.56.1