summaryrefslogtreecommitdiff
path: root/sysdeps/x86_64
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2025-06-15 11:38:54 +0800
committerH.J. Lu <hjl.tools@gmail.com>2025-06-16 08:43:40 +0800
commit81467d4b6168c7ce40d951d6b32e387109c0e5ae (patch)
treed8d7261619e6a35f40e905b6b2a1874309dae40f /sysdeps/x86_64
parent27360ab9ea637de80ded9f0e0fe23ac0cc621b29 (diff)
elf: Add optimization barrier for __ehdr_start and _end
rtld.c has extern const ElfW(Ehdr) __ehdr_start attribute_hidden; ... _dl_rtld_map.l_map_start = (ElfW(Addr)) &__ehdr_start; _dl_rtld_map.l_map_end = (ElfW(Addr)) _end; 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. Add optimization barrier to prevent run-time relocations against __ehdr_start and _end. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'sysdeps/x86_64')
-rw-r--r--sysdeps/x86_64/Makefile18
1 files changed, 18 insertions, 0 deletions
diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
index 5723ec1847..e8f8a52eea 100644
--- a/sysdeps/x86_64/Makefile
+++ b/sysdeps/x86_64/Makefile
@@ -214,6 +214,24 @@ $(objpfx)tst-plt-rewrite2: $(objpfx)tst-plt-rewritemod2.so
endif
test-internal-extras += tst-gnu2-tls2mod1
+
+tests-special += $(objpfx)check-rtld.out
+
+$(objpfx)rtld.reloc: $(objpfx)rtld.os
+ @rm -f $@T
+ LC_ALL=C $(READELF) -rW $< > $@T
+ test -s $@T
+ mv -f $@T $@
+common-generated += $(objpfx)rtld.reloc
+
+# Verify that there are no run-time relocations against __ehdr_start nor
+# _end.
+$(objpfx)check-rtld.out: $(objpfx)rtld.reloc
+ LC_ALL=C; \
+ if grep -E "R_X86_64_64.*(__ehdr_start|_end)" $^ > $@; \
+ then false; else true; fi; \
+ $(evaluate-test)
+generated += check-rtld.out
endif # $(subdir) == elf
ifeq ($(subdir),csu)