Skip to content

Commit 9741e07

Browse files
Jiri Olsaanakryiko
authored andcommitted
kbuild: Unify options for BTF generation for vmlinux and modules
Using new PAHOLE_FLAGS variable to pass extra arguments to pahole for both vmlinux and modules BTF data generation. Adding new scripts/pahole-flags.sh script that detect and prints pahole options. [ fixed issues found by kernel test robot ] Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0869e50 commit 9741e07

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ LZ4 = lz4c
480480
XZ = xz
481481
ZSTD = zstd
482482

483+
PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)
484+
483485
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
484486
-Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
485487
NOSTDINC_FLAGS :=
@@ -534,6 +536,7 @@ export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
534536
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
535537
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
536538
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
539+
export PAHOLE_FLAGS
537540

538541
# Files to ignore in find ... statements
539542

scripts/Makefile.modfinal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ quiet_cmd_ld_ko_o = LD [M] $@
4040
quiet_cmd_btf_ko = BTF [M] $@
4141
cmd_btf_ko = \
4242
if [ -f vmlinux ]; then \
43-
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J --btf_base vmlinux $@; \
43+
LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \
4444
$(RESOLVE_BTFIDS) -b vmlinux $@; \
4545
else \
4646
printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \

scripts/link-vmlinux.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ vmlinux_link()
205205
gen_btf()
206206
{
207207
local pahole_ver
208-
local extra_paholeopt=
209208

210209
if ! [ -x "$(command -v ${PAHOLE})" ]; then
211210
echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available"
@@ -220,16 +219,8 @@ gen_btf()
220219

221220
vmlinux_link ${1}
222221

223-
if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
224-
# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
225-
extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
226-
fi
227-
if [ "${pahole_ver}" -ge "121" ]; then
228-
extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
229-
fi
230-
231222
info "BTF" ${2}
232-
LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${extra_paholeopt} ${1}
223+
LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1}
233224

234225
# Create ${2} which contains just .BTF section but no symbols. Add
235226
# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all

scripts/pahole-flags.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
extra_paholeopt=
5+
6+
if ! [ -x "$(command -v ${PAHOLE})" ]; then
7+
return
8+
fi
9+
10+
pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/')
11+
12+
if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
13+
# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
14+
extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
15+
fi
16+
if [ "${pahole_ver}" -ge "121" ]; then
17+
extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
18+
fi
19+
20+
echo ${extra_paholeopt}

0 commit comments

Comments
 (0)