summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/alpha/init-first.h
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/alpha/init-first.h')
-rw-r--r--sysdeps/unix/sysv/linux/alpha/init-first.h39
1 files changed, 28 insertions, 11 deletions
diff --git a/sysdeps/unix/sysv/linux/alpha/init-first.h b/sysdeps/unix/sysv/linux/alpha/init-first.h
index c27c589a28..ffbcaf1521 100644
--- a/sysdeps/unix/sysv/linux/alpha/init-first.h
+++ b/sysdeps/unix/sysv/linux/alpha/init-first.h
@@ -1,12 +1,29 @@
-/* This fragment is invoked in the stack context of program start.
-   Its job is to set up a pointer to argc as an argument, pass
-   control to `INIT', and, if necessary, clean up after the call
-   to leave the stack in the same condition it was found in.  */
+/* The job of this fragment it to find argc and friends for INIT.
+   This is done in one of two ways: either in the stack context
+   of program start, or having dlopen pass them in.  */
 
-#define SYSDEP_CALL_INIT(NAME, INIT)	\
-    asm(".globl " #NAME "\n"		\
-	#NAME ":\n\t"			\
-	"ldgp $29, 0($27)\n\t"		\
-	".prologue 1\n\t"		\
-	"mov $30, $16\n\t"		\
-	"br $31, " #INIT "..ng");
+#define SYSDEP_CALL_INIT(NAME, INIT)		\
+    asm(".weak _dl_starting_up\n\t"		\
+        ".globl " #NAME "\n\t"			\
+	".ent " #NAME "\n"			\
+	#NAME ":\n\t"				\
+	"ldgp	$29, 0($27)\n\t"		\
+	".prologue 1\n\t"			\
+	".set at\n\t"				\
+	/* Are we a dynamic libc being loaded into a static program?  */ \
+	"lda	$0, _dl_starting_up\n\t"	\
+	"beq	$0, 1f\n\t"			\
+	"ldl	$0, 0($0)\n"			\
+	"cmpeq	$31, $0, $0\n"			\
+	"1:\t"					\
+	"stl	$0, __libc_multiple_libcs\n\t"	\
+	/* If so, argc et al are in a0-a2 already.  Otherwise, load them.  */ \
+	"bne	$0, 2f\n\t"			\
+	"ldl	$16, 0($30)\n\t"		\
+	"lda	$17, 8($30)\n\t"		\
+	"s8addq	$16, $17, $18\n\t"		\
+	"addq	$18, 8, $18\n"			\
+	"2:\t"					\
+	"br $31, " #INIT "..ng\n\t"		\
+	".set noat\n\t"				\
+	".end " #NAME);