diff mbox series

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

Message ID 20211026212419.144077-1-jolsa@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [PATCHv2,bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: kpsingh@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Jiri Olsa <jolsa@redhat.com>' != 'Signed-off-by: Jiri Olsa <jolsa@kernel.org>' WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Jiri Olsa Oct. 26, 2021, 9:24 p.m. UTC
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

Comments

kernel test robot Oct. 26, 2021, 10:39 p.m. UTC | #1
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 <lkp@intel.com>

All errors (new ones prefixed by >>):

>> /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
   scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
   scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
>> /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
kernel test robot Oct. 27, 2021, 1:44 p.m. UTC | #2
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 <lkp@intel.com>

All errors (new ones prefixed by >>):

>> /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
--
>> /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
   scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
   scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
>> /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
kernel test robot Oct. 27, 2021, 2:57 p.m. UTC | #3
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 <lkp@intel.com>

All errors (new ones prefixed by >>):

>> /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.
--
>> /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
Jiri Olsa Oct. 28, 2021, 5:14 p.m. UTC | #4
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

> ---
> 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
>
diff mbox series

Patch

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}