Skip to contentSkip to conversation

kbuild: use objtool-args-y to clean up objtool arguments

PATCH Superseded Masahiro Yamada 3 participants 4 messages Sep 2, 2022 – Sep 6, 2022 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: use objtool-args-y to clean up objtool arguments

Based on Linus' patch.

---

 scripts/Makefile.lib       | 31 ++++++++++++++++---------------
 scripts/Makefile.vmlinux_o | 17 ++++++++---------
 2 files changed, 24 insertions(+), 24 deletions(-)
scripts/Makefile.lib +16 -15
index b594705d571a..731f735240f8 100644
@@ -229,25 +229,26 @@ ifdef CONFIG_OBJTOOL
 
 objtool := $(objtree)/tools/objtool/objtool
 
-objtool_args =								\
-	$(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label)	\
-	$(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr)		\
-	$(if $(CONFIG_X86_KERNEL_IBT), --ibt)				\
-	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)		\
-	$(if $(CONFIG_UNWINDER_ORC), --orc)				\
-	$(if $(CONFIG_RETPOLINE), --retpoline)				\
-	$(if $(CONFIG_RETHUNK), --rethunk)				\
-	$(if $(CONFIG_SLS), --sls)					\
-	$(if $(CONFIG_STACK_VALIDATION), --stackval)			\
-	$(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call)		\
-	$(if $(CONFIG_HAVE_UACCESS_VALIDATION), --uaccess)		\
+objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK)		+= --hacks=jump_label
+objtool-args-$(CONFIG_HAVE_NOINSTR_HACK)		+= --hacks=noinstr
+objtool-args-$(CONFIG_X86_KERNEL_IBT)			+= --ibt
+objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL)	+= --mcount
+objtool-args-$(CONFIG_UNWINDER_ORC)			+= --orc
+objtool-args-$(CONFIG_RETPOLINE)			+= --retpoline
+objtool-args-$(CONFIG_RETHUNK)				+= --rethunk
+objtool-args-$(CONFIG_SLS)				+= --sls
+objtool-args-$(CONFIG_STACK_VALIDATION)			+= --stackval
+objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE)		+= --static-call
+objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION)		+= --uaccess
+objtool-args-$(CONFIG_GCOV_KERNEL)			+= --no-unreachable
+
+objtool-args = $(objtool-args-y)					\
 	$(if $(delay-objtool), --link)					\
-	$(if $(part-of-module), --module)				\
-	$(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
+	$(if $(part-of-module), --module)
 
 delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
 
-cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
+cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
 cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
 
 endif # CONFIG_OBJTOOL
scripts/Makefile.vmlinux_o +8 -9
index 81a4e0484457..df928a6717a1 100644
@@ -35,18 +35,17 @@ endif
 
 objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
 
-# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
+# Reuse objtool-args-y defined in scripts/Makefile.lib if LTO or IBT is enabled.
+# (Expand objtool-args-y to a simple variable to avoid circular reference)
 #
 # Add some more flags as needed.
-# --no-unreachable and --link might be added twice, but it is fine.
-#
-# Expand objtool_args to a simple variable to avoid circular reference.
+# --no-unreachable might be added twice, but it is fine.
+
+objtool-args-$(delay-objtool)			:= $(objtool-args-y)
+objtool-args-$(CONFIG_GCOV_KERNEL)		+= --no-unreachable
+objtool-args-$(CONFIG_NOINSTR_VALIDATION)	+= --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret))
 
-objtool_args := \
-	$(if $(delay-objtool),$(objtool_args)) \
-	$(if $(CONFIG_NOINSTR_VALIDATION), --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret)) \
-	$(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
-	--link
+objtool-args = $(objtool-args-y) --link
 
 # Link of vmlinux.o used for section mismatch analysis
 # ---------------------------------------------------------------------------
Signature · 1 line
2.34.1
#1 lore raw
Quoted 67 lines · Masahiro Yamada

Based on Linus' patch.

---

 scripts/Makefile.lib       | 31 ++++++++++++++++---------------
 scripts/Makefile.vmlinux_o | 17 ++++++++---------
 2 files changed, 24 insertions(+), 24 deletions(-)
scripts/Makefile.lib +16 -15
index b594705d571a..731f735240f8 100644
@@ -229,25 +229,26 @@ ifdef CONFIG_OBJTOOL
 
 objtool := $(objtree)/tools/objtool/objtool
 
-objtool_args =                                                         \
-       $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label)        \
-       $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr)              \
-       $(if $(CONFIG_X86_KERNEL_IBT), --ibt)                           \
-       $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)             \
-       $(if $(CONFIG_UNWINDER_ORC), --orc)                             \
-       $(if $(CONFIG_RETPOLINE), --retpoline)                          \
-       $(if $(CONFIG_RETHUNK), --rethunk)                              \
-       $(if $(CONFIG_SLS), --sls)                                      \
-       $(if $(CONFIG_STACK_VALIDATION), --stackval)                    \
-       $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call)          \
-       $(if $(CONFIG_HAVE_UACCESS_VALIDATION), --uaccess)              \
+objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK)            += --hacks=jump_label
+objtool-args-$(CONFIG_HAVE_NOINSTR_HACK)               += --hacks=noinstr
+objtool-args-$(CONFIG_X86_KERNEL_IBT)                  += --ibt
+objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL)       += --mcount
+objtool-args-$(CONFIG_UNWINDER_ORC)                    += --orc
+objtool-args-$(CONFIG_RETPOLINE)                       += --retpoline
+objtool-args-$(CONFIG_RETHUNK)                         += --rethunk
+objtool-args-$(CONFIG_SLS)                             += --sls
+objtool-args-$(CONFIG_STACK_VALIDATION)                        += --stackval
+objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE)         += --static-call
+objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION)         += --uaccess
+objtool-args-$(CONFIG_GCOV_KERNEL)                     += --no-unreachable
+
+objtool-args = $(objtool-args-y)                                       \
        $(if $(delay-objtool), --link)                                  \
-       $(if $(part-of-module), --module)                               \
-       $(if $(CONFIG_GCOV_KERNEL), --no-unreachable)
+       $(if $(part-of-module), --module)
 
 delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
 
-cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
+cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
 cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
 
 endif # CONFIG_OBJTOOL
scripts/Makefile.vmlinux_o +0 -1
index 81a4e0484457..df928a6717a1 100644
@@ -35,18 +35,17 @@ endif
 
 objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
 
-# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.

scripts/Makefile.vmlinux_o endif · line 44

Quoted 10 lines
scripts/Makefile.vmlinux_o +5 -3
+# Reuse objtool-args-y defined in scripts/Makefile.lib if LTO or IBT is enabled.
+# (Expand objtool-args-y to a simple variable to avoid circular reference)
 #
 # Add some more flags as needed.
-# --no-unreachable and --link might be added twice, but it is fine.
-#
-# Expand objtool_args to a simple variable to avoid circular reference.
+# --no-unreachable might be added twice, but it is fine.
+
+objtool-args-$(delay-objtool)                  := $(objtool-args-y)

This line is wrong. I will change like follows:

objtool-args-y := $(if $(delay-objtool), $(objtool-args-y))

Quoted 15 lines
scripts/Makefile.vmlinux_o +3 -6
+objtool-args-$(CONFIG_GCOV_KERNEL)             += --no-unreachable
+objtool-args-$(CONFIG_NOINSTR_VALIDATION)      += --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret))
 
-objtool_args := \
-       $(if $(delay-objtool),$(objtool_args)) \
-       $(if $(CONFIG_NOINSTR_VALIDATION), --noinstr $(if $(CONFIG_CPU_UNRET_ENTRY), --unret)) \
-       $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) \
-       --link
+objtool-args = $(objtool-args-y) --link
 
 # Link of vmlinux.o used for section mismatch analysis
 # ---------------------------------------------------------------------------
--

2.34.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
In reply to Masahiro Yamada
I love your patch! Yet something to improve:

Hi Masahiro,

I love your patch! Yet something to improve:

[auto build test ERROR on masahiroy-kbuild/for-next]
[also build test ERROR on linux/master linus/master v6.0-rc3 next-20220901] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Masahiro-Yamada/kbuild-use-objtool-args-y-to-clean-up-objtool-arguments/20220902-221441
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
config: x86_64-randconfig-a013 (https://download.01.org/0day-ci/archive/20220903/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/9cb92b4715f74a8869ca8ec50a8dcdc4fb5b384e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Masahiro-Yamada/kbuild-use-objtool-args-y-to-clean-up-objtool-arguments/20220902-221441
        git checkout 9cb92b4715f74a8869ca8ec50a8dcdc4fb5b384e
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable

All errors (new ones prefixed by >>):

>> /bin/bash: -c: line 1: syntax error near unexpected token `)'

/bin/bash: -c: line 1: `set -e; echo ' LD vmlinux.o'; ld -m elf_x86_64 -z noexecstack --no-warn-rwx-segments -r -o vmlinux.o --whole-archive arch/x86/kernel/head_64.o arch/x86/kernel/head64.o arch/x86/kernel/ebda.o arch/x86/kernel/platform-quirks.o init/built-in.a usr/built-in.a arch/x86/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a io_uring/built-in.a lib/built-in.a arch/x86/lib/built-in.a lib/lib.a arch/x86/lib/lib.a drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a arch/x86/pci/built-in.a arch/x86/power/built-in.a arch/x86/video/built-in.a --no-whole-archive --start-group --end-group ; ./tools/objtool/objtool --hacks=jump_label --hacks=noinstr --orc --static-call --uaccess --no-unreachable --no-unreachable --noinstr ) --link vmlinux.o; printf '%s\n' 'cmd_vmlinux.o := ld -m elf_x86_64 -z noexecstack --no-warn-rwx-segments -r -o vmlinux.o --whole-archive arch/x86/kernel/head_64.o arch/x86/kernel/head64.o arch/x86/kernel/ebda.o arch/x86/kernel/platform-quirks.o init/built-in.a usr/built-in.a arch/x86/built-in.a kernel/built-in.a certs/built-in.a mm/built-in.a fs/built-in.a ipc/built-in.a security/built-in.a crypto/built-in.a io_uring/built-in.a lib/built-in.a arch/x86/lib/built-in.a lib/lib.a arch/x86/lib/lib.a drivers/built-in.a sound/built-in.a net/built-in.a virt/built-in.a arch/x86/pci/built-in.a arch/x86/power/built-in.a arch/x86/video/built-in.a --no-whole-archive --start-group --end-group ; ./tools/objtool/objtool --hacks=jump_label --hacks=noinstr --orc --static-call --uaccess --no-unreachable --no-unreachable --noinstr ) --link vmlinux.o' > ./.vmlinux.o.cmd'

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp