Skip to content

Commit

Permalink
Merge pull request torvalds#668 from ojeda/nathan
Browse files Browse the repository at this point in the history
scripts: `is_rust_module.sh` rework
  • Loading branch information
ojeda authored Feb 11, 2022
2 parents a274015 + 0fb3dcb commit 5bded08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
9 changes: 9 additions & 0 deletions rust/macros/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
/// Used by the printing macros, e.g. [`info!`].
const __LOG_PREFIX: &[u8] = b\"{name}\\0\";
/// The \"Rust loadable module\" mark, for `scripts/is_rust_module.sh`.
//
// This may be best done another way later on, e.g. as a new modinfo
// key or a new section. For the moment, keep it simple.
#[cfg(MODULE)]
#[doc(hidden)]
#[used]
static __IS_RUST_MODULE: () = ();
static mut __MOD: Option<{type_}> = None;
// SAFETY: `__this_module` is constructed by the kernel at load time and will not be freed until the module is unloaded.
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.modfinal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ quiet_cmd_btf_ko = BTF [M] $@
cmd_btf_ko = \
if [ ! -f vmlinux ]; then \
printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
elif $(srctree)/scripts/is_rust_module.sh $@; then \
elif [ -n "$(CONFIG_RUST)" ] && $(srctree)/scripts/is_rust_module.sh $@; then \
printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \
else \
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \
Expand Down
20 changes: 7 additions & 13 deletions scripts/is_rust_module.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/bin/bash
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# is_rust_module.sh MOD.ko
# is_rust_module.sh module.ko
#
# Returns 0 if MOD.ko is a rust module, 1 otherwise.
# Returns `0` if `module.ko` is a Rust module, `1` otherwise.

set -e
module="$*"

while IFS= read -r line
do
# Any symbol beginning with "_R" is a v0 mangled rust symbol
if [[ $line =~ ^[0-9a-fA-F]+[[:space:]]+[uUtTrR][[:space:]]+_R[^[:space:]]+$ ]]; then
exit 0
fi
done < <(nm "$module")

exit 1
# Using the `16_` prefix ensures other symbols with the same substring
# are not picked up (even if it would be unlikely). The last part is
# used just in case LLVM decides to use the `.` suffix.
${NM} "$*" | grep -qE '^[0-9a-fA-F]+ r _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$'

0 comments on commit 5bded08

Please sign in to comment.