[PATCHv2 bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules

Subsystems: kernel build + files below scripts/ (unless maintained elsewhere), the rest

5 messages, 2 authors, 2021-10-28 · open the first message on its own page

[PATCHv2 bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules

From: Jiri Olsa <hidden>
Date: 2021-10-26 21:24:26

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.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
v2 changes:
  - posting separately from original patchset
  - added Andrii's ack

 Makefile                  |  3 +++
 scripts/Makefile.modfinal |  2 +-
 scripts/link-vmlinux.sh   | 11 +----------
 scripts/pahole-flags.sh   | 20 ++++++++++++++++++++
 4 files changed, 25 insertions(+), 11 deletions(-)
 create mode 100755 scripts/pahole-flags.sh
diff --git a/Makefile b/Makefile
index 437ccc66a1c2..ee514b80c62e 100644
--- a/Makefile
+++ b/Makefile
@@ -480,6 +480,8 @@ LZ4		= lz4c
 XZ		= xz
 ZSTD		= zstd
 
+PAHOLE_FLAGS	= $(shell PAHOLE=$(PAHOLE) scripts/pahole-flags.sh)
+
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
 		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
 NOSTDINC_FLAGS :=
@@ -534,6 +536,7 @@ export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
+export PAHOLE_FLAGS
 
 # Files to ignore in find ... statements
 
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 1fb45b011e4b..7f39599e9fae 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -40,7 +40,7 @@ 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 $@; \
+		LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \
 		$(RESOLVE_BTFIDS) -b vmlinux $@; 			\
 	else								\
 		printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index d74cee5c4326..3ea7cece7c97 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -205,7 +205,6 @@ vmlinux_link()
 gen_btf()
 {
 	local pahole_ver
-	local extra_paholeopt=
 
 	if ! [ -x "$(command -v ${PAHOLE})" ]; then
 		echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available"
@@ -220,16 +219,8 @@ gen_btf()
 
 	vmlinux_link ${1}
 
-	if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
-		# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
-		extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
-	fi
-	if [ "${pahole_ver}" -ge "121" ]; then
-		extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
-	fi
-
 	info "BTF" ${2}
-	LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${extra_paholeopt} ${1}
+	LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1}
 
 	# Create ${2} which contains just .BTF section but no symbols. Add
 	# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all
diff --git a/scripts/pahole-flags.sh b/scripts/pahole-flags.sh
new file mode 100755
index 000000000000..2b99fc77019c
--- /dev/null
+++ b/scripts/pahole-flags.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+extra_paholeopt=
+
+if ! [ -x "$(command -v ${PAHOLE})" ]; then
+	return
+fi
+
+pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/')
+
+if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
+	# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
+	extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
+fi
+if [ "${pahole_ver}" -ge "121" ]; then
+	extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
+fi
+
+echo ${extra_paholeopt}
-- 
2.31.1

Re: [PATCHv2 bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules

From: kernel test robot <hidden>
Date: 2021-10-26 22:40:23

Hi Jiri,

I love your patch! Yet something to improve:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Jiri-Olsa/kbuild-Unify-options-for-BTF-generation-for-vmlinux-and-modules/20211027-052639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/cd9d0571d9b0204fb3c1badf41ca847ba840e40c
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Jiri-Olsa/kbuild-Unify-options-for-BTF-generation-for-vmlinux-and-modules/20211027-052639
        git checkout cd9d0571d9b0204fb3c1badf41ca847ba840e40c
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All errors (new ones prefixed by >>):
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
--
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
   scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
   scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
   arch/mips/kernel/asm-offsets.c:26:6: error: no previous prototype for 'output_ptreg_defines' [-Werror=missing-prototypes]
      26 | void output_ptreg_defines(void)
         |      ^~~~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:78:6: error: no previous prototype for 'output_task_defines' [-Werror=missing-prototypes]
      78 | void output_task_defines(void)
         |      ^~~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:92:6: error: no previous prototype for 'output_thread_info_defines' [-Werror=missing-prototypes]
      92 | void output_thread_info_defines(void)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:108:6: error: no previous prototype for 'output_thread_defines' [-Werror=missing-prototypes]
     108 | void output_thread_defines(void)
         |      ^~~~~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:136:6: error: no previous prototype for 'output_thread_fpu_defines' [-Werror=missing-prototypes]
     136 | void output_thread_fpu_defines(void)
         |      ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:179:6: error: no previous prototype for 'output_mm_defines' [-Werror=missing-prototypes]
     179 | void output_mm_defines(void)
         |      ^~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:218:6: error: no previous prototype for 'output_sc_defines' [-Werror=missing-prototypes]
     218 | void output_sc_defines(void)
         |      ^~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:253:6: error: no previous prototype for 'output_signal_defined' [-Werror=missing-prototypes]
     253 | void output_signal_defined(void)
         |      ^~~~~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:320:6: error: no previous prototype for 'output_pbe_defines' [-Werror=missing-prototypes]
     320 | void output_pbe_defines(void)
         |      ^~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:332:6: error: no previous prototype for 'output_pm_defines' [-Werror=missing-prototypes]
     332 | void output_pm_defines(void)
         |      ^~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:346:6: error: no previous prototype for 'output_kvm_defines' [-Werror=missing-prototypes]
     346 | void output_kvm_defines(void)
         |      ^~~~~~~~~~~~~~~~~~
   arch/mips/kernel/asm-offsets.c:390:6: error: no previous prototype for 'output_cps_defines' [-Werror=missing-prototypes]
     390 | void output_cps_defines(void)
         |      ^~~~~~~~~~~~~~~~~~
   cc1: all warnings being treated as errors
   make[2]: *** [scripts/Makefile.build:121: arch/mips/kernel/asm-offsets.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1222: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:219: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Re: [PATCHv2 bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules

From: kernel test robot <hidden>
Date: 2021-10-27 13:44:51

Hi Jiri,

I love your patch! Yet something to improve:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Jiri-Olsa/kbuild-Unify-options-for-BTF-generation-for-vmlinux-and-modules/20211027-052639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: powerpc64-buildonly-randconfig-r006-20211027 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 5db7568a6a1fcb408eb8988abdaff2a225a8eb72)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install powerpc64 cross compiling tool for clang build
        # apt-get install binutils-powerpc64-linux-gnu
        # https://github.com/0day-ci/linux/commit/cd9d0571d9b0204fb3c1badf41ca847ba840e40c
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Jiri-Olsa/kbuild-Unify-options-for-BTF-generation-for-vmlinux-and-modules/20211027-052639
        git checkout cd9d0571d9b0204fb3c1badf41ca847ba840e40c
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc distclean

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All errors (new ones prefixed by >>):
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
   /bin/sh: 1: scripts/pahole-flags.sh: not found
   /bin/sh: 1: scripts/pahole-flags.sh: not found
   /bin/sh: 1: scripts/pahole-flags.sh: not found
   /bin/sh: 1: scripts/pahole-flags.sh: not found
--
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
--
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
   scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
   scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
quoted
/bin/sh: 1: scripts/pahole-flags.sh: not found
/bin/sh: 1: scripts/pahole-flags.sh: not found
   clang-14: error: unsupported argument '-mpower4' to option 'Wa,'
   clang-14: error: unsupported argument '-many' to option 'Wa,'
   make[2]: *** [scripts/Makefile.build:277: scripts/mod/empty.o] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1221: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:219: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Re: [PATCHv2 bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules

From: kernel test robot <hidden>
Date: 2021-10-27 14:57:58

Hi Jiri,

I love your patch! Yet something to improve:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Jiri-Olsa/kbuild-Unify-options-for-BTF-generation-for-vmlinux-and-modules/20211027-052639
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: openrisc-buildonly-randconfig-r001-20211027 (attached as .config)
compiler: or1k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/cd9d0571d9b0204fb3c1badf41ca847ba840e40c
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Jiri-Olsa/kbuild-Unify-options-for-BTF-generation-for-vmlinux-and-modules/20211027-052639
        git checkout cd9d0571d9b0204fb3c1badf41ca847ba840e40c
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <redacted>

All errors (new ones prefixed by >>):
quoted
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
/bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   make[1]: *** [Makefile:1871: init] Error 2
   make[1]: *** [Makefile:1871: arch/openrisc] Error 2
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   /bin/bash: scripts/pahole-flags.sh: No such file or directory
   make[1]: *** [Makefile:1871: security] Error 2
   make[1]: *** [Makefile:1871: mm] Error 2
   make[1]: *** [Makefile:1871: block] Error 2
   make[1]: *** [Makefile:1871: kernel] Error 2
   make[1]: *** [Makefile:1871: net] Error 2
   make[1]: *** [Makefile:1871: lib] Error 2
   make[1]: *** [Makefile:1871: fs] Error 2
   make[1]: *** [Makefile:1871: drivers] Error 2
   make[1]: *** [Makefile:1871: sound] Error 2
   make[1]: Target '__all' not remade because of errors.
--
quoted
/bin/bash: scripts/pahole-flags.sh: No such file or directory
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Re: [PATCHv2 bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules

From: Jiri Olsa <hidden>
Date: 2021-10-28 17:14:52

On Tue, Oct 26, 2021 at 11:24:19PM +0200, Jiri Olsa wrote:
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.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
I'm checking on reported build failures and will send v3

jirka
quoted hunk
---
v2 changes:
  - posting separately from original patchset
  - added Andrii's ack

 Makefile                  |  3 +++
 scripts/Makefile.modfinal |  2 +-
 scripts/link-vmlinux.sh   | 11 +----------
 scripts/pahole-flags.sh   | 20 ++++++++++++++++++++
 4 files changed, 25 insertions(+), 11 deletions(-)
 create mode 100755 scripts/pahole-flags.sh
diff --git a/Makefile b/Makefile
index 437ccc66a1c2..ee514b80c62e 100644
--- a/Makefile
+++ b/Makefile
@@ -480,6 +480,8 @@ LZ4		= lz4c
 XZ		= xz
 ZSTD		= zstd
 
+PAHOLE_FLAGS	= $(shell PAHOLE=$(PAHOLE) scripts/pahole-flags.sh)
+
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
 		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
 NOSTDINC_FLAGS :=
@@ -534,6 +536,7 @@ export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
+export PAHOLE_FLAGS
 
 # Files to ignore in find ... statements
 
diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 1fb45b011e4b..7f39599e9fae 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -40,7 +40,7 @@ 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 $@; \
+		LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \
 		$(RESOLVE_BTFIDS) -b vmlinux $@; 			\
 	else								\
 		printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index d74cee5c4326..3ea7cece7c97 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -205,7 +205,6 @@ vmlinux_link()
 gen_btf()
 {
 	local pahole_ver
-	local extra_paholeopt=
 
 	if ! [ -x "$(command -v ${PAHOLE})" ]; then
 		echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available"
@@ -220,16 +219,8 @@ gen_btf()
 
 	vmlinux_link ${1}
 
-	if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
-		# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
-		extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
-	fi
-	if [ "${pahole_ver}" -ge "121" ]; then
-		extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
-	fi
-
 	info "BTF" ${2}
-	LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${extra_paholeopt} ${1}
+	LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1}
 
 	# Create ${2} which contains just .BTF section but no symbols. Add
 	# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all
diff --git a/scripts/pahole-flags.sh b/scripts/pahole-flags.sh
new file mode 100755
index 000000000000..2b99fc77019c
--- /dev/null
+++ b/scripts/pahole-flags.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+extra_paholeopt=
+
+if ! [ -x "$(command -v ${PAHOLE})" ]; then
+	return
+fi
+
+pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/')
+
+if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
+	# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
+	extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
+fi
+if [ "${pahole_ver}" -ge "121" ]; then
+	extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
+fi
+
+echo ${extra_paholeopt}
-- 
2.31.1

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help