From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8038 invoked by alias); 14 Jun 2011 22:06:03 -0000 Received: (qmail 8019 invoked by uid 22791); 14 Jun 2011 22:06:01 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-qy0-f175.google.com (HELO mail-qy0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Jun 2011 22:05:46 +0000 Received: by qyk35 with SMTP id 35so1714674qyk.20 for ; Tue, 14 Jun 2011 15:05:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.106.34 with SMTP id v34mr5448436qco.111.1308089144723; Tue, 14 Jun 2011 15:05:44 -0700 (PDT) Received: by 10.229.47.78 with HTTP; Tue, 14 Jun 2011 15:05:44 -0700 (PDT) Date: Tue, 14 Jun 2011 22:39:00 -0000 Message-ID: Subject: PING: PATCH: PR other/49325: Incorrect target HAVE_INITFINI_ARRAY check From: "H.J. Lu" To: DJ Delorie , Alexandre Oliva Cc: gcc-patches@gcc.gnu.org, bonzini@gnu.org, Ralf.Wildenhues@gmx.de Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg01118.txt.bz2 On Wed, Jun 8, 2011 at 9:49 AM, H.J. Lu wrote: > Hi, > > Target HAVE_INITFINI_ARRAY support was added by: > > http://gcc.gnu.org/ml/gcc-patches/2002-11/msg00387.html > > Unfortunately, it checks if host supports init_array/fini_array > sections, not target. =A0It will generate wrong result for cross compiler. > > This patch uses the target compiler instead of host compiler to check > this feature. =A0For ia64, we set HAVE_INITFINI_ARRAY to 1 if > init_array/fini_array section can be used. =A0For other targets, we > set it only if we can mix init_array/fini_array sections with > ctors/dtors sections. =A0OK for trunk? > > Thanks. > > > H.J. > --- > 2011-06-07 =A0H.J. Lu =A0 > > =A0 =A0 =A0 =A0PR other/49325 > =A0 =A0 =A0 =A0* acinclude.m4 (gcc_AC_INITFINI_ARRAY): Removed. > > =A0 =A0 =A0 =A0* configure.ac: Remove gcc_AC_INITFINI_ARRAY. =A0Add > =A0 =A0 =A0 =A0--enable-initfini-array and check if .init_array can be us= ed with > =A0 =A0 =A0 =A0.ctors. > =A0 =A0 =A0 =A0* configure: Regenerated. > > diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4 > index 3eec559..0f5f686 100644 > --- a/gcc/acinclude.m4 > +++ b/gcc/acinclude.m4 > @@ -369,26 +369,6 @@ else > =A0fi > =A0fi]) > > -AC_DEFUN([gcc_AC_INITFINI_ARRAY], > -[AC_ARG_ENABLE(initfini-array, > - =A0 =A0 =A0 [ =A0--enable-initfini-array =A0 =A0 =A0use .init_array/.fi= ni_array sections], > - =A0 =A0 =A0 [], [ > -AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gcc_cv_initfini_array, [dnl > - =A0AC_RUN_IFELSE([AC_LANG_SOURCE([ > -static int x =3D -1; > -int main (void) { return x; } > -int foo (void) { x =3D 0; } > -int (*fp) (void) __attribute__ ((section (".init_array"))) =3D foo;])], > - =A0 =A0 =A0 =A0 =A0 =A0[gcc_cv_initfini_array=3Dyes], [gcc_cv_initfini_= array=3Dno], > - =A0 =A0 =A0 =A0 =A0 =A0[gcc_cv_initfini_array=3Dno])]) > - =A0enable_initfini_array=3D$gcc_cv_initfini_array > -]) > -if test $enable_initfini_array =3D yes; then > - =A0AC_DEFINE(HAVE_INITFINI_ARRAY, 1, > - =A0 =A0[Define .init_array/.fini_array sections are available and worki= ng.]) > -fi]) > - > =A0dnl # _gcc_COMPUTE_GAS_VERSION > =A0dnl # Used by gcc_GAS_VERSION_GTE_IFELSE > =A0dnl # > diff --git a/gcc/configure b/gcc/configure > index a373518..a23e2fa 100755 > --- a/gcc/configure > +++ b/gcc/configure > @@ -10447,6 +10447,7 @@ fi > =A0# Restore CFLAGS from before the gcc_AC_NEED_DECLARATIONS tests. > =A0CFLAGS=3D"$saved_CFLAGS" > > +# Check if .init_array can be used with .ctors. > =A0# Check whether --enable-initfini-array was given. > =A0if test "${enable_initfini_array+set}" =3D set; then : > =A0 enableval=3D$enable_initfini_array; > @@ -10457,16 +10458,114 @@ $as_echo_n "checking for .preinit_array/.init_= array/.fini_array support... " >&6 > =A0if test "${gcc_cv_initfini_array+set}" =3D set; then : > =A0 $as_echo_n "(cached) " >&6 > =A0else > + =A0 =A0if test "x${build}" =3D "x${target}" ; then > =A0 =A0 if test "$cross_compiling" =3D yes; then : > =A0 gcc_cv_initfini_array=3Dno > =A0else > =A0 cat confdefs.h - <<_ACEOF >conftest.$ac_ext > =A0/* end confdefs.h. =A0*/ > > +#ifdef __ia64__ > +/* We turn on .preinit_array/.init_array/.fini_array support for ia64 > + =A0 if it can be used. =A0*/ > =A0static int x =3D -1; > =A0int main (void) { return x; } > =A0int foo (void) { x =3D 0; } > =A0int (*fp) (void) __attribute__ ((section (".init_array"))) =3D foo; > +#else > +extern void abort (); > +static int count; > + > +static void > +init1005 () > +{ > + =A0if (count !=3D 0) > + =A0 =A0abort (); > + =A0count =3D 1005; > +} > +void (*const init_array1005) () > + =A0__attribute__ ((section (".init_array.01005"), aligned (sizeof (void= *)))) > + =A0=3D { init1005 }; > +static void > +fini1005 () > +{ > + =A0if (count !=3D 1005) > + =A0 =A0abort (); > +} > +void (*const fini_array1005) () > + =A0__attribute__ ((section (".fini_array.01005"), aligned (sizeof (void= *)))) > + =A0=3D { fini1005 }; > + > +static void > +ctor1007 () > +{ > + =A0if (count !=3D 1005) > + =A0 =A0abort (); > + =A0count =3D 1007; > +} > +void (*const ctors1007) () > + =A0__attribute__ ((section (".ctors.64528"), aligned (sizeof (void *)))) > + =A0=3D { ctor1007 }; > +static void > +dtor1007 () > +{ > + =A0if (count !=3D 1007) > + =A0 =A0abort (); > + =A0count =3D 1005; > +} > +void (*const dtors1007) () > + =A0__attribute__ ((section (".dtors.64528"), aligned (sizeof (void *)))) > + =A0=3D { dtor1007 }; > + > +static void > +init65530 () > +{ > + =A0if (count !=3D 1007) > + =A0 =A0abort (); > + =A0count =3D 65530; > +} > +void (*const init_array65530) () > + =A0__attribute__ ((section (".init_array.65530"), aligned (sizeof (void= *)))) > + =A0=3D { init65530 }; > +static void > +fini65530 () > +{ > + =A0if (count !=3D 65530) > + =A0 =A0abort (); > + =A0count =3D 1007; > +} > +void (*const fini_array65530) () > + =A0__attribute__ ((section (".fini_array.65530"), aligned (sizeof (void= *)))) > + =A0=3D { fini65530 }; > + > +static void > +ctor65535 () > +{ > + =A0if (count !=3D 65530) > + =A0 =A0abort (); > + =A0count =3D 65535; > +} > +void (*const ctors65535) () > + =A0__attribute__ ((section (".ctors"), aligned (sizeof (void *)))) > + =A0=3D { ctor65535 }; > +static void > +dtor65535 () > +{ > + =A0if (count !=3D 65535) > + =A0 =A0abort (); > + =A0count =3D 65530; > +} > +void (*const dtors65535) () > + =A0__attribute__ ((section (".dtors"), aligned (sizeof (void *)))) > + =A0=3D { dtor65535 }; > + > +int > +main () > +{ > + =A0return 0; > +} > +#endif > + > =A0_ACEOF > =A0if ac_fn_c_try_run "$LINENO"; then : > =A0 gcc_cv_initfini_array=3Dyes > @@ -10477,6 +10576,9 @@ rm -f core *.core core.conftest.* gmon.out bb.out= conftest$ac_exeext \ > =A0 conftest.$ac_objext conftest.beam conftest.$ac_ext > =A0fi > > + =A0 else > + =A0 =A0 gcc_cv_initfini_array=3Dno > + =A0 fi > =A0fi > =A0{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_initfini_arra= y" >&5 > =A0$as_echo "$gcc_cv_initfini_array" >&6; } > @@ -17517,7 +17619,7 @@ else > =A0 lt_dlunknown=3D0; lt_dlno_uscore=3D1; lt_dlneed_uscore=3D2 > =A0 lt_status=3D$lt_dlunknown > =A0 cat > conftest.$ac_ext <<_LT_EOF > -#line 17520 "configure" > +#line 17622 "configure" > =A0#include "confdefs.h" > > =A0#if HAVE_DLFCN_H > @@ -17623,7 +17725,7 @@ else > =A0 lt_dlunknown=3D0; lt_dlno_uscore=3D1; lt_dlneed_uscore=3D2 > =A0 lt_status=3D$lt_dlunknown > =A0 cat > conftest.$ac_ext <<_LT_EOF > -#line 17626 "configure" > +#line 17728 "configure" > =A0#include "confdefs.h" > > =A0#if HAVE_DLFCN_H > diff --git a/gcc/configure.ac b/gcc/configure.ac > index 5e41479..0347b43 100644 > --- a/gcc/configure.ac > +++ b/gcc/configure.ac > @@ -1134,7 +1134,126 @@ fi > =A0# Restore CFLAGS from before the gcc_AC_NEED_DECLARATIONS tests. > =A0CFLAGS=3D"$saved_CFLAGS" > > -gcc_AC_INITFINI_ARRAY > +# Check if .init_array can be used with .ctors. > +AC_ARG_ENABLE(initfini-array, > + =A0 =A0 =A0 [ =A0--enable-initfini-array =A0 =A0 =A0use .init_array/.fi= ni_array sections], > + =A0 =A0 =A0 [], [ > +AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gcc_cv_initfini_array, [dnl > + =A0if test "x${build}" =3D "x${target}" ; then > + =A0 =A0AC_RUN_IFELSE([AC_LANG_SOURCE([ > +#ifdef __ia64__ > +/* We turn on .preinit_array/.init_array/.fini_array support for ia64 > + =A0 if it can be used. =A0*/ > +static int x =3D -1; > +int main (void) { return x; } > +int foo (void) { x =3D 0; } > +int (*fp) (void) __attribute__ ((section (".init_array"))) =3D foo; > +#else > +extern void abort (); > +static int count; > + > +static void > +init1005 () > +{ > + =A0if (count !=3D 0) > + =A0 =A0abort (); > + =A0count =3D 1005; > +} > +void (*const init_array1005[]) () > + =A0__attribute__ ((section (".init_array.01005"), aligned (sizeof (void= *)))) > + =A0=3D { init1005 }; > +static void > +fini1005 () > +{ > + =A0if (count !=3D 1005) > + =A0 =A0abort (); > +} > +void (*const fini_array1005[]) () > + =A0__attribute__ ((section (".fini_array.01005"), aligned (sizeof (void= *)))) > + =A0=3D { fini1005 }; > + > +static void > +ctor1007 () > +{ > + =A0if (count !=3D 1005) > + =A0 =A0abort (); > + =A0count =3D 1007; > +} > +void (*const ctors1007[]) () > + =A0__attribute__ ((section (".ctors.64528"), aligned (sizeof (void *)))) > + =A0=3D { ctor1007 }; > +static void > +dtor1007 () > +{ > + =A0if (count !=3D 1007) > + =A0 =A0abort (); > + =A0count =3D 1005; > +} > +void (*const dtors1007[]) () > + =A0__attribute__ ((section (".dtors.64528"), aligned (sizeof (void *)))) > + =A0=3D { dtor1007 }; > + > +static void > +init65530 () > +{ > + =A0if (count !=3D 1007) > + =A0 =A0abort (); > + =A0count =3D 65530; > +} > +void (*const init_array65530[]) () > + =A0__attribute__ ((section (".init_array.65530"), aligned (sizeof (void= *)))) > + =A0=3D { init65530 }; > +static void > +fini65530 () > +{ > + =A0if (count !=3D 65530) > + =A0 =A0abort (); > + =A0count =3D 1007; > +} > +void (*const fini_array65530[]) () > + =A0__attribute__ ((section (".fini_array.65530"), aligned (sizeof (void= *)))) > + =A0=3D { fini65530 }; > + > +static void > +ctor65535 () > +{ > + =A0if (count !=3D 65530) > + =A0 =A0abort (); > + =A0count =3D 65535; > +} > +void (*const ctors65535[]) () > + =A0__attribute__ ((section (".ctors"), aligned (sizeof (void *)))) > + =A0=3D { ctor65535 }; > +static void > +dtor65535 () > +{ > + =A0if (count !=3D 65535) > + =A0 =A0abort (); > + =A0count =3D 65530; > +} > +void (*const dtors65535[]) () > + =A0__attribute__ ((section (".dtors"), aligned (sizeof (void *)))) > + =A0=3D { dtor65535 }; > + > +int > +main () > +{ > + =A0return 0; > +} > +#endif > +])], > + =A0 =A0 =A0 =A0 =A0 =A0[gcc_cv_initfini_array=3Dyes], [gcc_cv_initfini_= array=3Dno], > + =A0 =A0 =A0 =A0 =A0 =A0[gcc_cv_initfini_array=3Dno]) > + =A0 else > + =A0 =A0 gcc_cv_initfini_array=3Dno > + =A0 fi]) > + =A0enable_initfini_array=3D$gcc_cv_initfini_array > +]) > +if test $enable_initfini_array =3D yes; then > + =A0AC_DEFINE(HAVE_INITFINI_ARRAY, 1, > + =A0 =A0[Define .init_array/.fini_array sections are available and worki= ng.]) > +fi > > =A0# mkdir takes a single argument on some systems. > =A0gcc_AC_FUNC_MKDIR_TAKES_ONE_ARG > PING. --=20 H.J.