LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: Sami Tolvanen <samitolvanen@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Alexander Lobakin <alobakin@pm.me>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4] kbuild: Fix TRIM_UNUSED_KSYMS with LTO_CLANG
Date: Thu, 19 Aug 2021 09:11:10 +0900	[thread overview]
Message-ID: <CAK7LNARFdB9=bV+X6nYzkrpvO-2FtOu5oxg6Ch3r=AROa1atVA@mail.gmail.com> (raw)
In-Reply-To: <CABCJKudQhagwdb-UfGE2JQN8H29NSpMd5PgVoftJYRp5ZwpRrA@mail.gmail.com>

On Thu, Aug 19, 2021 at 12:06 AM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> On Tue, Aug 17, 2021 at 7:34 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Tue, Aug 17, 2021 at 3:05 AM Sami Tolvanen <samitolvanen@google.com> wrote:
> > >
> > > With CONFIG_LTO_CLANG, we currently link modules into native
> > > code just before modpost, which means with TRIM_UNUSED_KSYMS
> > > enabled, we still look at the LLVM bitcode in the .o files when
> > > generating the list of used symbols. As the bitcode doesn't
> > > yet have calls to compiler intrinsics and llvm-nm doesn't see
> > > function references that only exist in function-level inline
> > > assembly, we currently need a whitelist for TRIM_UNUSED_KSYMS to
> > > work with LTO.
> > >
> > > This change moves module LTO linking to happen earlier, and
> > > thus avoids the issue with LLVM bitcode and TRIM_UNUSED_KSYMS
> > > entirely, allowing us to also drop the whitelist from
> > > gen_autoksyms.sh.
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1369
> > > Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> > > Reviewed-by: Alexander Lobakin <alobakin@pm.me>
> > > Tested-by: Alexander Lobakin <alobakin@pm.me>
> > > ---
> > > Changes in v4:
> > > - Added .lto.o to targets to actually fix the use of if_changed.
> > > - Replaced an unnecessary mod-prelink-ext with .lto.
> > >
> > > Changes in v3:
> > > - Added missing FORCE.
> > >
> > > Changes in v2:
> > > - Fixed a couple of typos.
> > > - Fixed objtool arguments for .lto.o to always include --module.
> > >
> > > ---
> > >  scripts/Makefile.build    | 28 +++++++++++++++++++++++++++-
> > >  scripts/Makefile.lib      |  7 +++++++
> > >  scripts/Makefile.modfinal | 21 ++-------------------
> > >  scripts/Makefile.modpost  | 22 +++-------------------
> > >  scripts/gen_autoksyms.sh  | 12 ------------
> > >  5 files changed, 39 insertions(+), 51 deletions(-)
> > >
> > > diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> > > index 02197cb8e3a7..a6f43afd09bb 100644
> > > --- a/scripts/Makefile.build
> > > +++ b/scripts/Makefile.build
> > > @@ -88,6 +88,10 @@ endif
> > >
> > >  targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
> > >
> > > +ifdef CONFIG_LTO_CLANG
> > > +targets-for-modules += $(patsubst %.o, %.lto.o, $(filter %.o, $(obj-m)))
> > > +endif
> > > +
> > >  ifdef need-modorder
> > >  targets-for-modules += $(obj)/modules.order
> > >  endif
> > > @@ -271,12 +275,34 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $$(objtool_dep) FORCE
> > >         $(call if_changed_rule,cc_o_c)
> > >         $(call cmd,force_checksrc)
> > >
> > > +ifdef CONFIG_LTO_CLANG
> > > +# Module .o files may contain LLVM bitcode, compile them into native code
> > > +# before ELF processing
> > > +quiet_cmd_cc_lto_link_modules = LTO [M] $@
> > > +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,$^)
> > > +
> > > +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 += ;                                           \
> > > +       $(objtree)/tools/objtool/objtool $(objtool_args) --module       \
> > > +               $(@:.ko=.lto.o)
> >
> >
> > What is this "$(@:.ko=.lto.o)" doing ?
> >
> > The target is already suffixed with .lto.o
> > so $(@:.ko=.lto.o) should be the same as $@
>
> Good catch, probably a leftover from an earlier iteration.
>
> > Shall I fix it locally unless
> > I find more questionable code?
>
> Please do.
>
> Sami


Applied with $(@:.ko=.lto.o)  ->  $@

Thanks.


-- 
Best Regards
Masahiro Yamada

      reply	other threads:[~2021-08-19  0:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-16 18:05 Sami Tolvanen
2021-08-18  2:33 ` Masahiro Yamada
2021-08-18 15:06   ` Sami Tolvanen
2021-08-19  0:11     ` Masahiro Yamada [this message]

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='CAK7LNARFdB9=bV+X6nYzkrpvO-2FtOu5oxg6Ch3r=AROa1atVA@mail.gmail.com' \
    --to=masahiroy@kernel.org \
    --cc=alobakin@pm.me \
    --cc=clang-built-linux@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=samitolvanen@google.com \
    --subject='Re: [PATCH v4] kbuild: Fix TRIM_UNUSED_KSYMS with LTO_CLANG' \
    /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

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).