public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] x86-64: Add -z mark-plt and -z nomark-plt
Date: Wed, 27 Sep 2023 10:17:32 -0700	[thread overview]
Message-ID: <CAMe9rOora-ryS1Gdfrbkxyj51s1wXWWFAC+JaS5d9=P1J-BSwA@mail.gmail.com> (raw)
In-Reply-To: <86209ea1-7ae7-b14a-3a26-c9454caf5c32@suse.com>

On Tue, Sep 26, 2023 at 11:56 PM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 26.09.2023 18:13, H.J. Lu via Binutils wrote:
> > The PLT entry in executables and shared libraries contains an indirect
> > branch, like
> >
> >       jmp *foo@GOTPCREL(%rip)
> >       push $index_foo
> >       jmp .PLT0
> >
> > or
> >
> >       endbr64
> >       jmp *foo@GOTPCREL(%rip)
> >       NOP padding
> >
> > which is used to branch to the function, foo, defined in another object.
> > Each R_X86_64_JUMP_SLOT relocation has a corresponding PLT entry.
> >
> > The dynamic tags have been added to the x86-64 psABI to mark such PLT
> > entries:
> >
> > https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/6d824a52a42d173eb838b879616c1be5870b593e
> >
> > Add an x86-64 linker option, -z mark-plt, to mark PLT entries with
> >
> >  #define DT_X86_64_PLT     (DT_LOPROC + 0)
> >  #define DT_X86_64_PLTSZ   (DT_LOPROC + 1)
> >  #define DT_X86_64_PLTENT  (DT_LOPROC + 3)
> >
> > 1. DT_X86_64_PLT: The address of the procedure linkage table.
> > 2. DT_X86_64_PLTSZ: The total size, in bytes, of the procedure linkage
> > table.
> > 3. DT_X86_64_PLTENT: The size, in bytes, of a procedure linkage table
> > entry.
> >
> > and set the r_addend field of the R_X86_64_JUMP_SLOT relocation to the
> > memory offset of the indirect branch instruction.  The dynamic linker
> > can use these tags to update the PLT section to direct branch.
> >
> > bfd/
> >
> >       * elf-linker-x86.h (elf_linker_x86_params): Add mark_plt.
> >       * elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Set the
> >       r_addend of R_X86_64_JUMP_SLOT to the indirect branch offset
> >       in PLT entry for -z mark-plt.
> >       * elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Add
> >       DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT for
> >       -z mark-plt.
> >       (_bfd_x86_elf_finish_dynamic_sections): Set DT_X86_64_PLT,
> >       DT_X86_64_PLTSZ and DT_X86_64_PLTENT.
> >       (_bfd_x86_elf_get_synthetic_symtab): Ignore addend for
> >       JUMP_SLOT relocation.
> >       (_bfd_x86_elf_link_setup_gnu_properties): Set
> >       plt_indirect_branch_offset.
> >       * elfxx-x86.h (elf_x86_plt_layout): Add plt_indirect_branch_offset.
> >
> > binutils/
> >
> >       * readelf.c (get_x86_64_dynamic_type): New function.
> >       (get_dynamic_type): Call get_x86_64_dynamic_type.
> >
> > include/
> >
> >       * elf/x86-64.h (DT_X86_64_PLT): New.
> >       (DT_X86_64_PLTSZ): Likewise.
> >       (DT_X86_64_PLTENT): Likewise.
> >
> > ld/
> >       * emulparams/elf32_x86_64.sh: Source x86-64-plt.sh.
> >       * emulparams/elf_x86_64.sh: Likewise.
> >       * emulparams/x86-64-plt.sh: New file.
> >       * testsuite/ld-x86-64/mark-plt-1.s: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1a-x32.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1a.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1b-x32.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1b.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1c-x32.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1c.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1d-x32.d: Likewise.
> >       * testsuite/ld-x86-64/mark-plt-1d.d: Likewise.
> >       * testsuite/ld-x86-64/x86-64.exp: Run -z mark-plt tests.
>
> Don't you also want to add text to ld.texi? There it would also be made

Will fix it in v2.

> clear what the default setting is ("off" aiui). A related question would
> be whether it would make sense to allow configure time selection of the
> default.
>

Since glibc versions without

commit f8587a61892cbafd98ce599131bf4f103466f084
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri May 20 19:21:48 2022 -0700

    x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT

    According to x86-64 psABI, r_addend should be ignored for R_X86_64_GLOB_DAT
    and R_X86_64_JUMP_SLOT.  Since linkers always set their r_addends to 0, we
    can ignore their r_addends.

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

won't ignore the r_addend value in the R_X86_64_JUMP_SLOT relocation.

making -z mark-plt the default may cause run-time issues for older versions
of glibc.

-- 
H.J.

      reply	other threads:[~2023-09-27 17:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26 16:13 H.J. Lu
2023-09-27  6:56 ` Jan Beulich
2023-09-27 17:17   ` H.J. Lu [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='CAMe9rOora-ryS1Gdfrbkxyj51s1wXWWFAC+JaS5d9=P1J-BSwA@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.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).