[PATCH v5] elf: Add DL_ADDRESS_WITHOUT_RELOC [BZ #33088]

Florian Weimer fweimer@redhat.com
Mon Jun 30 13:52:48 GMT 2025


* H. J. Lu:

> Add DL_ADDRESS_WITHOUT_RELOC to force an address into a general purpose
> register to prevent loading it into a vector register directly before
> run-time relocation.  This is an updated fix for BZ #33088.
>
> -- 
> H.J.
>
> From df5a1cf09dbf5b779aa93f8568194854e87d9bed Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Sun, 15 Jun 2025 11:38:54 +0800
> Subject: [PATCH v5] elf: Add DL_ADDRESS_WITHOUT_RELOC [BZ #33088]
>
> Add DL_ADDRESS_WITHOUT_RELOC to force an address into a general purpose
> register to prevent loading it into a vector register directly before
> run-time relocation.  This is an updated fix for BZ #33088.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  elf/rtld.c    |  9 ++++-----
>  include/elf.h | 13 +++++++++++++
>  2 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/elf/rtld.c b/elf/rtld.c
> index e6a181dc31..9038a50799 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -476,11 +476,10 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
>  #endif
>    _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));
> +  _dl_rtld_map.l_map_start
> +    = (ElfW(Addr)) DL_ADDRESS_WITHOUT_RELOC (&__ehdr_start);
> +  _dl_rtld_map.l_map_end
> +    = (ElfW(Addr)) DL_ADDRESS_WITHOUT_RELOC (_end);
>    /* Copy the TLS related data if necessary.  */
>  #ifndef DONT_USE_BOOTSTRAP_MAP
>  # if NO_TLS_OFFSET != 0
> diff --git a/include/elf.h b/include/elf.h
> index 14ed67ff67..1424982bb5 100644
> --- a/include/elf.h
> +++ b/include/elf.h
> @@ -15,6 +15,19 @@
>  # define ELF_NOTE_NEXT_OFFSET(namesz, descsz, align) \
>    ALIGN_UP (ELF_NOTE_DESC_OFFSET ((namesz), (align)) + (descsz), (align))
>  
> +# ifdef HIDDEN_VAR_NEEDS_DYNAMIC_RELOC
> +#  define DL_ADDRESS_WITHOUT_RELOC(expr) (expr)
> +# else
> +/* Evaluate EXPR without run-time relocation for it.  EXPR should be an
> +   array, an address of an object, or a string literal.  */
> +#  define DL_ADDRESS_WITHOUT_RELOC(expr)	\
> +  ({						\
> +     __auto_type _result = (expr);		\
> +     asm ("" : "+r" (_result));			\
> +     _result;					\
> +   })
> +# endif

I was a bit confused, but the #ifdef without any extra #includes should
be fine because of this in include/libc-symbols.h:

/* This file is included implicitly in the compilation of every source file,
   using -include.  It includes config.h.  */

If we need an arch override for DL_ADDRESS_WITHOUT_RELOC, we can create
one, so I'm fine with this version.

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

Thanks,
Florian



More information about the Libc-alpha mailing list