Skip to content

Commit 1c3caa1

Browse files
authored
Merge pull request torvalds#491 from danobi/disable_btf_rust
rust: bpf: Disable BTF generation for modules written in Rust
2 parents 0d6f2a0 + 07c4d32 commit 1c3caa1

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

scripts/Makefile.modfinal

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ quiet_cmd_ld_ko_o = LD [M] $@
3939

4040
quiet_cmd_btf_ko = BTF [M] $@
4141
cmd_btf_ko = \
42-
if [ -f vmlinux ]; then \
43-
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J --btf_base vmlinux $@; \
44-
else \
42+
if [ ! -f vmlinux ]; then \
4543
printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
44+
elif $(srctree)/scripts/is_rust_module.sh $@; then \
45+
printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \
46+
else \
47+
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J --btf_base vmlinux $@; \
4648
fi;
4749

4850
# Same as newer-prereqs, but allows to exclude specified extra dependencies

scripts/is_rust_module.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# is_rust_module.sh MOD.ko
5+
#
6+
# Returns 0 if MOD.ko is a rust module, 1 otherwise.
7+
8+
set -e
9+
module="$*"
10+
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

0 commit comments

Comments
 (0)