[PATCH v2] elf: Add optimization barrier for __ehdr_start and _end

Florian Weimer fweimer@redhat.com
Mon Jun 16 04:55:39 GMT 2025


* H. J. Lu:

> diff --git a/elf/rtld.c b/elf/rtld.c
> index 8e8f0e6253..e6a181dc31 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -477,7 +477,10 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
>    _dl_setup_hash (&_dl_rtld_map);
>    _dl_rtld_map.l_real = &_dl_rtld_map;
>    _dl_rtld_map.l_map_start = (ElfW(Addr)) &__ehdr_start;
> +  /* Prevent run-time relocations against __ehdr_start and _end.  */
> +  asm ("" : "+g" (_dl_rtld_map.l_map_start));
>    _dl_rtld_map.l_map_end = (ElfW(Addr)) _end;
> +  asm ("" : "+g" (_dl_rtld_map.l_map_end));
>    /* Copy the TLS related data if necessary.  */
>  #ifndef DONT_USE_BOOTSTRAP_MAP
>  # if NO_TLS_OFFSET != 0

This needs a better comment about why we are doing this, and exactly how
it prevents this problem.

However, I think x86 without -mgeneral-regs-only simply is a
HIDDEN_VAR_NEEDS_DYNAMIC_RELOC architecture because GCC uses dynamic
relocations against hidden or static objects to load pointers into
vector registers (and that's exactly what HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
is about).

Should we build elf/rtld.c with -mgeneral-regs-only?  As far as I can
see, it solves the issue, and it does not need GCC changes.

Thanks,
Florian



More information about the Libc-alpha mailing list