From: Kees Cook <keescook@chromium.org>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-kbuild@vger.kernel.org,
Michal Marek <michal.lkml@markovi.net>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 06/13] kbuild: reuse $(cmd_objtool) for cmd_cc_lto_link_modules
Date: Tue, 31 Aug 2021 10:35:29 -0700 [thread overview]
Message-ID: <202108311034.D4B1410@keescook> (raw)
In-Reply-To: <20210831074004.3195284-7-masahiroy@kernel.org>
On Tue, Aug 31, 2021 at 04:39:57PM +0900, Masahiro Yamada wrote:
> For CONFIG_LTO_CLANG=y, the objtool processing is not possible at the
> compilation, hence postponed by the link time.
>
> Reuse $(cmd_objtool) for CONFIG_LTO_CLANG=y by defining objtool-enabled
> properly.
>
> For CONFIG_LTO_CLANG=y:
>
> objtool-enabled is off for %.o compilation
> objtool-enabled is on for %.lto link
>
> For CONFIG_LTO_CLANG=n:
>
> objtool-enabled is on for %.o compilation
> (but, it depends on OBJECT_FILE_NON_STANDARD)
>
> Set part-of-module := y for %.lto.o to avoid repeating --module.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
> scripts/Makefile.build | 28 +++++++++++++++++-----------
> 1 file changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 21b55f37a23f..afc906cd7256 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -236,20 +236,26 @@ objtool_args = \
> $(if $(CONFIG_X86_SMAP), --uaccess) \
> $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)
>
> -ifndef CONFIG_LTO_CLANG
> +cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
> +cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
> +
> +endif # CONFIG_STACK_VALIDATION
> +
> +ifdef CONFIG_LTO_CLANG
> +
> +# Skip objtool for LLVM bitcode
> +$(obj)/%o: objtool-enabled :=
Is this intentionally "%o" instead of "%.o"? (And it later overridden by
the "%.lto.o" rule?
> +
> +else
>
> # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
> # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
> # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>
> -objtool-enabled = $(if $(filter-out y%, \
> +$(obj)/%o: objtool-enabled = $(if $(filter-out y%, \
> $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
>
> -cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@)
> -cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
> -
> -endif # CONFIG_LTO_CLANG
> -endif # CONFIG_STACK_VALIDATION
> +endif
>
> ifdef CONFIG_TRIM_UNUSED_KSYMS
> cmd_gen_ksymdeps = \
> @@ -289,13 +295,13 @@ cmd_cc_lto_link_modules = \
> $(LD) $(ld_flags) -r -o $@ \
> $(shell [ -s $(@:.lto.o=.o.symversions) ] && \
> echo -T $(@:.lto.o=.o.symversions)) \
> - --whole-archive $(filter-out FORCE,$^)
> + --whole-archive $(filter-out FORCE,$^) \
> + $(cmd_objtool)
>
> -ifdef CONFIG_STACK_VALIDATION
> # objtool was skipped for LLVM bitcode, run it now that we have compiled
> # modules into native code
> -cmd_cc_lto_link_modules += ; $(objtool) $(objtool_args) --module $@
> -endif
> +$(obj)/%.lto.o: objtool-enabled = y
> +$(obj)/%.lto.o: part-of-module := y
>
> $(obj)/%.lto.o: $(obj)/%.o FORCE
> $(call if_changed,cc_lto_link_modules)
> --
> 2.30.2
>
--
Kees Cook
next prev parent reply other threads:[~2021-08-31 17:35 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 7:39 [PATCH v2 00/13] kbuild: second round of Clang LTO refactoring Masahiro Yamada
2021-08-31 7:39 ` [PATCH v2 01/13] kbuild: move objtool_args back to scripts/Makefile.build Masahiro Yamada
2021-09-04 18:18 ` Josh Poimboeuf
2021-08-31 7:39 ` [PATCH v2 02/13] kbuild: rename __objtool_obj to objtool Masahiro Yamada
2021-08-31 17:16 ` Nick Desaulniers
2021-08-31 17:29 ` Kees Cook
2021-09-04 18:19 ` Josh Poimboeuf
2021-08-31 7:39 ` [PATCH v2 03/13] kbuild: store the objtool command in *.cmd files Masahiro Yamada
2021-08-31 17:23 ` Nick Desaulniers
2021-08-31 17:30 ` Kees Cook
2021-09-04 18:04 ` Josh Poimboeuf
2021-09-04 18:45 ` Josh Poimboeuf
2021-09-08 16:12 ` Masahiro Yamada
2021-08-31 7:39 ` [PATCH v2 04/13] kbuild: factor out OBJECT_FILES_NON_STANDARD check into a macro Masahiro Yamada
2021-08-31 17:25 ` Nick Desaulniers
2021-08-31 17:31 ` Kees Cook
2021-09-04 18:59 ` Josh Poimboeuf
2021-08-31 7:39 ` [PATCH v2 05/13] kbuild: detect objtool update without using .SECONDEXPANSION Masahiro Yamada
2021-08-31 17:32 ` Kees Cook
2021-09-03 0:43 ` Masahiro Yamada
2021-08-31 17:33 ` Nick Desaulniers
2021-09-02 23:42 ` Masahiro Yamada
2021-09-04 19:04 ` Josh Poimboeuf
2021-08-31 7:39 ` [PATCH v2 06/13] kbuild: reuse $(cmd_objtool) for cmd_cc_lto_link_modules Masahiro Yamada
2021-08-31 17:35 ` Kees Cook [this message]
2021-09-03 0:39 ` Masahiro Yamada
2021-09-03 1:49 ` Kees Cook
2021-09-04 19:11 ` Josh Poimboeuf
2021-08-31 7:39 ` [PATCH v2 07/13] kbuild: do not create built-in.a.symversions or lib.a.symversions Masahiro Yamada
2021-08-31 17:36 ` Kees Cook
2021-08-31 7:39 ` [PATCH v2 08/13] kbuild: build modules in the same way with/without Clang LTO Masahiro Yamada
2021-08-31 17:39 ` Kees Cook
2021-08-31 17:46 ` Nick Desaulniers
2021-08-31 7:40 ` [PATCH v2 09/13] kbuild: add cmd_and_savecmd macro Masahiro Yamada
2021-08-31 17:39 ` Kees Cook
2021-08-31 7:40 ` [PATCH v2 10/13] kbuild: rebuild modules when objtool is updated for CONFIG_LTO_CLANG Masahiro Yamada
2021-08-31 17:40 ` Kees Cook
2021-09-04 19:13 ` Josh Poimboeuf
2021-08-31 7:40 ` [PATCH v2 11/13] kbuild: always postpone CRC links for module versioning Masahiro Yamada
2021-08-31 7:40 ` [PATCH v2 12/13] kbuild: merge cmd_modversions_c and cmd_modversions_S Masahiro Yamada
2021-08-31 7:40 ` [PATCH v2 13/13] kbuild: merge cmd_ar_builtin and cmd_ar_module Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202108311034.D4B1410@keescook \
--to=keescook@chromium.org \
--cc=clang-built-linux@googlegroups.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=michal.lkml@markovi.net \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).