[v2] Always enable DT_INIT_ARRAY/DT_FINI_ARRAY on Linux

Message ID CAMe9rOrmatVu9-6AQrLV3_tuLpc6UPJN_xyxpR5CYnZ3x8=xyw@mail.gmail.com
State New
Headers show
Series
  • [v2] Always enable DT_INIT_ARRAY/DT_FINI_ARRAY on Linux
Related show

Commit Message

Aaron Sawdey via Gcc-patches June 9, 2021, 12:05 p.m.
On Wed, Jun 9, 2021 at 4:00 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>

> On Wed, Jun 9, 2021 at 1:13 AM H.J. Lu via Gcc-patches

> <gcc-patches@gcc.gnu.org> wrote:

> >

> > DT_INIT_ARRAY/DT_FINI_ARRAY support was added to glibc by

> >

> > commit fcf70d4114db9ff7923f5dfeb3fea6e2d623e5c2

> > Author: Ulrich Drepper <drepper@redhat.com>

> > Date:   Sat Jul 24 19:45:13 1999 +0000

> >

> >     Update.

> >

> >     1999-07-24  Ulrich Drepper  <drepper@cygnus.com>

> >

> >             * elf/dl-fini.c: Handle DT_FINI_ARRAY.

> >             * elf/link.h (struct link_map): Remove l_init_running.  Add l_runcount

> >             and l_initcount.

> >             * elf/dl-init.c: Handle DT_INIT_ARRAY.

> > ...

> >

> >         PR target/100896

> >         * config.gcc (gcc_cv_initfini_array): Set to yes for Linux and

> >         GNU targets.

> > ---

> >  gcc/config.gcc | 2 ++

> >  1 file changed, 2 insertions(+)

> >

> > diff --git a/gcc/config.gcc b/gcc/config.gcc

> > index 6833a6c13d9..4dc4fe0b65c 100644

> > --- a/gcc/config.gcc

> > +++ b/gcc/config.gcc

> > @@ -848,6 +848,8 @@ case ${target} in

> >    tmake_file="${tmake_file} t-glibc"

> >    target_has_targetcm=yes

> >    target_has_targetdm=yes

> > +  # Linux targets always support .init_array.

>

> Other *linux targets specifically mention

>

>         # Force .init_array support.  The configure script cannot always

>         # automatically detect that GAS supports it, yet we require it.

>         gcc_cv_initfini_array=yes

>

> and thus involve binutils.  Can you please change the comment

> to mention the glibc and binutils versions required?  It might


Done.  They are glibc 2.1 and binutils 2.12.

> be good to mention those in install.texi as minimal versions given


Fixed.

> they are not trumped by already stricter requirements.

>

> Otherwise I think this is OK.

>

> > +  gcc_cv_initfini_array=yes

> >    ;;

> >  *-*-netbsd*)

> >    tm_p_file="${tm_p_file} netbsd-protos.h"

> > --

> > 2.31.1

> >


Here is the v2 patch.  OK for master and release branches?

Thanks.

-- 
H.J.

Comments

Aaron Sawdey via Gcc-patches June 9, 2021, 12:11 p.m. | #1
On Wed, Jun 9, 2021 at 2:05 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>

> On Wed, Jun 9, 2021 at 4:00 AM Richard Biener

> <richard.guenther@gmail.com> wrote:

> >

> > On Wed, Jun 9, 2021 at 1:13 AM H.J. Lu via Gcc-patches

> > <gcc-patches@gcc.gnu.org> wrote:

> > >

> > > DT_INIT_ARRAY/DT_FINI_ARRAY support was added to glibc by

> > >

> > > commit fcf70d4114db9ff7923f5dfeb3fea6e2d623e5c2

> > > Author: Ulrich Drepper <drepper@redhat.com>

> > > Date:   Sat Jul 24 19:45:13 1999 +0000

> > >

> > >     Update.

> > >

> > >     1999-07-24  Ulrich Drepper  <drepper@cygnus.com>

> > >

> > >             * elf/dl-fini.c: Handle DT_FINI_ARRAY.

> > >             * elf/link.h (struct link_map): Remove l_init_running.  Add l_runcount

> > >             and l_initcount.

> > >             * elf/dl-init.c: Handle DT_INIT_ARRAY.

> > > ...

> > >

> > >         PR target/100896

> > >         * config.gcc (gcc_cv_initfini_array): Set to yes for Linux and

> > >         GNU targets.

> > > ---

> > >  gcc/config.gcc | 2 ++

> > >  1 file changed, 2 insertions(+)

> > >

> > > diff --git a/gcc/config.gcc b/gcc/config.gcc

> > > index 6833a6c13d9..4dc4fe0b65c 100644

> > > --- a/gcc/config.gcc

> > > +++ b/gcc/config.gcc

> > > @@ -848,6 +848,8 @@ case ${target} in

> > >    tmake_file="${tmake_file} t-glibc"

> > >    target_has_targetcm=yes

> > >    target_has_targetdm=yes

> > > +  # Linux targets always support .init_array.

> >

> > Other *linux targets specifically mention

> >

> >         # Force .init_array support.  The configure script cannot always

> >         # automatically detect that GAS supports it, yet we require it.

> >         gcc_cv_initfini_array=yes

> >

> > and thus involve binutils.  Can you please change the comment

> > to mention the glibc and binutils versions required?  It might

>

> Done.  They are glibc 2.1 and binutils 2.12.

>

> > be good to mention those in install.texi as minimal versions given

>

> Fixed.

>

> > they are not trumped by already stricter requirements.

> >

> > Otherwise I think this is OK.

> >

> > > +  gcc_cv_initfini_array=yes

> > >    ;;

> > >  *-*-netbsd*)

> > >    tm_p_file="${tm_p_file} netbsd-protos.h"

> > > --

> > > 2.31.1

> > >

>

> Here is the v2 patch.  OK for master and release branches?


OK for master, this isn't appropriate for release branches.

Richard.

> Thanks.

>

> --

> H.J.

Patch

From 1ab48e7abf836689581ce007d920649aecebd623 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 8 Jun 2021 16:09:24 -0700
Subject: [PATCH v2] Always enable DT_INIT_ARRAY/DT_FINI_ARRAY on Linux

DT_INIT_ARRAY/DT_FINI_ARRAY support was added to glibc 2.1 by

commit fcf70d4114db9ff7923f5dfeb3fea6e2d623e5c2
Author: Ulrich Drepper <drepper@redhat.com>
Date:   Sat Jul 24 19:45:13 1999 +0000

    Update.

    1999-07-24  Ulrich Drepper  <drepper@cygnus.com>

            * elf/dl-fini.c: Handle DT_FINI_ARRAY.
            * elf/link.h (struct link_map): Remove l_init_running.  Add l_runcount
            and l_initcount.
            * elf/dl-init.c: Handle DT_INIT_ARRAY.
...

and added to binutils 2.12 by

commit e9682144c14fc809af72bd6c0b8c69731d38679c
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Mar 4 20:40:48 2002 +0000

    2002-03-04  H.J. Lu <hjl@gnu.org>

            * config/obj-elf.c (special_section): Add .init_array,
            .fini_array and .preinit_array.

            * config/tc-ia64.h (ELF_TC_SPECIAL_SECTIONS): Remove
            .init_array and .fini_array.

gcc/

	PR target/100896
	* config.gcc (gcc_cv_initfini_array): Set to yes for Linux and
	GNU targets.
	* doc/install.texi: Require glibc 2.1 and binutils 2.12 for
	Linux and GNU targets.
---
 gcc/config.gcc       | 2 ++
 gcc/doc/install.texi | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6833a6c13d9..4dc4fe0b65c 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -848,6 +848,8 @@  case ${target} in
   tmake_file="${tmake_file} t-glibc"
   target_has_targetcm=yes
   target_has_targetdm=yes
+  # Linux targets always support .init_array.
+  gcc_cv_initfini_array=yes
   ;;
 *-*-netbsd*)
   tm_p_file="${tm_p_file} netbsd-protos.h"
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 591ccaacbc1..94b167a3ed3 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4126,6 +4126,9 @@  supported, so @option{--enable-threads=dce} does not work.
 @end html
 @anchor{x-x-linux-gnu}
 @heading *-*-linux-gnu
+The @code{.init_array} and @code{.fini_array} sections are enabled
+unconditionally which requires at least glibc 2.1 and binutils 2.12.
+
 Versions of libstdc++-v3 starting with 3.2.1 require bug fixes present
 in glibc 2.2.5 and later.  More information is available in the
 libstdc++-v3 documentation.
-- 
2.31.1