unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
To: "Fāng-ruì Sòng" <maskray@google.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH v2 3/3] configure: Allow LD to be LLD 13.0.0 or above [BZ #26558]
Date: Sat, 7 Aug 2021 06:15:21 -0700	[thread overview]
Message-ID: <CAMe9rOrMpTS6zmYe3Txp=u4iG3tdaoh2f6xuF-jcGeBXG5omMQ@mail.gmail.com> (raw)
In-Reply-To: <20210807004759.7rskhwijvxaoaoja@google.com>

On Fri, Aug 6, 2021 at 5:48 PM Fāng-ruì Sòng <maskray@google.com> wrote:
>
> On 2021-08-05, H.J. Lu wrote:
> >On Thu, Aug 5, 2021 at 9:43 AM Fāng-ruì Sòng <maskray@google.com> wrote:
> >>
> >> On Thu, Aug 5, 2021 at 9:34 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >> >
> >> > On Thu, Aug 5, 2021 at 9:29 AM Fangrui Song via Libc-alpha
> >> > <libc-alpha@sourceware.org> wrote:
> >> > >
> >> > > When using LLD (LLVM linker) as the linker, configure prints a confusing
> >> > > message.
> >> > >
> >> > >     *** These critical programs are missing or too old: GNU ld
> >> > >
> >> > > LLD>=13.0.0 can build glibc --enable-static-pie. (8.0.0 needs one
> >> > > workaround for -Wl,-defsym=_begin=0. 9.0.0 works with
> >> > > --disable-static-pie).
> >> > >
> >> > > With BZ #28153 (glibc bug exposed by testing with LLD) fixed,
> >> > > `make check` only has 2 more failures with LLD than with GNU ld:
> >> > > BZ #28154 (LLD follows the PowerPC port of GNU ld for ifunc by
> >> > > placing IRELATIVE relocations in .rela.dyn).
> >> >
> >> > This is an lld bug, similar to:
> >> >
> >> > https://sourceware.org/bugzilla/show_bug.cgi?id=13302
> >> >
> >> > Please fix it at least on x86.
> >>
> >> I am afraid that I disagree. The PowerPC port of GNU ld does the right
> >
> >This is just one opinion and it doesn't make it "the right thing".
> >
> >> thing and LLD follows suit.
> >> R_*_IRELATIVE relocations should be eagerly resolved, so they belong
> >> to .rela.dyn instead of .rela.plt.
> >
> >Ulrich and I designed/implemented IFUNC on x86 and for x86.  I consider
> >x86 implementation of IFUC as the gold standard.
>
> kib from FreeBSD said
>
> "FreeBSD rtld does the initial pass over the plt relocations and handles
> R_X86_64_JMP_SLOT only, If there are any R_X86_64_IRELATIVE relocks, we
> mark the object as having such relocations. Then, we do the ireloc
> processing, using the depth-first descend. We handle all IRELOCs for
> dependent objects before doing it for dependee. There, we iterate over
> all plt relocs to select IRELOCs."
>
> I pondered at this comment
>
> /*
>   * The handling of R_MACHINE_IRELATIVE relocations and jumpslots
>   * referencing STT_GNU_IFUNC symbols is postponed till the other
>   * relocations are done.  The indirect functions specified as
>   * ifunc are allowed to call other symbols, so we need to have
>   * objects relocated before asking for resolution from indirects.
>   *
>   * The R_MACHINE_IRELATIVE slots are resolved in greedy fashion,
>   * instead of the usual lazy handling of PLT slots.  It is
>   * consistent with how GNU does it.
>   */
>
> and re-read https://sourceware.org/glibc/wiki/GNU_IFUNC
>
> "This may work on x86_64 where the R_*_IRELATIVE relocations happen in
> DT_JMPREL after the DT_REL* relocations, but that is no guarantee that it will
> work on AArch64, PPC64, or other architectures that are slightly different.
> Such fundamental limitations may be lifted at a future point."
>
> I think adopting the FreeBSD approach can make IRELATIVE more robust, even for
> x86. IRELATIVE is still eager resolved, just postponed after other relocations.
> Fixing this property in glibc will improve rubustness/flexibility of ifunc
> resolvers and freeing linkers the responsibility to order IRELATIVE in a
> particular position.
>
> Pioneering on one feature gives the designer respect, yet the designer can only
> earn authority by demonstrating the consideration of all sort of implication.
>

On Linux/x86, lld is incompatible with ld.so on this particular IFUNC feature.
We have 3 choices:

1. Ignore it.  But it means that if lld is used to build glibc, we don't know if
this feature works or not.
2. Change glibc to make it compatible with lld.
3. Change lld to make it compatible with glibc.

The FreeBSD scheme is not wrong.  But it is a workaround in glibc
for a linker bug unless it also fixes other IFUNC issues on Linux/x86.

-- 
H.J.

  reply	other threads:[~2021-08-07 13:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05 16:25 [PATCH v2 0/3] Allow LLD 13.0.0 and improve compatibility with gold and clang Fangrui Song via Libc-alpha
2021-08-05 16:25 ` [PATCH v2 1/3] elf: Replace .tls_common with .tbss definition [BZ #28152] Fangrui Song via Libc-alpha
2021-08-05 16:26 ` [PATCH v2 2/3] elf: Skip tst-auditlogmod-* if the linker doesn't support --depaudit [BZ #28151] Fangrui Song via Libc-alpha
2021-08-16  4:59   ` Fāng-ruì Sòng via Libc-alpha
2021-08-24  3:56     ` Fāng-ruì Sòng via Libc-alpha
2021-08-24 12:04   ` Adhemerval Zanella via Libc-alpha
2021-08-05 16:26 ` [PATCH v2 3/3] configure: Allow LD to be LLD 13.0.0 or above [BZ #26558] Fangrui Song via Libc-alpha
2021-08-05 16:34   ` H.J. Lu via Libc-alpha
2021-08-05 16:43     ` Fāng-ruì Sòng via Libc-alpha
2021-08-05 17:04       ` H.J. Lu via Libc-alpha
2021-08-07  0:47         ` Fāng-ruì Sòng via Libc-alpha
2021-08-07 13:15           ` H.J. Lu via Libc-alpha [this message]
2021-08-08  4:17             ` Fāng-ruì Sòng via Libc-alpha
2021-08-09 17:58               ` H.J. Lu via Libc-alpha
2021-08-09 19:58                 ` Fāng-ruì Sòng via Libc-alpha
2021-08-10 14:38                   ` H.J. Lu via Libc-alpha
2021-08-10 17:42                     ` Fāng-ruì Sòng via Libc-alpha
2021-08-10 22:19   ` Fangrui Song via Libc-alpha
2021-08-23  3:18     ` Fāng-ruì Sòng via Libc-alpha
2021-08-24 17:05       ` Fāng-ruì Sòng via Libc-alpha
2021-08-30 19:52         ` Fāng-ruì Sòng via Libc-alpha
2021-08-30 20:01           ` Adhemerval Zanella via Libc-alpha
2021-08-31 21:24             ` Fāng-ruì Sòng via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOrMpTS6zmYe3Txp=u4iG3tdaoh2f6xuF-jcGeBXG5omMQ@mail.gmail.com' \
    --to=libc-alpha@sourceware.org \
    --cc=hjl.tools@gmail.com \
    --cc=maskray@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 read-only IMAP folder(s) and NNTP newsgroup(s).