[PATCH 2/5] [PowerPC64] Set up thread register for _dl_relocate_static_pie
Alan Modra
amodra@gmail.com
Mon Jan 24 03:47:32 GMT 2022
On Sun, Jan 23, 2022 at 11:12:13PM +1030, Alan Modra wrote:
> There's a serious problem in libgcc too. libgcc ifuncs access the
> AT_HWCAP words stored in the tcb with an offset from the thread
> pointer (r13), but r13 isn't set at the time _dl_relocate_static_pie
> runs, and I'm loathe to try calling init_tls early. A better approach
> that might work is to fake r13 so that _dl_hwcap is at the expected
> offset where we'd normally find the tcb hwcap words.
Like this.
libgcc ifunc resolvers that access hwcap via a field in the tcb can't
be called until the thread pointer is set up. This patch sets up a
fake thread pointer early so that static-pies won't segfault on
attempting to relocate themselves.
diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h
index eb41c85280..413bbe7c06 100644
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
@@ -589,6 +589,27 @@ elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc,
#define ARCH_LA_PLTEXIT ppc64v2_gnu_pltexit
#endif
+#if ENABLE_STATIC_PIE && !defined SHARED && !IS_IN (rtld)
+#include <libc-diag.h>
+#include <tcb-offsets.h>
+
+/* Set up r13 for _dl_relocate_static_pie so that libgcc ifuncs that
+ normally access the tcb copy of hwcap will see __tcb_hwcap. */
+
+static inline void __attribute__ ((always_inline))
+ppc_init_fake_thread_pointer (void)
+{
+ DIAG_PUSH_NEEDS_COMMENT;
+ /* We are playing pointer tricks. Silence gcc warning. */
+ DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Warray-bounds");
+ __thread_register = (char *) &__tcb_hwcap - TCB_HWCAP;
+ DIAG_POP_NEEDS_COMMENT;
+}
+
+#define ELF_MACHINE_BEFORE_RTLD_RELOC(map, dynamic_info) \
+ ppc_init_fake_thread_pointer ();
+#endif /* ENABLE_STATIC_PIE && !defined SHARED && !IS_IN (rtld) */
+
#endif /* dl_machine_h */
#ifdef RESOLVE_MAP
--
Alan Modra
Australia Development Lab, IBM
More information about the Libc-alpha
mailing list