unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Fāng-ruì Sòng via Libc-alpha" <libc-alpha@sourceware.org>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations [BZ #27164]
Date: Tue, 13 Jul 2021 16:57:55 -0700	[thread overview]
Message-ID: <CAFP8O3+uLKzXSbUN0wJMy_W-635kTJHtW1B6R84reZTtvtLd1Q@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOoSW2bTnEGz09gUYmLYD2K+=3pByY22NXF1Z5woey4BEg@mail.gmail.com>

On Tue, Jul 13, 2021 at 4:48 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Jul 13, 2021 at 4:31 PM Fāng-ruì Sòng <maskray@google.com> wrote:
> >
> > On Tue, Jul 13, 2021 at 4:21 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Tue, Jul 13, 2021 at 4:07 PM Fangrui Song via Libc-alpha
> > > <libc-alpha@sourceware.org> wrote:
> > > >
> > > > On 2021-07-13, Siddhesh Poyarekar wrote:
> > > > >On 7/13/21 1:36 PM, Fangrui Song via Libc-alpha wrote:
> > > > >>A toolchain project can do some workaround for a libc if this choice
> > > > >>makes a large community happy. However, I think it is important not to
> > > > >>take it granted. It is inadequate to just dismiss toolchain developers'
> > > > >>reasonable complaints. The libc should actively fix the issues so that
> > > > >>the toolchain will not need to bear unneeded code in the future.
> > > > >>
> > > > >>I actually have contributed quite a few lld/ELF patches to work around
> > > > >>glibc. For this one I just feel it is not right to just patch lld/ELF
> > > > >>without fixing glibc.
> > > > >
> > > > >What's the utility of having the __rela_iplt{_start,_end} symbols in
> > > > >all binaries other than, maybe, simplifying the static linker
> > > > >implementation?  How does it improve things for the generated
> > > > >application code in the end?  AFAICT it is doing the opposite by
> > > > >requiring application startup to add a conditional to work around the
> > > > >presence of a redundant symbol.
> > > > >
> > > > >Siddhesh
> > > >
> > > > Please see the sentence from the first message
> > > > "In addition, this enables a future simplification to GNU ld: we can
> > > > drop a linker script difference between -no-pie and -pie."
> > >
> > > Did you mean non-PIE static and PIE static?  Neither PIE nor PDE
> > > define __rela_iplt{_start,_end}.
> > >
> > > > This is the only difference other than image base difference.
> > >
> > > There are many differences between non-PIE static and PIE static.
> > > Non-PIE static doesn't have DT_XXX sections.
> >
> > % diff -U1 =(ld.bfd --verbose) =(ld.bfd -pie --verbose)
> > --- /tmp/zshEtZMxJ      2021-07-13 16:30:50.228732445 -0700
> > +++ /tmp/zshNM1wJL      2021-07-13 16:30:50.232732450 -0700
> > @@ -12,3 +12,3 @@
> >  ==================================================
> > -/* Script for -z combreloc -z separate-code */
> > +/* Script for -pie -z combreloc -z separate-code */
> >  /* Copyright (C) 2014-2020 Free Software Foundation, Inc.
> > @@ -24,3 +24,3 @@
> >  {
> > -  PROVIDE (__executable_start = SEGMENT_START("text-segment",
> > 0x400000)); . = SEGMENT_START("text-segment", 0x400000) +
> > SIZEOF_HEADERS;
> > +  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0)); .
> > = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS;
> >    .interp         : { *(.interp) }
> > @@ -55,5 +55,3 @@
> >        *(.rela.plt)
> > -      PROVIDE_HIDDEN (__rela_iplt_start = .);
> >        *(.rela.iplt)
> > -      PROVIDE_HIDDEN (__rela_iplt_end = .);
> >      }
>
> Here is the deal:
>
> 1.  ld uses the same linker script for both PDE static and PDE.  We need
>  __rela_iplt{_start,_end} for PDE static.   That is why there are
>
>       PROVIDE_HIDDEN (__rela_iplt_start = .);
>       *(.rela.iplt)
>       PROVIDE_HIDDEN (__rela_iplt_end = .);
>
> Since PDE is linked against libc.so which doesn't reference
> __rela_iplt{_start,_end}, these symbols are not defined for PDE.
>
> 2. ld uses the same linker script for both PIE static and PIE.  There is
> no need for  __rela_iplt{_start,_end}.
>
> Are you suggesting to use the same linker scripts for PDE, PDE static,
> PIE and PIE static?

Because of the image base difference, PDE/PIE linker scripts cannot be
entirely identical,
but symbol differences should be reduced.

BTW: diff -u =(ld.bfd -pie --verbose) =(ld.bfd -shared --verbose) has
some PROVIDE_HIDDEN differences.
Since these symbols are PROVIDE style, these differences are
artificial and should be reduced as well.

  reply	other threads:[~2021-07-13 23:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08 22:10 [PATCH] csu: Skip ARCH_SETUP_IREL if _dl_relocate_static_pie applied IRELATIVE relocations [BZ #27164] Fangrui Song via Libc-alpha
2021-07-08 23:27 ` H.J. Lu via Libc-alpha
2021-07-12 14:08 ` Carlos O'Donell via Libc-alpha
2021-07-13  8:06   ` Fangrui Song via Libc-alpha
2021-07-13  8:33     ` Siddhesh Poyarekar
2021-07-13 23:06       ` Fangrui Song via Libc-alpha
2021-07-13 23:20         ` H.J. Lu via Libc-alpha
2021-07-13 23:31           ` Fāng-ruì Sòng via Libc-alpha
2021-07-13 23:47             ` H.J. Lu via Libc-alpha
2021-07-13 23:57               ` Fāng-ruì Sòng via Libc-alpha [this message]
2021-07-14  1:17                 ` H.J. Lu via Libc-alpha
2021-07-14  2:15         ` Siddhesh Poyarekar
2021-09-06  6:30           ` 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=CAFP8O3+uLKzXSbUN0wJMy_W-635kTJHtW1B6R84reZTtvtLd1Q@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).