Skip to content

Commit

Permalink
Merge pull request torvalds#491 from danobi/disable_btf_rust
Browse files Browse the repository at this point in the history
rust: bpf: Disable BTF generation for modules written in Rust
  • Loading branch information
ojeda authored Oct 5, 2021
2 parents 0d6f2a0 + 07c4d32 commit 1c3caa1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/Makefile.modfinal
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ quiet_cmd_ld_ko_o = LD [M] $@

quiet_cmd_btf_ko = BTF [M] $@
cmd_btf_ko = \
if [ -f vmlinux ]; then \
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J --btf_base vmlinux $@; \
else \
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 \
printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \
else \
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J --btf_base vmlinux $@; \
fi;

# Same as newer-prereqs, but allows to exclude specified extra dependencies
Expand Down
19 changes: 19 additions & 0 deletions scripts/is_rust_module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# is_rust_module.sh MOD.ko
#
# Returns 0 if MOD.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

0 comments on commit 1c3caa1

Please sign in to comment.