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 New, archived
Headers show
Series [PATCHv2,bpf-next] kbuild: Unify options for BTF generation for vmlinux and modules | expand

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. 27, 2021, 1:44 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: 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 | #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: 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 | #3
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}