public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,
	gcc-patches@gcc.gnu.org, keescook@chromium.org,
	 Jakub Jelinek <jakub@redhat.com>,
	Richard Biener <rguenther@suse.de>,
	 Hou Wenlong <houwenlong.hwl@antgroup.com>
Subject: Re: [PATCH] i386: Honour -mdirect-extern-access when calling __fentry__
Date: Fri, 12 May 2023 16:07:23 +0200	[thread overview]
Message-ID: <CAMj1kXGPN4YpDZvPsULBrG-YRaGFOrxmU=kz07GM2c7NhUgn1g@mail.gmail.com> (raw)
In-Reply-To: <CAFULd4a=7D9kSmdPG8TOhwNPv9=k5z8ytLyXUqDox8UyZw1T+A@mail.gmail.com>

On Thu, 11 May 2023 at 08:08, Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Thu, May 11, 2023 at 12:04 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Wed, May 10, 2023 at 2:17 AM Uros Bizjak <ubizjak@gmail.com> wrote:
> > >
> > > On Tue, May 9, 2023 at 10:58 AM Ard Biesheuvel <ardb@kernel.org> wrote:
> > > >
> > > > The small and medium PIC code models generate profiling calls that
> > > > always load the address of __fentry__() via the GOT, even if
> > > > -mdirect-extern-access is in effect.
> > > >
> > > > This deviates from the behavior with respect to other external
> > > > references, and results in a longer opcode that relies on linker
> > > > relaxation to eliminate the GOT load. In this particular case, the
> > > > transformation replaces an indirect 'CALL *__fentry__@GOTPCREL(%rip)'
> > > > with either 'CALL __fentry__; NOP' or 'NOP; CALL __fentry__', where the
> > > > NOP is a 1 byte NOP that preserves the 6 byte length of the sequence.
> > > >
> > > > This is problematic for the Linux kernel, which generally relies on
> > > > -mdirect-extern-access and hidden visibility to eliminate GOT based
> > > > symbol references in code generated with -fpie/-fpic, without having to
> > > > depend on linker relaxation.
> > > >
> > > > The Linux kernel relies on code patching to replace these opcodes with
> > > > NOPs at runtime, and this is complicated code that we'd prefer not to
> > > > complicate even more by adding support for patching both 5 and 6 byte
> > > > sequences as well as parsing the instruction stream to decide which
> > > > variant of CALL+NOP we are dealing with.
> > > >
> > > > So let's honour -mdirect-extern-access, and only load the address of
> > > > __fentry__ via the GOT if direct references to external symbols are not
> > > > permitted.
> > > >
> > > > Note that the GOT reference in question is in fact a data reference: we
> > > > explicitly load the address of __fentry__ from the GOT, which amounts to
> > > > eager binding, rather than emitting a PLT call that could bind eagerly,
> > > > lazily or directly at link time.
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > >         * config/i386/i386.cc (x86_function_profiler): Take
> > > >           ix86_direct_extern_access into account when generating calls
> > > >           to __fentry__()
> > >
> > > HJ, is the patch OK with you?
> >
> > LGTM.
>
> OK then.
>

Thanks all. Is anything expected of me at this point?

  reply	other threads:[~2023-05-12 14:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09  8:58 Ard Biesheuvel
2023-05-10  9:16 ` Uros Bizjak
2023-05-10 22:03   ` H.J. Lu
2023-05-11  6:08     ` Uros Bizjak
2023-05-12 14:07       ` Ard Biesheuvel [this message]
2023-05-12 17:05         ` Uros Bizjak
2023-05-12 21:56           ` Ard Biesheuvel

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='CAMj1kXGPN4YpDZvPsULBrG-YRaGFOrxmU=kz07GM2c7NhUgn1g@mail.gmail.com' \
    --to=ardb@kernel.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=houwenlong.hwl@antgroup.com \
    --cc=jakub@redhat.com \
    --cc=keescook@chromium.org \
    --cc=rguenther@suse.de \
    --cc=ubizjak@gmail.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 read-only IMAP folder(s) and NNTP newsgroup(s).