about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog24
-rw-r--r--elf/Makefile25
-rw-r--r--elf/tst-array1.c99
-rw-r--r--elf/tst-array1.exp11
-rw-r--r--elf/tst-array2.c1
-rw-r--r--elf/tst-array2.exp19
-rw-r--r--elf/tst-array2dep.c67
-rw-r--r--elf/tst-array3.c1
-rw-r--r--sysdeps/ia64/elf/initfini.c185
9 files changed, 354 insertions, 78 deletions
diff --git a/ChangeLog b/ChangeLog
index ad82256c91..c99038a9f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2002-10-29  David Mosberger  <davidm@hpl.hp.com>
+
+	* sysdeps/ia64/elf/initfini.c [HAVE_INITFINI_ARRAY]
+	(gmon_initializer): New function.
+	(.init prologue): If HAVE_INITFINI_ARRAY is true, don't call
+	__gmon_start__ here.  Call it from gmon_initializer() instead.
+
+2002-03-12  H.J. Lu  <hjl@gnu.org>
+
+	* elf/Makefile [$(have-initfini-array) = yes] (tests): Add tst-array1,
+	tst-array2, and tst-array3.
+	[$(have-initfini-array) = yes] (tests-static): Add tst-array3.
+	[$(have-initfini-array) = yes] (modules-names): Add tst-array2dep.
+	($(objpfx)tst-array1.out): New target.
+	($(objpfx)tst-array2): Likewise.
+	($(objpfx)tst-array2.out): Likewise.
+	($(objpfx)tst-array3.out): Likewise.
+	* elf/tst-array1.c: New file.
+	* elf/tst-array1.exp: Likewise.
+	* elf/tst-array2.c: Likewise.
+	* elf/tst-array2dep.c: Likewise.
+	* elf/tst-array2.exp: Likewise.
+	* elf/tst-array3.c: Likewise.
+
 2002-10-28  David Mosberger  <davidm@hpl.hp.com>
 
 	* elf/dl-fini.c (_dl_fini): Invoke fini_array in _reverse_ order.
diff --git a/elf/Makefile b/elf/Makefile
index 015352275c..a6d96c6d90 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -117,6 +117,9 @@ endif
 endif
 
 tests = tst-tls1 tst-tls2 tst-tls9
+ifeq (yes,$(have-initfini-array))
+tests += tst-array1 tst-array2 tst-array3
+endif
 ifeq (yes,$(build-static))
 tests-static = tst-tls1-static tst-tls2-static
 ifeq (yesyesyes,$(build-static)$(build-shared)$(elf))
@@ -156,6 +159,9 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
 		tst-tlsmod5 tst-tlsmod6 \
 		circlemod1 circlemod1a circlemod2 circlemod2a \
 		circlemod3 circlemod3a
+ifeq (yes,$(have-initfini-array))
+modules-names += tst-array2dep
+endif
 modules-vis-yes = vismod1 vismod2 vismod3
 modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4
 modules-nodlopen-yes = nodlopenmod nodlopenmod2
@@ -543,3 +549,22 @@ ifdef libdl
 $(objpfx)tst-tls9-static: $(common-objpfx)dlfcn/libdl.a
 $(objpfx)tst-tls9-static.out: $(objpfx)tst-tlsmod5.so $(objpfx)tst-tlsmod6.so
 endif
+
+$(objpfx)tst-array1.out: $(objpfx)tst-array1
+	$(elf-objpfx)$(rtld-installed-name) \
+	  --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
+	  $(objpfx)tst-array1 > $@
+	cmp $@ tst-array1.exp > /dev/null
+
+$(objpfx)tst-array2: $(objpfx)tst-array2dep.so
+$(objpfx)tst-array2.out: $(objpfx)tst-array2
+	$(elf-objpfx)$(rtld-installed-name) \
+	  --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
+	  $(objpfx)tst-array2 > $@
+	cmp $@ tst-array2.exp > /dev/null
+
+$(objpfx)tst-array3.out: $(objpfx)tst-array3
+	$(elf-objpfx)$(rtld-installed-name) \
+	  --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
+	  $(objpfx)tst-array3 > $@
+	cmp $@ tst-array1.exp > /dev/null
diff --git a/elf/tst-array1.c b/elf/tst-array1.c
new file mode 100644
index 0000000000..86ed4a1a63
--- /dev/null
+++ b/elf/tst-array1.c
@@ -0,0 +1,99 @@
+#include <unistd.h>
+
+static void init (void) __attribute__ ((constructor));
+
+static void
+init (void)
+{
+  write (STDOUT_FILENO, "init\n", 5);
+}
+
+static void fini (void) __attribute__ ((destructor));
+
+static void
+fini (void)
+{
+  write (STDOUT_FILENO, "fini\n", 5);
+}
+
+static void
+preinit_0 (void)
+{
+  write (STDOUT_FILENO, "preinit array 0\n", 16);
+}
+
+static void
+preinit_1 (void)
+{
+  write (STDOUT_FILENO, "preinit array 1\n", 16);
+}
+
+static void
+preinit_2 (void)
+{
+  write (STDOUT_FILENO, "preinit array 2\n", 16);
+}
+
+void (*const preinit_array []) (void)
+     __attribute__ ((section (".preinit_array"))) =
+{
+  &preinit_0,
+  &preinit_1,
+  &preinit_2
+};
+
+static void
+init_0 (void)
+{
+  write (STDOUT_FILENO, "init array 0\n", 13);
+}
+
+static void
+init_1 (void)
+{
+  write (STDOUT_FILENO, "init array 1\n", 13);
+}
+
+static void
+init_2 (void)
+{
+  write (STDOUT_FILENO, "init array 2\n", 13);
+}
+
+void (*const init_array []) (void) __attribute__ ((section (".init_array"))) =
+{
+  &init_0,
+  &init_1,
+  &init_2
+};
+
+static void
+fini_0 (void)
+{
+  write (STDOUT_FILENO, "fini array 0\n", 13);
+}
+
+static void
+fini_1 (void)
+{
+  write (STDOUT_FILENO, "fini array 1\n", 13);
+}
+
+static void
+fini_2 (void)
+{
+  write (STDOUT_FILENO, "fini array 2\n", 13);
+}
+
+void (*const fini_array []) (void) __attribute__ ((section (".fini_array"))) =
+{
+  &fini_0,
+  &fini_1,
+  &fini_2
+};
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/elf/tst-array1.exp b/elf/tst-array1.exp
new file mode 100644
index 0000000000..cfcec9de0f
--- /dev/null
+++ b/elf/tst-array1.exp
@@ -0,0 +1,11 @@
+preinit array 0
+preinit array 1
+preinit array 2
+init
+init array 0
+init array 1
+init array 2
+fini array 2
+fini array 1
+fini array 0
+fini
diff --git a/elf/tst-array2.c b/elf/tst-array2.c
new file mode 100644
index 0000000000..21539a4212
--- /dev/null
+++ b/elf/tst-array2.c
@@ -0,0 +1 @@
+#include "tst-array1.c"
diff --git a/elf/tst-array2.exp b/elf/tst-array2.exp
new file mode 100644
index 0000000000..ed203525b5
--- /dev/null
+++ b/elf/tst-array2.exp
@@ -0,0 +1,19 @@
+preinit array 0
+preinit array 1
+preinit array 2
+DSO init
+DSO init array 0
+DSO init array 1
+DSO init array 2
+init
+init array 0
+init array 1
+init array 2
+fini array 2
+fini array 1
+fini array 0
+fini
+DSO fini array 2
+DSO fini array 1
+DSO fini array 0
+DSO fini
diff --git a/elf/tst-array2dep.c b/elf/tst-array2dep.c
new file mode 100644
index 0000000000..be46dd13e2
--- /dev/null
+++ b/elf/tst-array2dep.c
@@ -0,0 +1,67 @@
+#include <unistd.h>
+
+static void init (void) __attribute__ ((constructor));
+
+static void
+init (void)
+{
+  write (STDOUT_FILENO, "DSO init\n", 9);
+}
+
+static void fini (void) __attribute__ ((destructor));
+
+static void
+fini (void)
+{
+  write (STDOUT_FILENO, "DSO fini\n", 9);
+}
+
+static void
+init_0 (void)
+{
+  write (STDOUT_FILENO, "DSO init array 0\n", 17);
+}
+
+static void
+init_1 (void)
+{
+  write (STDOUT_FILENO, "DSO init array 1\n", 17);
+}
+
+static void
+init_2 (void)
+{
+  write (STDOUT_FILENO, "DSO init array 2\n", 17);
+}
+
+void (*const init_array []) (void) __attribute__ ((section (".init_array"))) =
+{
+  &init_0,
+  &init_1,
+  &init_2
+};
+
+static void
+fini_0 (void)
+{
+  write (STDOUT_FILENO, "DSO fini array 0\n", 17);
+}
+
+static void
+fini_1 (void)
+{
+  write (STDOUT_FILENO, "DSO fini array 1\n", 17);
+}
+
+static void
+fini_2 (void)
+{
+  write (STDOUT_FILENO, "DSO fini array 2\n", 17);
+}
+
+void (*const fini_array []) (void) __attribute__ ((section (".fini_array"))) =
+{
+  &fini_0,
+  &fini_1,
+  &fini_2
+};
diff --git a/elf/tst-array3.c b/elf/tst-array3.c
new file mode 100644
index 0000000000..21539a4212
--- /dev/null
+++ b/elf/tst-array3.c
@@ -0,0 +1 @@
+#include "tst-array1.c"
diff --git a/sysdeps/ia64/elf/initfini.c b/sysdeps/ia64/elf/initfini.c
index 2e3234a2aa..5315abfee1 100644
--- a/sysdeps/ia64/elf/initfini.c
+++ b/sysdeps/ia64/elf/initfini.c
@@ -27,81 +27,110 @@
    * crtn.s puts the corresponding function epilogues
    in the .init and .fini sections. */
 
-__asm__ ("\n\
-\n\
-#include \"defs.h\"\n\
-\n\
-/*@HEADER_ENDS*/\n\
-\n\
-/*@_init_PROLOG_BEGINS*/\n\
-	.section .init\n\
-	.align 16\n\
-	.global _init#\n\
-	.proc _init#\n\
-_init:\n\
-	alloc r34 = ar.pfs, 0, 3, 0, 0\n\
-	mov r32 = r12\n\
-	mov r33 = b0\n\
-	adds r12 = -16, r12\n\
-	addl r14 = @ltoff(@fptr(__gmon_start__#)), gp\n\
-	;;\n\
-	ld8 r15 = [r14]\n\
-	;;\n\
-	cmp.eq p6, p7 = 0, r15\n\
-	(p6) br.cond.dptk .L5\n\
-\n\
-/* we could use r35 to save gp, but we use the stack since that's what\n\
- * all the other init routines will do --davidm 00/04/05 */\n\
-	st8 [r12] = gp, -16\n\
-	br.call.sptk.many b0 = __gmon_start__# ;;\n\
-	adds r12 = 16, r12\n\
-	;;\n\
-	ld8 gp = [r12]\n\
-	;;\n\
-.L5:\n\
-	.align 16\n\
-	.endp _init#\n\
-\n\
-/*@_init_PROLOG_ENDS*/\n\
-\n\
-/*@_init_EPILOG_BEGINS*/\n\
-	.section .init\n\
-	.regstk 0,2,0,0\n\
-	mov r12 = r32\n\
-	mov ar.pfs = r34\n\
-	mov b0 = r33\n\
-	br.ret.sptk.many b0\n\
-	.endp _init#\n\
-/*@_init_EPILOG_ENDS*/\n\
-\n\
-/*@_fini_PROLOG_BEGINS*/\n\
-	.section .fini\n\
-	.align 16\n\
-	.global _fini#\n\
-	.proc _fini#\n\
-_fini:\n\
-	alloc r34 = ar.pfs, 0, 3, 0, 0\n\
-	mov r32 = r12\n\
-	mov r33 = b0\n\
-	adds r12 = -16, r12\n\
-	;;\n\
-	.align 16\n\
-	.endp _fini#\n\
-\n\
-/*@_fini_PROLOG_ENDS*/\n\
-	br.call.sptk.many b0 = i_am_not_a_leaf# ;;\n\
-	;;\n\
-\n\
-/*@_fini_EPILOG_BEGINS*/\n\
-	.section .fini\n\
-	mov r12 = r32\n\
-	mov ar.pfs = r34\n\
-	mov b0 = r33\n\
-	br.ret.sptk.many b0\n\
-	.endp _fini#\n\
-\n\
-/*@_fini_EPILOG_ENDS*/\n\
-\n\
-/*@TRAILER_BEGINS*/\n\
-	.weak	__gmon_start__#\n\
-");
+__asm__ ("\n\n"
+"#include \"defs.h\"\n"
+"\n"
+"/*@HEADER_ENDS*/\n"
+"\n"
+"/*@_init_PROLOG_BEGINS*/\n");
+
+#ifdef HAVE_INITFINI_ARRAY
+
+/* If we have working .init_array support, we want to keep the .init
+   section empty (apart from the mandatory prologue/epilogue.  This
+   ensures that the default unwind conventions (return-pointer in b0,
+   frame state in ar.pfs, etc.)  will do the Right Thing.  To ensure
+   an empty .init section, we register gmon_initializer() via the
+   .init_array.
+
+	--davidm 02/10/29 */
+
+static void
+gmon_initializer (void)
+{
+  extern void weak_function __gmon_start__ (void);
+
+  if (__gmon_start__)
+    (*__gmon_start__)();
+}
+
+__asm__ (".section .init_array, \"aw\"\n"
+	 "\tdata8 @fptr(gmon_initializer)\n");
+
+#endif
+
+__asm__ (".section .init\n"
+"	.align 16\n"
+"	.global _init#\n"
+"	.proc _init#\n"
+"_init:\n"
+"	alloc r34 = ar.pfs, 0, 3, 0, 0\n"
+"	mov r32 = r12\n"
+"	mov r33 = b0\n"
+"	adds r12 = -16, r12\n"
+#ifdef HAVE_INITFINI_ARRAY
+ "	;;\n"		/* see gmon_initializer() below */
+#else
+"	.weak	__gmon_start__#\n"
+"	addl r14 = @ltoff(@fptr(__gmon_start__#)), gp\n"
+"	;;\n"
+"	ld8 r15 = [r14]\n"
+"	;;\n"
+"	cmp.eq p6, p7 = 0, r15\n"
+"	(p6) br.cond.dptk .L5\n"
+"\n"
+"/* we could use r35 to save gp, but we use the stack since that's what\n"
+" * all the other init routines will do --davidm 00/04/05 */\n"
+"	st8 [r12] = gp, -16\n"
+"	br.call.sptk.many b0 = __gmon_start__# ;;\n"
+"	adds r12 = 16, r12\n"
+"	;;\n"
+"	ld8 gp = [r12]\n"
+"	;;\n"
+".L5:\n"
+#endif
+"	.align 16\n"
+"	.endp _init#\n"
+"\n"
+"/*@_init_PROLOG_ENDS*/\n"
+"\n"
+"/*@_init_EPILOG_BEGINS*/\n"
+"	.section .init\n"
+"	.regstk 0,2,0,0\n"
+"	mov r12 = r32\n"
+"	mov ar.pfs = r34\n"
+"	mov b0 = r33\n"
+"	br.ret.sptk.many b0\n"
+"	.endp _init#\n"
+"/*@_init_EPILOG_ENDS*/\n"
+"\n"
+"/*@_fini_PROLOG_BEGINS*/\n"
+"	.section .fini\n"
+"	.align 16\n"
+"	.global _fini#\n"
+"	.proc _fini#\n"
+"_fini:\n"
+"	alloc r34 = ar.pfs, 0, 3, 0, 0\n"
+"	mov r32 = r12\n"
+"	mov r33 = b0\n"
+"	adds r12 = -16, r12\n"
+"	;;\n"
+"	.align 16\n"
+"	.endp _fini#\n"
+"\n"
+"/*@_fini_PROLOG_ENDS*/\n"
+"	br.call.sptk.many b0 = i_am_not_a_leaf# ;;\n"
+"	;;\n"
+"\n"
+"/*@_fini_EPILOG_BEGINS*/\n"
+"	.section .fini\n"
+"	mov r12 = r32\n"
+"	mov ar.pfs = r34\n"
+"	mov b0 = r33\n"
+"	br.ret.sptk.many b0\n"
+"	.endp _fini#\n"
+"\n"
+"/*@_fini_EPILOG_ENDS*/\n"
+"\n"
+"/*@TRAILER_BEGINS*/\n"
+);