This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
PATCH: Add a testcase and fix for .fini_array in static binary
- From: "H. J. Lu" <hjl at lucon dot org>
- To: GNU C Library <libc-alpha at sources dot redhat dot com>
- Date: Mon, 14 Feb 2005 12:21:22 -0800
- Subject: PATCH: Add a testcase and fix for .fini_array in static binary
- References: <20050209224744.GA963@lucon.org>
On Wed, Feb 09, 2005 at 02:47:44PM -0800, H. J. Lu wrote:
> .fini_array no longer works in static binary. This patch adds a
> testcase for it.
>
This patch fixes .fini_array in static binary. We have to call the
original __libc_csu_fini for static binaries.
H.J.
------
2005-02-14 H.J. Lu <hongjiu.lu@intel.com>
* csu/elf-init.c (__libc_csu_fini): Enable if LIBC_NONSHARED
isn't defined.
* elf/Makefile (tests-static): Add tst-array1-static.
($(objpfx)tst-array1-static.out): New target.
* elf/tst-array1-static.c: New file.
* sysdeps/generic/libc-start.c (LIBC_START_MAIN): Call fini
if SHARED isn't defined.
--- libc/csu/elf-init.c.static 2005-01-07 14:13:21.000000000 -0800
+++ libc/csu/elf-init.c 2005-02-14 10:04:54.200580726 -0800
@@ -92,7 +92,7 @@ __libc_csu_init (void)
void
__libc_csu_fini (void)
{
-#if 0
+#ifndef LIBC_NONSHARED
#ifdef HAVE_INITFINI_ARRAY
size_t i = __fini_array_end - __fini_array_start;
while (i-- > 0)
--- libc/elf/Makefile.static 2005-01-24 15:30:36.000000000 -0800
+++ libc/elf/Makefile 2005-02-14 10:04:54.000000000 -0800
@@ -138,6 +138,9 @@ tests += tst-array1 tst-array2 tst-array
endif
ifeq (yes,$(build-static))
tests-static = tst-tls1-static tst-tls2-static
+ifeq (yes,$(have-initfini-array))
+tests-static += tst-array1-static
+endif
ifeq (yesyesyes,$(build-static)$(build-shared)$(elf))
tests-static += tst-tls9-static
tst-tls9-static-ENV = \
@@ -701,6 +704,10 @@ $(objpfx)tst-array1.out: $(objpfx)tst-ar
$(objpfx)tst-array1 > $@
cmp $@ tst-array1.exp > /dev/null
+$(objpfx)tst-array1-static.out: $(objpfx)tst-array1-static
+ $(objpfx)tst-array1-static > $@
+ 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) \
--- libc/elf/tst-array1-static.c.static 2005-02-14 10:04:54.000000000 -0800
+++ libc/elf/tst-array1-static.c 2005-02-14 10:04:54.000000000 -0800
@@ -0,0 +1 @@
+#include "tst-array1.c"
--- libc/sysdeps/generic/libc-start.c.static 2005-01-07 14:13:47.000000000 -0800
+++ libc/sysdeps/generic/libc-start.c 2005-02-14 11:56:41.154994807 -0800
@@ -81,9 +81,9 @@ STATIC int LIBC_START_MAIN (int (*main)
__attribute__ ((noreturn));
-/* Note: the fini parameter is ignored here. It used to be registered
- with __cxa_atexit. This had the disadvantage that finalizers were
- called in more than one place. */
+/* Note: the fini parameter is ignored here for shared library. It
+ is registered with __cxa_atexit. This had the disadvantage that
+ finalizers were called in more than one place. */
STATIC int
LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
int argc, char *__unbounded *__unbounded ubp_av,
@@ -163,6 +163,12 @@ LIBC_START_MAIN (int (*main) (int, char
#endif
#ifndef SHARED
+ /* Register the destructor of the program, if any. */
+ if (fini)
+ __cxa_atexit ((void (*) (void *)) fini, NULL, NULL);
+#endif
+
+#ifndef SHARED
/* Some security at this point. Prevent starting a SUID binary where
the standard file descriptors are not opened. We have to do this
only for statically linked applications since otherwise the dynamic