ldso: use __ehdr_start if available to locate its own ELF headers
commit5baf2d92d3ed82960c419cb6093fbcdd028dde11
authorRich Felker <dalias@aerifal.cx>
Mon, 6 Nov 2023 17:59:34 +0000 (6 12:59 -0500)
committerRich Felker <dalias@aerifal.cx>
Mon, 6 Nov 2023 17:59:34 +0000 (6 12:59 -0500)
treeadd0f8e3612b483f84a2fe2b6beda049dbd084fe
parent725e17ed6dff4d0cd22487bb64470881e86a92e7
ldso: use __ehdr_start if available to locate its own ELF headers

previously, the relative load address was used as the address at which
to find the ELF headers. this only works if two conditions are met:
ldso is linked to start at a virtual address of 0, and the linker is
cooperative and includes the main ELF headers in a loadable segment.

while in practice these are always met, modern linkers provide a
__ehdr_start symbol pointing to the ELF headers, and can in principle
use the reference to this symbol as an indication that they need to be
mapped in a segment. this also should make it possible to link for a
different starting virtual address, if that's ever desirable.
ldso/dynlink.c