diff mbox series

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

Message ID 20220902130846.654526-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series kbuild: use objtool-args-y to clean up objtool arguments | expand

Commit Message

Masahiro Yamada Sept. 2, 2022, 1:08 p.m. UTC
Based on Linus' patch.

Link: https://lore.kernel.org/lkml/CAHk-=wgjTMQgiKzBZTmb=uWGDEQxDdyF1+qxBkODYciuNsmwnw@mail.gmail.com/
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.lib       | 31 ++++++++++++++++---------------
 scripts/Makefile.vmlinux_o | 17 ++++++++---------
 2 files changed, 24 insertions(+), 24 deletions(-)

Comments

Masahiro Yamada Sept. 3, 2022, 1:11 a.m. UTC | #1
On Fri, Sep 2, 2022 at 10:11 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Based on Linus' patch.
>
> Link: https://lore.kernel.org/lkml/CAHk-=wgjTMQgiKzBZTmb=uWGDEQxDdyF1+qxBkODYciuNsmwnw@mail.gmail.com/
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
>  scripts/Makefile.lib       | 31 ++++++++++++++++---------------
>  scripts/Makefile.vmlinux_o | 17 ++++++++---------
>  2 files changed, 24 insertions(+), 24 deletions(-)
>
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index b594705d571a..731f735240f8 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -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
> diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o
> index 81a4e0484457..df928a6717a1 100644
> --- a/scripts/Makefile.vmlinux_o
> +++ b/scripts/Makefile.vmlinux_o
> @@ -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)

This line is wrong. I will change like follows:

objtool-args-y    := $(if $(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
>  # ---------------------------------------------------------------------------
> --
> 2.34.1
>
kernel test robot Sept. 3, 2022, 2:36 a.m. UTC | #2
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/202209031000.bJCDq6zH-lkp@intel.com/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
Reported-by: kernel test robot <lkp@intel.com>

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'
Peter Zijlstra Sept. 6, 2022, 8:11 p.m. UTC | #3
On Fri, Sep 02, 2022 at 10:08:45PM +0900, Masahiro Yamada wrote:
> Based on Linus' patch.
> 
> Link: https://lore.kernel.org/lkml/CAHk-=wgjTMQgiKzBZTmb=uWGDEQxDdyF1+qxBkODYciuNsmwnw@mail.gmail.com/
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Ack on the version that works ;-)
diff mbox series

Patch

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index b594705d571a..731f735240f8 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -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
diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o
index 81a4e0484457..df928a6717a1 100644
--- a/scripts/Makefile.vmlinux_o
+++ b/scripts/Makefile.vmlinux_o
@@ -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
 # ---------------------------------------------------------------------------