scripts/Makefile.lib | 31 ++++++++++++++++--------------- scripts/Makefile.vmlinux_o | 15 ++++----------- 2 files changed, 20 insertions(+), 26 deletions(-)
Based on Linus' patch. Refactor scripts/Makefile.vmlinux_o as well.
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>
---
Changes in v2:
- bug fix
scripts/Makefile.lib | 31 ++++++++++++++++---------------
scripts/Makefile.vmlinux_o | 15 ++++-----------
2 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 9bdc9ed37f49..3392721e1355 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -231,25 +231,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..68c22879bade 100644
--- a/scripts/Makefile.vmlinux_o
+++ b/scripts/Makefile.vmlinux_o
@@ -35,18 +35,11 @@ endif
objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
-# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
-#
-# 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.
+vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y)
+vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
+vmlinux-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 = $(vmlinux-objtool-args-y) --link
# Link of vmlinux.o used for section mismatch analysis
# ---------------------------------------------------------------------------
--
2.34.1
On Tue, Sep 6, 2022 at 11:50 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Based on Linus' patch. Refactor scripts/Makefile.vmlinux_o as well.
>
> 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>
Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>
> Changes in v2:
> - bug fix
>
> scripts/Makefile.lib | 31 ++++++++++++++++---------------
> scripts/Makefile.vmlinux_o | 15 ++++-----------
> 2 files changed, 20 insertions(+), 26 deletions(-)
>
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 9bdc9ed37f49..3392721e1355 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -231,25 +231,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..68c22879bade 100644
> --- a/scripts/Makefile.vmlinux_o
> +++ b/scripts/Makefile.vmlinux_o
> @@ -35,18 +35,11 @@ endif
>
> objtool-enabled := $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION))
>
> -# Reuse objtool_args defined in scripts/Makefile.lib if LTO or IBT is enabled.
> -#
> -# 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.
> +vmlinux-objtool-args-$(delay-objtool) += $(objtool-args-y)
> +vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
> +vmlinux-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 = $(vmlinux-objtool-args-y) --link
>
> # Link of vmlinux.o used for section mismatch analysis
> # ---------------------------------------------------------------------------
> --
> 2.34.1
>
--
Thanks,
~Nick Desaulniers
© 2016 - 2026 Red Hat, Inc.