[PATCH] elf: Add _dl_ehdr_start_before_reloc
Sam James
sam@gentoo.org
Sun Jun 15 22:32:21 GMT 2025
"H.J. Lu" <hjl.tools@gmail.com> writes:
> rtld.c has
>
> extern const ElfW(Ehdr) __ehdr_start attribute_hidden;
> ...
> _dl_rtld_map.l_map_start = (ElfW(Addr)) &__ehdr_start;
>
> As
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120653
>
> shows, compiler may generate run-time relocation on __ehdr_start with
>
> movq .LC0(%rip), %xmm0
> ...
> .section .data.rel.ro.local,"aw"
> .align 8
> .LC0:
> .quad __ehdr_start
>
> This won't work before run-time relocation is finished in rtld.c. Define
> _dl_ehdr_start_before_reloc to allow x86-64 to generate LEA to avoid
> run-time relocation on __ehdr_start in rtld.c.
LGTM, but please give Florian a chance to object. Thanks for adding a
test too.
I still feel a bit uneasy about the general approach here
(whack-a-mole). Florian had some thoughts at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120653#c15 on doing better
but I don't think that should block this simple (and backportable in due
course) fix.
I see Jakub has a broader suggestion as well on the bug.
More information about the Libc-alpha
mailing list