This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] take advantage of init_array/fini_array on ia64 (v3)patch)


>>>>> On Wed, 30 Oct 2002 00:52:24 +0100 (CET), Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at> said:

  Gerald> Without looking at the actual code, this patch is not okay.
  Gerald> At the very least it lacks proper documentation.

  Gerald> (As a rule of thumb, if you add configure or command-line
  Gerald> options, you also need at least one .texi file appear in the
  Gerald> ChangeLog.)

Fair enough.  The attached patch has been updated to document
--enable-initini-array in doc/install.texi.

If the patch looks OK now, please apply.

Thanks,

	--david

2002-10-29  David Mosberger  <davidm@hpl.hp.com>

	* doc/install.texi (Configuration): Document configure option
	--enable-initfini-array.

	* config/ia64/t-initarray (ARRAY): New file.

	* config/ia64/t-ia64 (crtbegin.o): Append $(ARRAY) to name
	of source file to select between crtbegin.asm and crtbegin-array.asm,
	depending on whether or not init_array/fini_array should be used.
	(crtend.o): Ditto.

	* config/ia64/crtend-array.asm: New file.  Identical to
	crtend.asm, except for its use of .fini_array instead of .fini.

	* config/ia64/crtbegin-array.asm: New file.  Identical to
	crtbegin.asm, except for its use of .init_array instead of .init.

	* 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.

	* config.gcc: If gcc_cv_initfinit_array is "yes", add
	ia64/t-initarray as a Makefile-fragment in front of ia64/t-ia64.

	* 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	30 Oct 2002 03:31:22 -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.gcc
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.257
diff -u -r1.257 config.gcc
--- config.gcc	28 Oct 2002 17:20:35 -0000	1.257
+++ config.gcc	30 Oct 2002 03:31:22 -0000
@@ -1399,6 +1399,9 @@
 ia64*-*-linux*)
 	tm_file="${tm_file} dbxelf.h elfos.h svr4.h linux.h ia64/sysv4.h ia64/linux.h"
 	tmake_file="t-slibgcc-elf-ver t-linux ia64/t-ia64 ia64/t-glibc"
+	if test x"$gcc_cv_initfinit_array" = xyes; then
+	  tmake_file="ia64/t-initarray $tmake_file"
+	fi
 	target_cpu_default="MASK_GNU_AS|MASK_GNU_LD"
 	extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtfastmath.o"
 	;;
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	30 Oct 2002 03:31:23 -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-array.asm
===================================================================
RCS file: config/ia64/crtbegin-array.asm
diff -N config/ia64/crtbegin-array.asm
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/ia64/config/ia64/crtbegin-array.asm	30 Oct 2002 03:31:23 -0000
@@ -0,0 +1,207 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Contributed by Jes Sorensen, <Jes.Sorensen@cern.ch>
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+.section .ctors,"aw","progbits"
+	.align	8
+__CTOR_LIST__:
+	data8	-1
+
+.section .dtors,"aw","progbits"
+	.align	8
+__DTOR_LIST__:
+	data8	-1
+
+.section .jcr,"aw","progbits"
+	.align	8
+__JCR_LIST__:
+
+.section .sdata
+	.type dtor_ptr#,@object
+	.size dtor_ptr#,8
+dtor_ptr:
+	data8	@gprel(__DTOR_LIST__# + 8)
+
+	/* A handle for __cxa_finalize to manage c++ local destructors.  */
+	.global __dso_handle#
+	.type __dso_handle#,@object
+	.size __dso_handle#,8
+#ifdef SHARED
+	.section .data
+__dso_handle:
+	data8	__dso_handle#
+#else
+	.section .bss
+__dso_handle:
+	data8	0
+#endif
+	.hidden __dso_handle#
+
+
+.section .fini_array,"a","progbits"
+	data8 @fptr(__do_global_dtors_aux)
+
+/* Likewise for _init.  */
+
+.section .init_array,"a","progbits"
+	data8 @fptr(__do_jv_register_classes)
+
+.section .text
+	.align	16
+	.proc	__do_global_dtors_aux
+__do_global_dtors_aux:
+#ifndef SHARED
+	{ .mii
+	  alloc loc3 = ar.pfs, 0, 4, 1, 0
+	  addl loc0 = @gprel(dtor_ptr#), gp
+	  mov loc1 = b0
+	}
+	{ .mib
+	  mov loc2 = gp
+	  br.sptk.few 1f
+	  ;;
+	}
+#else
+	/*
+		if (__cxa_finalize)
+		  __cxa_finalize(__dso_handle)
+	*/
+	{ .mii
+	  alloc loc3 = ar.pfs, 0, 4, 1, 0
+	  addl loc0 = @gprel(dtor_ptr#), gp
+	  addl r16 = @ltoff(@fptr(__cxa_finalize#)), gp
+	  ;;
+	}
+	{ .mmi
+	  ld8 r16 = [r16]
+	  ;;
+	  addl out0 = @ltoff(__dso_handle#), gp
+	  cmp.ne p7, p0 = r0, r16
+	  ;;
+	}
+	{ .mmi
+	  ld8 out0 = [out0]
+(p7)	  ld8 r18 = [r16], 8
+	  mov loc1 = b0
+	  ;;
+	}
+	{ .mfi
+	  mov loc2 = gp
+(p7)	  mov b6 = r18
+	}
+	{
+	  .mfb
+(p7)	  ld8 gp = [r16]
+(p7)	  br.call.sptk.many b0 = b6
+	}
+	{ .mfb
+	  br.sptk.few 1f
+	}
+#endif
+	/*
+		do {
+		  dtor_ptr++;
+		  (*(dtor_ptr-1)) ();
+		} while (dtor_ptr);
+	*/
+0:
+	{ .mmi
+	  st8 [loc0] = r15
+	  ld8 r17 = [r16], 8
+	  ;;
+	}
+	{ .mib
+	  ld8 gp = [r16]
+	  mov b6 = r17
+	  br.call.sptk.many b0 = b6
+	}
+1:
+	{ .mmi
+	  ld8 r15 = [loc0]
+	  ;;
+	  add r16 = r15, loc2
+	  adds r15 = 8, r15
+	  ;;
+	}
+	{ .mmi
+	  ld8 r16 = [r16]
+	  mov gp = loc2
+	  mov b0 = loc1
+	  ;;
+	}
+	{ .mib
+	  cmp.ne p6, p0 = r0, r16
+	  mov ar.pfs = loc3
+(p6)	  br.cond.sptk.few 0b
+	}
+	{ .bbb
+	  br.ret.sptk.many b0
+	  ;;
+	}
+	.endp	__do_global_dtors_aux
+
+	.align	16
+	.proc	__do_jv_register_classes#
+__do_jv_register_classes:
+	{ .mlx
+	  alloc loc2 = ar.pfs, 0, 3, 1, 0
+	  movl out0 = @gprel(__JCR_LIST__)
+	  ;;
+	}
+	{ .mmi
+	  addl r14 = @ltoff(@fptr(_Jv_RegisterClasses)), gp
+	  add out0 = out0, gp
+	  ;;
+	}
+	{ .mmi
+	  ld8 r14 = [r14]
+	  ld8 r15 = [out0]
+	  cmp.ne p6, p0 = r0, r0
+	  ;;
+	}
+	{ .mib
+	  cmp.eq.or p6, p0 = r0, r14
+	  cmp.eq.or p6, p0 = r0, r15
+(p6)	  br.ret.sptk.many b0
+	}
+	{ .mii
+	  ld8 r15 = [r14], 8
+	  mov loc0 = b0
+	  mov loc1 = gp
+	  ;;
+	}
+	{ .mib
+	  ld8 gp = [r14]
+	  mov b6 = r15
+	  br.call.sptk.many b0 = b6
+	  ;;
+	}
+	{ .mii
+	  mov gp = loc1
+	  mov b0 = loc0
+	  mov ar.pfs = loc2
+	}
+	{ .bbb
+	  br.ret.sptk.many b0
+	  ;;
+	}
+	.endp	__do_jv_register_classes#
+
+#ifdef SHARED
+.weak __cxa_finalize#
+#endif
+.weak _Jv_RegisterClasses
Index: config/ia64/crtend-array.asm
===================================================================
RCS file: config/ia64/crtend-array.asm
diff -N config/ia64/crtend-array.asm
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/ia64/config/ia64/crtend-array.asm	30 Oct 2002 03:31:23 -0000
@@ -0,0 +1,91 @@
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Contributed by Jes Sorensen, <Jes.Sorensen@cern.ch>
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+.section .ctors,"aw","progbits"
+	.align	8
+__CTOR_END__:
+	data8	0
+
+.section .dtors,"aw","progbits"
+	.align 8
+__DTOR_END__:
+	data8	0
+
+.section .jcr,"aw","progbits"
+	.align 8
+__JCR_END__:
+	data8	0
+
+.section .init_array,"a","progbits"
+	data8 @fptr(__do_global_ctors_aux)
+
+.text
+	.align 16
+	.proc __do_global_ctors_aux
+__do_global_ctors_aux:
+	/*
+		for (loc0 = __CTOR_END__-1; *p != -1; --p)
+		  (*p) ();
+	*/
+	{ .mlx
+	  alloc loc4 = ar.pfs, 0, 5, 0, 0
+	  movl loc0 = @gprel(__CTOR_END__# - 8)
+	  ;;
+	}
+	{ .mmi
+	  add loc0 = loc0, gp
+	  mov loc1 = b0
+	  ;;
+	}
+	{
+	  .mmi
+	  ld8 loc3 = [loc0], -8
+	  mov loc2 = gp
+	  ;;
+	}
+	{ .mfb
+	  cmp.eq p6, p0 = -1, loc3
+(p6)	  br.cond.spnt.few 2f
+	}
+0:
+	{ .mmi
+	  ld8 r15 = [loc3], 8
+	  ;;
+	  ld8 gp = [loc3]
+	  mov b6 = r15
+	}
+	{ .mfb
+	  ld8 loc3 = [loc0], -8
+	  br.call.sptk.many b0 = b6
+	  ;;
+	}
+	{ .mfb
+	  cmp.ne p6, p0 = -1, loc3
+(p6)	  br.cond.sptk.few 0b
+	}
+2:
+	{ .mii
+	  mov gp = loc2
+	  mov b0 = loc1
+	  mov ar.pfs = loc4
+	}
+	{ .bbb
+	  br.ret.sptk.many b0
+	  ;;
+	}
+	.endp __do_global_ctors_aux
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	30 Oct 2002 03:31:23 -0000
@@ -23,16 +23,22 @@
 T = disable
 
 # 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
-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
-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
-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
+crtbegin.o: $(srcdir)/config/ia64/crtbegin$(ARRAY).asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) -c -o crtbegin.o -x assembler-with-cpp \
+		$(srcdir)/config/ia64/crtbegin$(ARRAY).asm
+crtend.o: $(srcdir)/config/ia64/crtend$(ARRAY).asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) -c -o crtend.o -x assembler-with-cpp \
+		$(srcdir)/config/ia64/crtend$(ARRAY).asm
+crtbeginS.o: $(srcdir)/config/ia64/crtbegin$(ARRAY).asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) -DSHARED -c -o crtbeginS.o \
+		-x assembler-with-cpp \
+		$(srcdir)/config/ia64/crtbegin$(ARRAY).asm
+crtendS.o: $(srcdir)/config/ia64/crtend$(ARRAY).asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) -DSHARED -c -o crtendS.o -x assembler-with-cpp \
+		$(srcdir)/config/ia64/crtend$(ARRAY).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: config/ia64/t-initarray
===================================================================
RCS file: config/ia64/t-initarray
diff -N config/ia64/t-initarray
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ config/ia64/config/ia64/t-initarray	30 Oct 2002 03:31:23 -0000
@@ -0,0 +1 @@
+ARRAY	= -array
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	30 Oct 2002 03:31:24 -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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]