public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] rtld: Add new hook to initialize dp register on hppa
@ 2022-02-11 17:29 John David Anglin
  2022-02-11 17:51 ` Florian Weimer
  2022-02-11 18:17 ` H.J. Lu
  0 siblings, 2 replies; 6+ messages in thread
From: John David Anglin @ 2022-02-11 17:29 UTC (permalink / raw)
  To: libc-alpha; +Cc: Adhemerval Zanella, carlos

[-- Attachment #1: Type: text/plain, Size: 2840 bytes --]

The test elf/tst-audit2 fails on hppa with a segmentation fault in the
long branch stub used to call malloc from calloc.  This occur because
the test is not a PIC executable and calloc is called from the dynamic
linker before the dp register is initialized in _dl_start_user.

The fix is to add a new hook, ELF_MACHINE_AFTER_RTLD_RELOC, in dl_main
to allow initialization of the dp register just after relocation is
completed.

Okay?

Dave
---

diff --git a/elf/rtld.c b/elf/rtld.c
index 19e328f89e..fcea41cb86 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -2333,6 +2333,10 @@ dl_main (const ElfW(Phdr) *phdr,
   /* Make sure no new search directories have been added.  */
   assert (GLRO(dl_init_all_dirs) == GL(dl_all_dirs));
 
+#ifdef ELF_MACHINE_AFTER_RTLD_RELOC
+  ELF_MACHINE_AFTER_RTLD_RELOC (main_map);
+#endif
+
   if (rtld_multiple_ref)
     {
       /* There was an explicit ref to the dynamic linker as a shared lib.
diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h
index da4d57d2e4..74a81dc1f7 100644
--- a/sysdeps/hppa/dl-machine.h
+++ b/sysdeps/hppa/dl-machine.h
@@ -70,6 +70,18 @@ __hppa_init_bootstrap_fdesc_table (struct link_map *map)
   map->l_mach.fptr_table = boot_table;
 }
 
+/* Set up dp for any non-PIC lib functions that may be called.  */
+static inline void
+set_dp (struct link_map *map)
+{
+  register Elf32_Addr dp asm ("%r27");
+  dp = D_PTR (map, l_info[DT_PLTGOT]);
+  asm volatile ("" : : "r" (dp));
+}
+
+#define ELF_MACHINE_AFTER_RTLD_RELOC(map)			\
+	set_dp (map);
+
 #define ELF_MACHINE_BEFORE_RTLD_RELOC(map, dynamic_info)	\
 	__hppa_init_bootstrap_fdesc_table (map);		\
 	_dl_fptr_init();
@@ -338,16 +350,6 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
    its return value is the user program's entry point.  */
 
 #define RTLD_START \
-/* Set up dp for any non-PIC lib constructors that may be called.  */	\
-static struct link_map * __attribute__((used))				\
-set_dp (struct link_map *map)						\
-{									\
-  register Elf32_Addr dp asm ("%r27");					\
-  dp = D_PTR (map, l_info[DT_PLTGOT]);					\
-  asm volatile ("" : : "r" (dp));					\
-  return map;								\
-}									\
-									\
 asm (									\
 "	.text\n"							\
 "	.globl _start\n"						\
@@ -447,14 +449,11 @@ asm (									\
 "	stw	%r24,-44(%sp)\n"					\
 									\
 ".Lnofix:\n"								\
+	/* Call _dl_init(main_map, argc, argv, envp). */		\
 "	addil	LT'_rtld_local,%r19\n"					\
 "	ldw	RT'_rtld_local(%r1),%r26\n"				\
-"	bl	set_dp, %r2\n"						\
 "	ldw	0(%r26),%r26\n"						\
 									\
-	/* Call _dl_init(_dl_loaded, argc, argv, envp). */		\
-"	copy	%r28,%r26\n"						\
-									\
 	/* envp = argv + argc + 1 */					\
 "	sh2add	%r25,%r24,%r23\n"					\
 "	bl	_dl_init,%r2\n"						\


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-14 15:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-11 17:29 [PATCH] rtld: Add new hook to initialize dp register on hppa John David Anglin
2022-02-11 17:51 ` Florian Weimer
2022-02-11 18:59   ` John David Anglin
2022-02-11 19:07     ` Florian Weimer
2022-02-14 15:25       ` John David Anglin
2022-02-11 18:17 ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).