All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fāng-ruì Sòng" <maskray@google.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Arnd Bergmann <arnd@arndb.de>, X86 ML <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Nathan Chancellor <natechancellor@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH v3] x86/entry: emit a symbol for register restoring thunk
Date: Mon, 11 Jan 2021 14:16:52 -0800	[thread overview]
Message-ID: <CAFP8O3+KBi5beri4rzor8NrwxVej2SFF-dxOQX0OTBLXJ5engg@mail.gmail.com> (raw)
In-Reply-To: <20210111220909.2wexjehwiria7jem@treble>

On Mon, Jan 11, 2021 at 2:09 PM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> On Mon, Jan 11, 2021 at 12:58:14PM -0800, Fangrui Song wrote:
> > On 2021-01-11, Nick Desaulniers wrote:
> > > Arnd found a randconfig that produces the warning:
> > >
> > > arch/x86/entry/thunk_64.o: warning: objtool: missing symbol for insn at
> > > offset 0x3e
> > >
> > > when building with LLVM_IAS=1 (use Clang's integrated assembler). Josh
> > > notes:
> > >
> > >  With the LLVM assembler stripping the .text section symbol, objtool
> > >  has no way to reference this code when it generates ORC unwinder
> > >  entries, because this code is outside of any ELF function.
> > >
> > > Fangrui notes that this optimization is helpful for reducing images size
> > > when compiling with -ffunction-sections and -fdata-sections. I have
> > > observerd on the order of tens of thousands of symbols for the kernel
> > > images built with those flags. A patch has been authored against GNU
> > > binutils to match this behavior, with a new flag
> > > --generate-unused-section-symbols=[yes|no].
> >
> > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d1bcae833b32f1408485ce69f844dcd7ded093a8
> > has been committed. The patch should be included in binutils 2.37.
> > The maintainers are welcome to the idea, but fixing all the arch-specific tests is tricky.
> >
> > H.J. fixed the x86 tests and enabled this for x86. When binutils 2.37
> > come out, some other architectures may follow as well.
> >
> > > We can omit the .L prefix on a label to emit an entry into the symbol
> > > table for the label, with STB_LOCAL binding.  This enables objtool to
> > > generate proper unwind info here with LLVM_IAS=1.
> >
> > Josh, I think objtool orc generate needs to synthesize STT_SECTION
> > symbols even if they do not exist in object files.
>
> I'm guessing you don't mean re-adding *all* missing STT_SECTIONs, as
> that would just be undoing these new assembler features.
>
> We could re-add STT_SECTION only when there's no other corresponding
> symbol associated with the code, but then objtool would have to start
> updating the symbol table (which right now it manages to completely
> avoid).  But that would only be for the niche cases, like
> 'SYM_CODE.*\.L' as you mentioned.
>
> I'd rather avoid making doing something so pervasive for such a small
> number of edge cases.  It's hopefully easier and more robust to just say
> "all code must be associated with a symbol".  I suspect we're already
> ~99.99% there anyway.
>
>   $ git grep -e 'SYM_CODE.*\.L'
>   arch/x86/entry/entry_64.S:SYM_CODE_START_LOCAL_NOALIGN(.Lbad_gs)
>   arch/x86/entry/entry_64.S:SYM_CODE_END(.Lbad_gs)
>   arch/x86/entry/thunk_64.S:SYM_CODE_START_LOCAL_NOALIGN(.L_restore)
>   arch/x86/entry/thunk_64.S:SYM_CODE_END(.L_restore)
>   arch/x86/lib/copy_user_64.S:SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail)
>   arch/x86/lib/copy_user_64.S:SYM_CODE_END(.Lcopy_user_handle_tail)
>   arch/x86/lib/getuser.S:SYM_CODE_START_LOCAL(.Lbad_get_user_clac)
>   arch/x86/lib/getuser.S:SYM_CODE_END(.Lbad_get_user_clac)
>   arch/x86/lib/getuser.S:SYM_CODE_START_LOCAL(.Lbad_get_user_8_clac)
>   arch/x86/lib/getuser.S:SYM_CODE_END(.Lbad_get_user_8_clac)
>   arch/x86/lib/putuser.S:SYM_CODE_START_LOCAL(.Lbad_put_user_clac)
>   arch/x86/lib/putuser.S:SYM_CODE_END(.Lbad_put_user_clac)

I'd prefer that the assembly can continue using .L and does not know
the objtool limitation.
Assemblers normally drop .L symbols. These symbols are otherwise not useful.

However, if as you said, teaching objtool about synthesizing
STT_SECTION from section header table is difficult,
this patch looks fine to me.

Reviewed-by: Fangrui Song <maskray@google.com>

> Alternatively, the assemblers could add an option to only strip
> -ffunction-sections and -fdata-sections STT_SECTION symbols, e.g. leave
> ".text" and friends alone.

I forgot to mention that --generate-unused-section-symbols=[yes|no] is
not added to GNU as.
Making the assembler behavior dependent on -ffunction-sections is not
an option in both LLVM integrated assembler and GNU as.

  reply	other threads:[~2021-01-11 22:18 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23 23:21 [PATCH] x86/entry: use STB_GLOBAL for register restoring thunk Nick Desaulniers
2020-12-24  4:55 ` Josh Poimboeuf
2021-01-06  0:43   ` [PATCH v2] " Nick Desaulniers
2021-01-06  1:58     ` Josh Poimboeuf
2021-01-11 20:38       ` [PATCH v3] x86/entry: emit a symbol " Nick Desaulniers
2021-01-11 20:58         ` Fangrui Song
2021-01-11 22:09           ` Josh Poimboeuf
2021-01-11 22:16             ` Fāng-ruì Sòng [this message]
2021-01-11 22:12         ` Josh Poimboeuf
2021-01-12  0:38         ` Borislav Petkov
2021-01-12  0:41           ` Fāng-ruì Sòng
2021-01-12  1:00             ` Borislav Petkov
2021-01-12  1:13               ` Nick Desaulniers
2021-01-12  1:59                 ` Josh Poimboeuf
2021-01-12 11:54                   ` Borislav Petkov
2021-01-12 19:46                     ` [PATCH v4] " Nick Desaulniers
2021-01-12 21:01                       ` Mark Brown
2021-01-13 16:59                         ` Josh Poimboeuf
2021-01-13 17:46                           ` [PATCH] Documentation: asm-annotation: clarify .L local symbol names Nick Desaulniers
2021-01-13 19:56                             ` Mark Brown
2021-01-13 17:56                           ` [PATCH v4] x86/entry: emit a symbol for register restoring thunk Nick Desaulniers
2021-01-14 10:39                             ` Borislav Petkov
2021-01-14 11:36                               ` Peter Zijlstra
2021-01-14 13:28                                 ` [PATCH] x86/entry: Remove put_ret_addr_in_rdi THUNK macro argument Borislav Petkov
2021-01-14 15:53                                   ` Peter Zijlstra
2021-01-19 10:12                                 ` [tip: x86/entry] " tip-bot2 for Borislav Petkov
2021-01-14 15:14                               ` [PATCH v4] x86/entry: emit a symbol for register restoring thunk Josh Poimboeuf
2021-01-14 11:49                         ` [Linux-kernel-mentees] Fwd: " Lukas Bulwahn
2021-01-14 14:21                           ` Aditya
2021-01-14 14:35                             ` Lukas Bulwahn
2021-01-13 11:52                       ` [tip: x86/entry] x86/entry: Emit " tip-bot2 for Nick Desaulniers
2021-01-19 10:12                       ` tip-bot2 for Nick Desaulniers
2021-01-12 11:47                 ` [PATCH v3] x86/entry: emit " Borislav Petkov

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=CAFP8O3+KBi5beri4rzor8NrwxVej2SFF-dxOQX0OTBLXJ5engg@mail.gmail.com \
    --to=maskray@google.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=natechancellor@gmail.com \
    --cc=ndesaulniers@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.