public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH 3/3] csu: Move static pie self relocation later [BZ #27072]
Date: Fri, 8 Jan 2021 10:08:14 +0000	[thread overview]
Message-ID: <20210108100813.GS2379@arm.com> (raw)
In-Reply-To: <CAMe9rOrE0hv9bCMtBY9ObQtLRoCNKjwL1tVfL+r=aV0TQQzrAQ@mail.gmail.com>

The 01/07/2021 13:03, H.J. Lu wrote:
> On Thu, Jan 7, 2021 at 3:04 AM Szabolcs Nagy via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> >  #ifndef SHARED
> > +# ifndef PI_STATIC_AND_HIDDEN
> > +  /* Do static pie self relocation as early as possible.  */
> >    _dl_relocate_static_pie ();
> > +# endif
> 
> It should be simply removed. PI_STATIC_AND_HIDDEN should be
> required for static PIE.

i guess that makes sense, i can add an assertion for that.

> >    char **ev = &argv[argc + 1];
> >
> > @@ -191,6 +194,13 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
> 
> Does
>    {
>       /* Starting from binutils-2.23, the linker will define the
>          magic symbol __ehdr_start to point to our own ELF header
>          if it is visible in a segment that also includes the phdrs.
>          So we can set up _dl_phdr and _dl_phnum even without any
>          information from auxv.  */
> 
>       extern const ElfW(Ehdr) __ehdr_start
>         __attribute__ ((weak, visibility ("hidden")));
>       if (&__ehdr_start != NULL)
>         {
>           assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
>           GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
>           GL(dl_phnum) = __ehdr_start.e_phnum;
>         }
>     }
> 
> here require RELATIVE relocation?

hm indeed __ehdr_start is accessed via GOT.
(i thought pc relative access would work, but
i guess that cannot work for an undefined
weak symbol.)

without relocation processing &__ehdr_start
will always evaluate to 0, i.e. as if it was
undefined.

but i think GL(dl_phdr) is only used much
later so it can be moved after self relocs.
that would also make it clear that we don't
use anything here from phdrs that might
require relocations.

i'll fix this.

  reply	other threads:[~2021-01-08 10:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 11:00 [PATCH 0/3] fix ifunc with static pie " Szabolcs Nagy
2021-01-07 11:01 ` [PATCH 1/3] Make libc symbols hidden in static PIE Szabolcs Nagy
2021-01-07 11:01 ` [PATCH 2/3] [RFC] elf: hack up tunables to avoid RELATIVE relocs Szabolcs Nagy
2021-01-07 13:50   ` Siddhesh Poyarekar
2021-01-07 11:01 ` [PATCH 3/3] csu: Move static pie self relocation later [BZ #27072] Szabolcs Nagy
2021-01-07 12:36   ` H.J. Lu
2021-01-07 12:46     ` Carlos O'Donell
2021-01-07 12:51       ` H.J. Lu
2021-01-07 13:02         ` Szabolcs Nagy
2021-01-07 14:25           ` Szabolcs Nagy
2021-01-07 14:48             ` Siddhesh Poyarekar
2021-01-07 15:25               ` Szabolcs Nagy
2021-01-07 17:48                 ` H.J. Lu
2021-01-07 21:03   ` H.J. Lu
2021-01-08 10:08     ` Szabolcs Nagy [this message]
2021-01-07 12:48 ` [PATCH 0/3] fix ifunc with static pie " H.J. Lu
2021-01-07 12:50   ` Carlos O'Donell
2021-01-07 12:55     ` H.J. Lu
2021-01-07 13:03       ` Szabolcs Nagy
2021-01-07 13:15         ` H.J. Lu
2021-01-07 13:28           ` Szabolcs Nagy

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=20210108100813.GS2379@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.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 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).