]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Add DL_ADDRESS_WITHOUT_RELOC [BZ #33088] master
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 15 Jun 2025 03:38:54 +0000 (11:38 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 30 Jun 2025 19:44:52 +0000 (03:44 +0800)
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>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
elf/rtld.c
include/elf.h

index e6a181dc310a080a8668ffc316f9a6818d0c0495..9038a507997029475e32df6e0250a2c096ac85ef 100644 (file)
@@ -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
index 14ed67ff67d36349b12750c431478ce86c504ab0..1424982bb59073b878f347e5e178ff4c22ec6782 100644 (file)
 # 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
+
 /* Some information which is not meant for the public and therefore not
    in <elf.h>.  */
 # include <dl-dtprocnum.h>