glibc/csu
Adhemerval Zanella 7e31d16651 elf: Fix GL(dl_phdr) and GL(dl_phnum) for static builds [BZ #29864]
The 73fc4e28b9 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.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2023-01-12 13:54:34 -03:00
..
abi-note.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
check_fds.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
dso_handle.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
errno-loc.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
errno.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
gmon-start.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
init-first.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
init.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
libc-start.c elf: Fix GL(dl_phdr) and GL(dl_phnum) for static builds [BZ #29864] 2023-01-12 13:54:34 -03:00
libc-tls.c elf: Fix GL(dl_phdr) and GL(dl_phnum) for static builds [BZ #29864] 2023-01-12 13:54:34 -03:00
Makefile Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
rtld-sizes.sym Extend struct r_debug to support multiple namespaces [BZ #15971] 2021-09-19 13:51:35 -07:00
start.c
static-reloc.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
sysdep.c
version.c Update copyright dates with scripts/update-copyrights 2023-01-06 21:14:39 +00:00
Versions Reduce the statically linked startup code [BZ #23323] 2021-02-25 12:13:02 +01:00