This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] take advantage of init_array/fini_array on ia64 (v3)patch)
- From: David Mosberger <davidm at napali dot hpl dot hp dot com>
- To: rth at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org, davidm at hpl dot hp dot com
- Date: Wed, 6 Nov 2002 16:49:28 -0800
- Subject: Re: [PATCH] take advantage of init_array/fini_array on ia64 (v3)patch)
- References: <15807.7079.778664.473273@napali.hpl.hp.com><Pine.BSF.4.44.0210300051130.99072-100000@pulcherrima.dbai.tuwien.ac.at><15807.21248.588029.853709@napali.hpl.hp.com>
- Reply-to: davidm at hpl dot hp dot com
Here is a revised version of the init_array/fini_array patch. Richard
suggested to keep a single crtbegin.asm/crtend.asm file and to use a
macro in auto-host.h to determine whether the .init_array/.fini_array
sections are available.
If it looks OK, please apply.
Thanks,
--david
2002-11-06 David Mosberger <davidm@hpl.hp.com>
* config/ia64/t-ia64 (crtbegin.o): Include from current directory.
(crtend.o): Ditto.
(crtbeginS.o): Ditto.
(crtendS.o): Ditto.
* config/ia64/crtend.asm: Include "auto-host.h".
[HAVE_INITFINI_ARRAY]: Invoke __do_global_ctors_aux via .init_array
section.
* config/ia64/crtbegin.asm: Include "auto-host.h".
[HAVE_INITFINI_ARRAY]: Invoke __do_global_dtors_aux via .fini_array
section. Invoke __do_jv_register_classes via .init_array section.
* config.in: Mention HAVE_INITFINI_ARRAY.
2002-10-29 David Mosberger <davidm@hpl.hp.com>
* doc/install.texi (Configuration): Document configure option
--enable-initfini-array.
* configure.in: Add new configure option --enable-initfini-array.
If this option isn't specified, use gcc_AC_INITFINI_ARRAY to guess
a reasonable default value.
* aclocal.m4: New check that tests whether the (host) machine
handles .init_array/.fini_array sections.
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/aclocal.m4,v
retrieving revision 1.59
diff -u -r1.59 aclocal.m4
--- aclocal.m4 22 Jan 2002 22:48:45 -0000 1.59
+++ aclocal.m4 7 Nov 2002 00:38:55 -0000
@@ -1690,3 +1690,28 @@
INTL_LIBTOOL_SUFFIX_PREFIX=ifelse([$1], use-libtool, [l], [])
AC_SUBST(INTL_LIBTOOL_SUFFIX_PREFIX)
])
+
+AC_DEFUN(gcc_AC_INITFINI_ARRAY,
+[AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
+ gcc_cv_initfinit_array, [dnl
+ cat > conftest.c <<EOF
+static int x = -1;
+int main (void) { return x; }
+int foo (void) { x = 0; }
+int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
+EOF
+ if AC_TRY_COMMAND([${CC-cc} -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
+ then
+ if ./conftest; then
+ gcc_cv_initfinit_array=yes
+ else
+ gcc_cv_initfinit_array=no
+ fi
+ else
+ gcc_cv_initfinit_array=no
+ fi
+ rm -f conftest*])
+ AC_SUBST(gcc_cv_initfinit_array)
+ if test $gcc_cv_initfinit_array = yes; then
+ AC_DEFINE(HAVE_INITFINI_ARRAY)
+ fi])
Index: config.in
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config.in,v
retrieving revision 1.143
diff -u -r1.143 config.in
--- config.in 24 Oct 2002 23:22:46 -0000 1.143
+++ config.in 7 Nov 2002 00:38:57 -0000
@@ -591,6 +591,8 @@
/* Define if gcc should use -lunwind. */
#undef USE_LIBUNWIND_EXCEPTIONS
+/* Define .init_array/.fini_array sections are available and working. */
+#undef HAVE_INITFINI_ARRAY
/* Bison unconditionally undefines `const' if neither `__STDC__' nor
__cplusplus are defined. That's a problem since we use `const' in
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/configure.in,v
retrieving revision 1.621
diff -u -r1.621 configure.in
--- configure.in 24 Oct 2002 23:22:46 -0000 1.621
+++ configure.in 7 Nov 2002 00:38:57 -0000
@@ -744,6 +744,10 @@
[Define if <time.h> defines clock_t.])
fi
+AC_ARG_ENABLE(initfini-array,
+ [ --enable-initfini-array use .init_array/.fini_array sections],
+ gcc_cv_initfinit_array=$enableval, [gcc_AC_INITFINI_ARRAY])
+
# Restore CFLAGS from before the gcc_AC_NEED_DECLARATIONS tests.
CFLAGS="$saved_CFLAGS"
Index: config/ia64/crtbegin.asm
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/ia64/crtbegin.asm,v
retrieving revision 1.12
diff -u -r1.12 crtbegin.asm
--- config/ia64/config/ia64/crtbegin.asm 22 Aug 2001 02:10:53 -0000 1.12
+++ config/ia64/config/ia64/crtbegin.asm 7 Nov 2002 00:38:59 -0000
@@ -16,6 +16,8 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include "auto-host.h"
+
.section .ctors,"aw","progbits"
.align 8
__CTOR_LIST__:
@@ -52,6 +54,15 @@
.hidden __dso_handle#
+#ifdef HAVE_INITFINI_ARRAY
+
+.section .fini_array,"a","progbits"
+ data8 @fptr(__do_global_dtors_aux)
+
+.section .init_array,"a","progbits"
+ data8 @fptr(__do_jv_register_classes)
+
+#else /* !HAVE_INITFINI_ARRAY */
/*
* Fragment of the ELF _fini routine that invokes our dtor cleanup.
*
@@ -98,6 +109,7 @@
br.call.sptk.many b0 = b6
;;
}
+#endif /* !HAVE_INITFINI_ARRAY */
.section .text
.align 16
Index: config/ia64/crtend.asm
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/ia64/crtend.asm,v
retrieving revision 1.8
diff -u -r1.8 crtend.asm
--- config/ia64/config/ia64/crtend.asm 19 Aug 2001 04:46:25 -0000 1.8
+++ config/ia64/config/ia64/crtend.asm 7 Nov 2002 00:38:59 -0000
@@ -16,6 +16,8 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include "auto-host.h"
+
.section .ctors,"aw","progbits"
.align 8
__CTOR_END__:
@@ -31,6 +33,12 @@
__JCR_END__:
data8 0
+#ifdef HAVE_INITFINI_ARRAY
+
+.section .init_array,"a","progbits"
+ data8 @fptr(__do_global_ctors_aux)
+
+#else /* !HAVE_INITFINI_ARRAY */
/*
* Fragment of the ELF _init routine that invokes our dtor cleanup.
*
@@ -59,6 +67,7 @@
br.call.sptk.many b0 = b6
;;
}
+#endif /* !HAVE_INITFINI_ARRAY */
.text
.align 16
Index: config/ia64/t-ia64
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/ia64/t-ia64,v
retrieving revision 1.15
diff -u -r1.15 t-ia64
--- config/ia64/config/ia64/t-ia64 13 Sep 2002 21:12:18 -0000 1.15
+++ config/ia64/config/ia64/t-ia64 7 Nov 2002 00:39:00 -0000
@@ -24,15 +24,21 @@
# Assemble startup files.
crtbegin.o: $(srcdir)/config/ia64/crtbegin.asm $(GCC_PASSES)
- $(GCC_FOR_TARGET) -c -o crtbegin.o -x assembler-with-cpp $(srcdir)/config/ia64/crtbegin.asm
+ $(GCC_FOR_TARGET) -I. -c -o crtbegin.o -x assembler-with-cpp \
+ $(srcdir)/config/ia64/crtbegin.asm
crtend.o: $(srcdir)/config/ia64/crtend.asm $(GCC_PASSES)
- $(GCC_FOR_TARGET) -c -o crtend.o -x assembler-with-cpp $(srcdir)/config/ia64/crtend.asm
+ $(GCC_FOR_TARGET) -I. -c -o crtend.o -x assembler-with-cpp \
+ $(srcdir)/config/ia64/crtend.asm
crtbeginS.o: $(srcdir)/config/ia64/crtbegin.asm $(GCC_PASSES)
- $(GCC_FOR_TARGET) -DSHARED -c -o crtbeginS.o -x assembler-with-cpp $(srcdir)/config/ia64/crtbegin.asm
+ $(GCC_FOR_TARGET) -I. -DSHARED -c -o crtbeginS.o \
+ -x assembler-with-cpp \
+ $(srcdir)/config/ia64/crtbegin.asm
crtendS.o: $(srcdir)/config/ia64/crtend.asm $(GCC_PASSES)
- $(GCC_FOR_TARGET) -DSHARED -c -o crtendS.o -x assembler-with-cpp $(srcdir)/config/ia64/crtend.asm
+ $(GCC_FOR_TARGET) -I. -DSHARED -c -o crtendS.o -x assembler-with-cpp \
+ $(srcdir)/config/ia64/crtend.asm
crtfastmath.o: $(srcdir)/config/ia64/crtfastmath.c $(GCC_PASSES)
- $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -c -o crtfastmath.o $(srcdir)/config/ia64/crtfastmath.c
+ $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -c -o crtfastmath.o \
+ $(srcdir)/config/ia64/crtfastmath.c
LIB2ADDEH = $(srcdir)/config/ia64/unwind-ia64.c $(srcdir)/unwind-sjlj.c
Index: doc/install.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.145
diff -u -r1.145 install.texi
--- doc/doc/install.texi 24 Oct 2002 20:32:28 -0000 1.145
+++ doc/doc/install.texi 7 Nov 2002 00:39:00 -0000
@@ -740,6 +740,14 @@
Specify that the user visible @command{cpp} program should be installed
in @file{@var{prefix}/@var{dirname}/cpp}, in addition to @var{bindir}.
+@item --enable-initfini-array
+Force the use of sections @code{.init_array} and @code{.fini_array}
+(instead of @code{.init} and @code{.fini}) for constructors and
+destructors. Option @option{--disable-initfini-array} has the
+opposite effect. If neither option is specified, the configure script
+will try to guess whether the @code{.init_array} and
+@code{.fini_array} sections are supported and, if they are, use them.
+
@item --enable-maintainer-mode
The build rules that
regenerate the GCC master message catalog @file{gcc.pot} are normally