Skip to content

Commit 5bded08

Browse files
authored
Merge pull request torvalds#668 from ojeda/nathan
scripts: `is_rust_module.sh` rework
2 parents a274015 + 0fb3dcb commit 5bded08

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

rust/macros/module.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

scripts/Makefile.modfinal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 $@; \

scripts/is_rust_module.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
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

88
set -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:]]*$'

0 commit comments

Comments
 (0)