public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org,
	 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Subject: Re: [PATCH v2] elf: Fix GL(dl_phdr) and GL(dl_phnum) for static builds [BZ #29864]
Date: Thu, 12 Jan 2023 15:46:44 +0100	[thread overview]
Message-ID: <875ydbq08b.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20230112144412.3102134-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Thu, 12 Jan 2023 11:44:12 -0300")

* Adhemerval Zanella:

> The 73fc4e28b9464f0e refactor did not add the GL(dl_phdr) and
> GL(dl_phnum) for static build, relying on the __ehdr_start symbol,
> which is always added by the static linker, to get the correct values.
>
> This is problematic in some ways:
>
>   - The segment may see its in-memory size differ from its in-file
>     size (or the binary may have holes).  The Linux has fixed is to
>     provide concise values for both AT_PHDR and AT_PHNUM (commit
>     0da1d5002745c - "fs/binfmt_elf: Fix AT_PHDR for unusual ELF files")
>
>   - Some archs (alpha for instance) the hidden weak reference is not
>     correctly pulled by the static linker and  __ehdr_start address
>     end up being 0, which makes GL(dl_phdr) and GL(dl_phnum) have both
>     invalid values (and triggering a segfault later on libc.so while
>     accessing TLS variables).
>
> The safer fix is to just restore the previous behavior to setup
> GL(dl_phdr) and GL(dl_phnum) for static based on kernel auxv.  The
> __ehdr_start fallback can also be simplified by not assuming weak
> linkage (as for PIE).
>
> The libc-static.c auxv init logic is moved to dl-support.c, since
> the later is build without SHARED and then GLRO macro is defined
> to access the variables directly.
>
> The _dl_phdr is also assumed to be always non NULL, since an invalid
> NULL values does not trigger TLS initialization (which is used in
> various libc systems).
>
> Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu.
>
> * Changes from v1:
>   - Removed auxv_values implicit initialization.
>   - Removed unused header inclusion.

This version looks okay to me.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian


  reply	other threads:[~2023-01-12 14:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 14:44 Adhemerval Zanella
2023-01-12 14:46 ` Florian Weimer [this message]
2023-02-02  9:36 ` John Paul Adrian Glaubitz
2023-02-03 14:04   ` Adhemerval Zanella Netto

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=875ydbq08b.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=glaubitz@physik.fu-berlin.de \
    --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).