File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -503,6 +503,15 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
503503 /// Used by the printing macros, e.g. [`info!`].
504504 const __LOG_PREFIX: &[u8] = b\" {name}\\ 0\" ;
505505
506+ /// The \" Rust loadable module\" mark, for `scripts/is_rust_module.sh`.
507+ //
508+ // This may be best done another way later on, e.g. as a new modinfo
509+ // key or a new section. For the moment, keep it simple.
510+ #[cfg(MODULE)]
511+ #[doc(hidden)]
512+ #[used]
513+ static __IS_RUST_MODULE: () = ();
514+
506515 static mut __MOD: Option<{type_}> = None;
507516
508517 // SAFETY: `__this_module` is constructed by the kernel at load time and will not be freed until the module is unloaded.
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ quiet_cmd_btf_ko = BTF [M] $@
4141 cmd_btf_ko = \
4242 if [ ! -f vmlinux ]; then \
4343 printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
44- elif $(srctree)/scripts/is_rust_module.sh $@; then \
44+ elif [ -n "$(CONFIG_RUST)" ] && $(srctree)/scripts/is_rust_module.sh $@; then \
4545 printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \
4646 else \
4747 LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \
Original file line number Diff line number Diff line change 1- #! /bin/bash
1+ #! /bin/sh
22# SPDX-License-Identifier: GPL-2.0
33#
4- # is_rust_module.sh MOD .ko
4+ # is_rust_module.sh module .ko
55#
6- # Returns 0 if MOD .ko is a rust module, 1 otherwise.
6+ # Returns `0` if `module .ko` is a Rust module, `1` otherwise.
77
88set -e
9- module=" $* "
109
11- while IFS= read -r line
12- do
13- # Any symbol beginning with "_R" is a v0 mangled rust symbol
14- if [[ $line =~ ^[0-9a-fA-F]+[[:space:]]+[uUtTrR][[:space:]]+_R[^[:space:]]+$ ]]; then
15- exit 0
16- fi
17- done < < (nm " $module " )
18-
19- exit 1
10+ # Using the `16_` prefix ensures other symbols with the same substring
11+ # are not picked up (even if it would be unlikely). The last part is
12+ # used just in case LLVM decides to use the `.` suffix.
13+ ${NM} " $* " | grep -qE ' ^[0-9a-fA-F]+ r _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$'
You can’t perform that action at this time.
0 commit comments