public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
       [not found] <m3g03lfd1g.fsf@myware.mynet>
@ 2002-02-28 17:10 ` H . J . Lu
  2002-02-28 17:28   ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-02-28 17:10 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: GNU libc hacker, binutils

On Thu, Feb 28, 2002 at 02:37:47PM -0800, Ulrich Drepper wrote:
> Another mail from David.  He'll eventually manage to get the mailing
> list handler to accept his machine.
> 

> From: David Mosberger <davidm@hpl.hp.com>
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> Message-ID: <15486.41523.514655.290242@napali.hpl.hp.com>
> Date: Thu, 28 Feb 2002 13:33:39 -0800
> To: <binutils@sources.redhat.com>
> Cc: "David Mosberger" <davidm@hpl.hp.com>, Cary Coutant <cary@cup.hp.com>,
>         <linux-ia64@linuxia64.org>, libc-hacker@sources.redhat.com
> Subject: Re: [Linux-ia64] problem with unwind info for .init/.fini sections
> In-Reply-To: <200202271920.LAA10765@adlmail.cup.hp.com>
> References: <200202271920.LAA10765@adlmail.cup.hp.com>
> X-Mailer: VM 7.01 under Emacs 21.1.1
> Reply-To: davidm@hpl.hp.com
> X-URL: http://www.hpl.hp.com/personal/David_Mosberger/
> MIME-Version: 1.0
> 
> >>>>> On Wed, 27 Feb 2002 11:19:30 -0800, Cary Coutant <cary@cup.hp.com> said:
> 
>   >> I can think of two approaches:
>   >> ...
>   >> Anybody else have a better idea or other comments?
> 
>   Cary> (3) Use the .init_array and .fini_array sections instead.
> 
> This would be by far the cleanest solution.
> 
> How well is this supported in binutils at the moment?  I see some
> references to it, but am not sure whether there are any holes in its
> support.
> 
> Are there any reasons *not* to switch to .init_array/.fini_array as
> the primary init/fini mechanism?  Besides fixing the unwind problem,
> it seems to me it's generally just a much cleaner solution and should
> allow us to get rid of some rather ugly hacks in glibc.
> 
> 	--david

I am not sure if .init_array/.fini_array are supported. It will be nice
to add them to binutils. 


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 17:10 ` [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections H . J . Lu
@ 2002-02-28 17:28   ` David Mosberger
  2002-02-28 17:33     ` Ulrich Drepper
  2002-02-28 17:43     ` H . J . Lu
  0 siblings, 2 replies; 54+ messages in thread
From: David Mosberger @ 2002-02-28 17:28 UTC (permalink / raw)
  To: H . J . Lu; +Cc: Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Thu, 28 Feb 2002 16:58:52 -0800, "H . J . Lu" <hjl@lucon.org> said:

  HJ> I am not sure if .init_array/.fini_array are supported. It will
  HJ> be nice to add them to binutils.

From my point of view, it's more worthwhile to spend time on getting
.init_array/.fini_array supported than trying to fix up .init/.fini.
I'm willing to help with such an effort, but I probably would need a
fair amount of help (or at least support) from the glibc and binutils
maintainers.  Anyone else willing to help with this?

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 17:28   ` David Mosberger
@ 2002-02-28 17:33     ` Ulrich Drepper
  2002-02-28 17:43     ` H . J . Lu
  1 sibling, 0 replies; 54+ messages in thread
From: Ulrich Drepper @ 2002-02-28 17:33 UTC (permalink / raw)
  To: davidm; +Cc: H . J . Lu, GNU libc hacker, binutils

David Mosberger <davidm@napali.hpl.hp.com> writes:

> but I probably would need a fair amount of help (or at least
> support) from the glibc and binutils maintainers.  Anyone else
> willing to help with this?

There should be nothing to be done in glibc.  Support is included for
ages.  Not tested, of course, put it's there.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 17:28   ` David Mosberger
  2002-02-28 17:33     ` Ulrich Drepper
@ 2002-02-28 17:43     ` H . J . Lu
  2002-02-28 17:54       ` David Mosberger
  1 sibling, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-02-28 17:43 UTC (permalink / raw)
  To: davidm; +Cc: Ulrich Drepper, GNU libc hacker, binutils

On Thu, Feb 28, 2002 at 05:19:35PM -0800, David Mosberger wrote:
> >>>>> On Thu, 28 Feb 2002 16:58:52 -0800, "H . J . Lu" <hjl@lucon.org> said:
> 
>   HJ> I am not sure if .init_array/.fini_array are supported. It will
>   HJ> be nice to add them to binutils.
> 
> >From my point of view, it's more worthwhile to spend time on getting
> .init_array/.fini_array supported than trying to fix up .init/.fini.
> I'm willing to help with such an effort, but I probably would need a
> fair amount of help (or at least support) from the glibc and binutils
> maintainers.  Anyone else willing to help with this?
> 

I believe glibc is ok. The problem is binutils. I didn't see any
supports for DT_INIT_ARRAY, DT_FINI_ARRAY. DT_INIT_ARRAYSZ,
DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY nor DT_PREINIT_ARRAYSZ.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 17:43     ` H . J . Lu
@ 2002-02-28 17:54       ` David Mosberger
  2002-02-28 18:01         ` Richard Henderson
  2002-02-28 18:11         ` H . J . Lu
  0 siblings, 2 replies; 54+ messages in thread
From: David Mosberger @ 2002-02-28 17:54 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Thu, 28 Feb 2002 17:33:11 -0800, "H . J . Lu" <hjl@lucon.org> said:

  HJ> I believe glibc is ok. The problem is binutils. I didn't see any
  HJ> supports for DT_INIT_ARRAY, DT_FINI_ARRAY. DT_INIT_ARRAYSZ,
  HJ> DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY nor DT_PREINIT_ARRAYSZ.

Shouldn't this be easy straight-forward to add?

I guess the other component that needs updating is gcc (at least the
ia64 versions of crtbegin.asm and crtend.asm would need that).  I'd be
happy to work on this.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 17:54       ` David Mosberger
@ 2002-02-28 18:01         ` Richard Henderson
  2002-02-28 18:05           ` David Mosberger
                             ` (2 more replies)
  2002-02-28 18:11         ` H . J . Lu
  1 sibling, 3 replies; 54+ messages in thread
From: Richard Henderson @ 2002-02-28 18:01 UTC (permalink / raw)
  To: davidm; +Cc: H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

On Thu, Feb 28, 2002 at 05:43:07PM -0800, David Mosberger wrote:
>   HJ> I believe glibc is ok. The problem is binutils. I didn't see any
>   HJ> supports for DT_INIT_ARRAY, DT_FINI_ARRAY. DT_INIT_ARRAYSZ,
>   HJ> DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY nor DT_PREINIT_ARRAYSZ.
> 
> Shouldn't this be easy straight-forward to add?

Yes, it should.  I think there's even some code for this 
for ia64-hpux in the tree already.

> I guess the other component that needs updating is gcc (at least the
> ia64 versions of crtbegin.asm and crtend.asm would need that).  I'd be
> happy to work on this.

Should be easy too, except for the bit to figure out whether or
not support for this exists in ld.so.


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 18:01         ` Richard Henderson
@ 2002-02-28 18:05           ` David Mosberger
  2002-02-28 18:14           ` H . J . Lu
  2002-02-28 22:52           ` David Mosberger
  2 siblings, 0 replies; 54+ messages in thread
From: David Mosberger @ 2002-02-28 18:05 UTC (permalink / raw)
  To: Richard Henderson
  Cc: davidm, H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Thu, 28 Feb 2002 17:54:26 -0800, Richard Henderson <rth@redhat.com> said:

  Rich> Yes, it should.  I think there's even some code for this for
  Rich> ia64-hpux in the tree already.

I only see code to print the DT*ARRAY* tags and to recognize the respective
sections.  Looks to me like elflink.h needs to be updated?

  >> I guess the other component that needs updating is gcc (at least
  >> the ia64 versions of crtbegin.asm and crtend.asm would need
  >> that).  I'd be happy to work on this.

  Rich> Should be easy too, except for the bit to figure out whether
  Rich> or not support for this exists in ld.so.

Right.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 17:54       ` David Mosberger
  2002-02-28 18:01         ` Richard Henderson
@ 2002-02-28 18:11         ` H . J . Lu
  1 sibling, 0 replies; 54+ messages in thread
From: H . J . Lu @ 2002-02-28 18:11 UTC (permalink / raw)
  To: davidm; +Cc: binutils

On Thu, Feb 28, 2002 at 05:43:07PM -0800, David Mosberger wrote:
> >>>>> On Thu, 28 Feb 2002 17:33:11 -0800, "H . J . Lu" <hjl@lucon.org> said:
> 
>   HJ> I believe glibc is ok. The problem is binutils. I didn't see any
>   HJ> supports for DT_INIT_ARRAY, DT_FINI_ARRAY. DT_INIT_ARRAYSZ,
>   HJ> DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY nor DT_PREINIT_ARRAYSZ.
> 
> Shouldn't this be easy straight-forward to add?
> 

I haven't looked at them closely. Mu guess is it shouldn't be too hard.
You just need to handle .init_array/.fini_array/.preinit_arrary. Here
is something to begin with. You need to set those DT_XXX entries from
those .init_array, .fini_array and .preinit_array sections.


H.J.
--
--- bfd/elf.c.array	Tue Feb 19 15:17:40 2002
+++ bfd/elf.c	Thu Feb 28 18:01:34 2002
@@ -2178,6 +2178,18 @@ elf_fake_sections (abfd, asect, failedpt
       this_hdr->sh_type = SHT_REL;
       this_hdr->sh_entsize = bed->s->sizeof_rel;
     }
+  else if (strcmp (name, ".init_array") == 0)
+    {
+      hdr->sh_type = SHT_INIT_ARRAY;
+    }
+  else if (strcmp (name, ".fini_array") == 0)
+    {
+      hdr->sh_type = SHT_FINI_ARRAY;
+    }
+  else if (strcmp (name, ".preinit_array") == 0)
+    {
+      hdr->sh_type = SHT_PREINIT_ARRAY;
+    }
   else if (strncmp (asect->name, ".note", 5) == 0)
     this_hdr->sh_type = SHT_NOTE;
   else if (strncmp (asect->name, ".stab", 5) == 0


^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 18:01         ` Richard Henderson
  2002-02-28 18:05           ` David Mosberger
@ 2002-02-28 18:14           ` H . J . Lu
  2002-02-28 21:01             ` Richard Henderson
  2002-02-28 22:52           ` David Mosberger
  2 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-02-28 18:14 UTC (permalink / raw)
  To: Richard Henderson; +Cc: davidm, Ulrich Drepper, GNU libc hacker, binutils

On Thu, Feb 28, 2002 at 05:54:26PM -0800, Richard Henderson wrote:
> 
> > I guess the other component that needs updating is gcc (at least the
> > ia64 versions of crtbegin.asm and crtend.asm would need that).  I'd be
> > happy to work on this.
> 
> Should be easy too, except for the bit to figure out whether or
> not support for this exists in ld.so.

ld should only generate those DT_XXX_ARRAY entries from those
.xxx_array sections. If ld.so doesn't support DT_XXX_ARRAY, there
shouldn't be any .xxx_array sections in ld inputs. It it is not an
ld problem. I think gcc should check it.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 18:14           ` H . J . Lu
@ 2002-02-28 21:01             ` Richard Henderson
  0 siblings, 0 replies; 54+ messages in thread
From: Richard Henderson @ 2002-02-28 21:01 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, Ulrich Drepper, GNU libc hacker, binutils

On Thu, Feb 28, 2002 at 06:11:37PM -0800, H . J . Lu wrote:
> If ld.so doesn't support DT_XXX_ARRAY, there
> shouldn't be any .xxx_array sections in ld inputs. It it is not an
> ld problem. I think gcc should check it.

Obviously.  Isn't this what I just said?


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 18:01         ` Richard Henderson
  2002-02-28 18:05           ` David Mosberger
  2002-02-28 18:14           ` H . J . Lu
@ 2002-02-28 22:52           ` David Mosberger
  2002-02-28 23:18             ` Richard Henderson
  2 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-02-28 22:52 UTC (permalink / raw)
  To: Richard Henderson
  Cc: davidm, H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Thu, 28 Feb 2002 17:54:26 -0800, Richard Henderson <rth@redhat.com> said:

  Rich> On Thu, Feb 28, 2002 at 05:43:07PM -0800, David Mosberger
  Rich> wrote:

  HJ> I believe glibc is ok. The problem is binutils. I didn't see any
  HJ> supports for DT_INIT_ARRAY, DT_FINI_ARRAY. DT_INIT_ARRAYSZ,
  HJ> DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY nor DT_PREINIT_ARRAYSZ.

  David>  Shouldn't this be easy straight-forward to add?

  Rich> Yes, it should.  I think there's even some code for this for
  Rich> ia64-hpux in the tree already.

OK, how is the attached for a start?

I'm not sure it's 100% correct, so it needs some reviewing, but it
does seem to do the right thing.

There is one more problem in glibc however: each platform's startup
code needs to be modified to handle these sections (since the dynamic
loader doesn't call them; which makes sense given that we need to
handle static binaries at any rate).  But how can the startup code
find to these sections?  Perhaps we should define symbols in the
linker script to mark the beginning and end of each section?  (I don't
know what the ${RELOCATING+${INIT_ARRAY_START}} stuff means in
scripttempl/elf.sc; perhaps this does the right thing?)

Thanks,

	--david

-----------------------
bfd/ChangeLog:

2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* elflink.h (size_dynamic_sections): If section named
	".preinit_array" exists, create DT_PREINIT_ARRAY and
	DT_PREINIT_ARRAYSZ entries in dynamic table.  Analogously for
	".init_array" and ".fini_array".
	(elf_bfd_final_link): Handle DT_PREINIT_ARRAYSZ, DT_INIT_ARRAYSZ,
	DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY, DT_INIT_ARRAY, and
	DT_FINI_ARRAY.

ld/ChangeLog:

2001-04-18  David Mosberger  <davidm@hpl.hp.com>

	* emulparams/elf64_ia64.sh (EXECUTABLE_SYMBOLS): Provide default
	value for _FPU_STATUS (initial value of ar.fpsr).



Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.141
diff -u -r1.141 elflink.h
--- bfd/elflink.h	2002/01/21 10:29:07	1.141
+++ bfd/elflink.h	2002/03/01 06:26:19
@@ -3200,6 +3200,33 @@
 	    return false;
 	}
 
+      /* yuck, more matching by name... */
+
+      if (bfd_get_section_by_name (output_bfd, ".preinit_array"))
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (bfd_get_section_by_name (output_bfd, ".init_array"))
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (bfd_get_section_by_name (output_bfd, ".fini_array"))
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+
       dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
       /* If .dynstr is excluded from the link, we don't want any of
 	 these tags.  Strictly, we should be checking each section
@@ -5548,6 +5575,31 @@
 		  }
 	      }
 	      break;
+
+	    case DT_PREINIT_ARRAYSZ:
+	      name = ".preinit_array";
+	      goto get_size;
+	    case DT_INIT_ARRAYSZ:
+	      name = ".init_array";
+	      goto get_size;
+	    case DT_FINI_ARRAYSZ:
+	      name = ".fini_array";
+	    get_size:
+	      o = bfd_get_section_by_name (abfd, name);
+	      BFD_ASSERT (o != NULL);
+	      dyn.d_un.d_val = o->_raw_size;
+	      elf_swap_dyn_out (dynobj, &dyn, dyncon);
+	      break;
+
+	    case DT_PREINIT_ARRAY:
+	      name = ".preinit_array";
+	      goto get_vma;
+	    case DT_INIT_ARRAY:
+	      name = ".init_array";
+	      goto get_vma;
+	    case DT_FINI_ARRAY:
+	      name = ".fini_array";
+	      goto get_vma;
 
 	    case DT_HASH:
 	      name = ".hash";

Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.26
diff -u -r1.26 elf.sc
--- ld/scripttempl/elf.sc	2002/02/12 14:50:08	1.26
+++ ld/scripttempl/elf.sc	2002/03/01 06:26:29
@@ -246,6 +246,27 @@
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
+  .preinit_array   ${RELOCATING-0} :
+  {
+    ${RELOCATING+${PREINIT_ARRAY_START}}
+    KEEP (*(.preinit_array))
+    ${RELOCATING+${PREINIT_ARRAY_END}}
+  }
+
+  .init_array   ${RELOCATING-0} :
+  {
+    ${RELOCATING+${INIT_ARRAY_START}}
+    KEEP (*(.init_array))
+    ${RELOCATING+${INIT_ARRAY_END}}
+  }
+
+  .fini_array   ${RELOCATING-0} :
+  {
+    ${RELOCATING+${FINI_ARRAY_START}}
+    KEEP (*(.fini_array))
+    ${RELOCATING+${FINI_ARRAY_END}}
+  }
+
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 22:52           ` David Mosberger
@ 2002-02-28 23:18             ` Richard Henderson
  2002-03-01 10:24               ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: Richard Henderson @ 2002-02-28 23:18 UTC (permalink / raw)
  To: davidm; +Cc: H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

On Thu, Feb 28, 2002 at 10:41:51PM -0800, David Mosberger wrote:
> (I don't know what the ${RELOCATING+${INIT_ARRAY_START}} stuff means
> in scripttempl/elf.sc; perhaps this does the right thing?)

It's sh code.  If RELOCATING is set, then expand INIT_ARRAY_START.
Which you havn't defined to anything, so it's of course empty.

You'd want to do something like

	INIT_ARRAY_START="PROVIDE(__init_array_start = .)"
	${RELOCATING+${CREATE_SHLIB-${INIT_ARRAY_START}}}


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-02-28 23:18             ` Richard Henderson
@ 2002-03-01 10:24               ` David Mosberger
  2002-03-01 16:47                 ` Richard Henderson
  2002-03-02  0:36                 ` H . J . Lu
  0 siblings, 2 replies; 54+ messages in thread
From: David Mosberger @ 2002-03-01 10:24 UTC (permalink / raw)
  To: Richard Henderson
  Cc: davidm, H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Thu, 28 Feb 2002 22:57:57 -0800, Richard Henderson <rth@redhat.com> said:

  Richard> On Thu, Feb 28, 2002 at 10:41:51PM -0800, David Mosberger
  Richard> wrote:
  >> (I don't know what the ${RELOCATING+${INIT_ARRAY_START}} stuff
  >> means in scripttempl/elf.sc; perhaps this does the right thing?)

  Richard> It's sh code.  If RELOCATING is set, then expand
  Richard> INIT_ARRAY_START.  Which you havn't defined to anything, so
  Richard> it's of course empty.

  Richard> You'd want to do something like

  Richard> 	INIT_ARRAY_START="PROVIDE(__init_array_start = .)"
  Richard> ${RELOCATING+${CREATE_SHLIB-${INIT_ARRAY_START}}}

OK, so how about this patch?

With this version, the linker determines whether a DT_*_ARRAY is
needed by search the input bfds for sections with the magic name.
Is there a better way for doing such a check?

	--david

--- bfd/ChangeLog	2002/02/22 20:36:12	1.1363
2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* elflink.h (size_dynamic_sections): If section named
	".preinit_array" exists, create DT_PREINIT_ARRAY and
	DT_PREINIT_ARRAYSZ entries in dynamic table.  Analogously for
	".init_array" and ".fini_array".
	(elf_bfd_final_link): Handle DT_PREINIT_ARRAYSZ, DT_INIT_ARRAYSZ,
	DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY, DT_INIT_ARRAY, and
	DT_FINI_ARRAY.

--- ld/ChangeLog
2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* scripttempl/elf.sc (SECTIONS): Add entries for .preinit_array,
	.init_array, and .fini_array.

Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.141
diff -u -r1.141 elflink.h
--- bfd/elflink.h	2002/01/21 10:29:07	1.141
+++ bfd/elflink.h	2002/03/01 17:29:46
@@ -3029,7 +3029,9 @@
      struct bfd_elf_version_tree *verdefs;
 {
   bfd_size_type soname_indx;
-  bfd *dynobj;
+  bfd *dynobj, *sub;
+  asection *o;
+  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3200,6 +3202,43 @@
 	    return false;
 	}
 
+      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+	for (o = sub->sections; o != NULL; o = o->next)
+	  {
+	    /* yuck, more matching by name... */
+
+	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
+	      need_preinit_array = 1;
+	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
+	      need_init_array = 1;
+	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
+	      need_fini_array = 1;
+	  }
+      if (need_preinit_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (need_init_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (need_fini_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+
       dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
       /* If .dynstr is excluded from the link, we don't want any of
 	 these tags.  Strictly, we should be checking each section
@@ -5548,6 +5587,31 @@
 		  }
 	      }
 	      break;
+
+	    case DT_PREINIT_ARRAYSZ:
+	      name = ".preinit_array";
+	      goto get_size;
+	    case DT_INIT_ARRAYSZ:
+	      name = ".init_array";
+	      goto get_size;
+	    case DT_FINI_ARRAYSZ:
+	      name = ".fini_array";
+	    get_size:
+	      o = bfd_get_section_by_name (abfd, name);
+	      BFD_ASSERT (o != NULL);
+	      dyn.d_un.d_val = o->_raw_size;
+	      elf_swap_dyn_out (dynobj, &dyn, dyncon);
+	      break;
+
+	    case DT_PREINIT_ARRAY:
+	      name = ".preinit_array";
+	      goto get_vma;
+	    case DT_INIT_ARRAY:
+	      name = ".init_array";
+	      goto get_vma;
+	    case DT_FINI_ARRAY:
+	      name = ".fini_array";
+	      goto get_vma;
 
 	    case DT_HASH:
 	      name = ".hash";
Index: scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.26
diff -u -r1.26 elf.sc
--- scripttempl/elf.sc	2002/02/12 14:50:08	1.26
+++ scripttempl/elf.sc	2002/03/01 18:23:50
@@ -246,6 +246,18 @@
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
+  .init_array   ${RELOCATING-0} : { *(.init_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 10:24               ` David Mosberger
@ 2002-03-01 16:47                 ` Richard Henderson
  2002-03-01 16:56                   ` David Mosberger
  2002-03-02  0:36                 ` H . J . Lu
  1 sibling, 1 reply; 54+ messages in thread
From: Richard Henderson @ 2002-03-01 16:47 UTC (permalink / raw)
  To: davidm; +Cc: H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

On Fri, Mar 01, 2002 at 10:24:26AM -0800, David Mosberger wrote:
> OK, so how about this patch?

Looks close.  The only problem I see is with

> +  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
> +  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
> +  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}

Suppose . is not as aligned as the contents of .preinit_array
etc?  Then __preinit_array_start will have the wrong value.
I think you want

    .preinit_array ${RELOCATING-0} : ${RELOCATING+ALIGN(${ALIGNMENT})} {
        ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
	*(.preinit_array)
	${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
    }

That will make sure you get 4 byte alignment for ELF32 and 8 byte
alignment for ELF64.  And assuming that the sections are similarly
aligned, this should work fine.


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 16:47                 ` Richard Henderson
@ 2002-03-01 16:56                   ` David Mosberger
  2002-03-01 17:00                     ` Richard Henderson
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-01 16:56 UTC (permalink / raw)
  To: Richard Henderson
  Cc: davidm, H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Fri, 1 Mar 2002 16:47:25 -0800, Richard Henderson <rth@redhat.com> said:

  Richard> On Fri, Mar 01, 2002 at 10:24:26AM -0800, David Mosberger wrote:
  >> OK, so how about this patch?

  Richard> Looks close.

Great!

  Richard> The only problem I see is with

  >> +  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
  >> +  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
  >> +  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}

  Richard> Suppose . is not as aligned as the contents of .preinit_array
  Richard> etc?  Then __preinit_array_start will have the wrong value.
  Richard> I think you want

  Richard> .preinit_array ${RELOCATING-0} : ${RELOCATING+ALIGN(${ALIGNMENT})} {
  Richard> ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
  Richard> *(.preinit_array)
  Richard> ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
  Richard> }

  Richard> That will make sure you get 4 byte alignment for ELF32 and 8 byte
  Richard> alignment for ELF64.  And assuming that the sections are similarly
  Richard> aligned, this should work fine.

Good point.  The reason I moved the labels outside is because
otherwise the linker seems to insist on creating the sections, even if
they're empty.  Is there another way to avoid this?  If not, I suppose
we can live with that as it's more of a beauty blemish than a real
problem.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 16:56                   ` David Mosberger
@ 2002-03-01 17:00                     ` Richard Henderson
  2002-03-01 17:20                       ` David Mosberger
  2002-03-01 21:34                       ` Alan Modra
  0 siblings, 2 replies; 54+ messages in thread
From: Richard Henderson @ 2002-03-01 17:00 UTC (permalink / raw)
  To: davidm; +Cc: H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

On Fri, Mar 01, 2002 at 04:52:55PM -0800, David Mosberger wrote:
> The reason I moved the labels outside is because
> otherwise the linker seems to insist on creating the sections, even if
> they're empty.  Is there another way to avoid this?

Not that I'm aware of.  I suppose you could put

	${RELOCATING+. = ALIGN(${ALIGNMENT})}

before the first label, which should have the same effect.


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 17:00                     ` Richard Henderson
@ 2002-03-01 17:20                       ` David Mosberger
  2002-03-01 17:26                         ` Richard Henderson
  2002-03-01 21:34                       ` Alan Modra
  1 sibling, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-01 17:20 UTC (permalink / raw)
  To: Richard Henderson; +Cc: H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

>>>>> On Fri, 1 Mar 2002 17:00:10 -0800, Richard Henderson <rth@redhat.com> said:

  Richard> On Fri, Mar 01, 2002 at 04:52:55PM -0800, David Mosberger wrote:
  >> The reason I moved the labels outside is because
  >> otherwise the linker seems to insist on creating the sections, even if
  >> they're empty.  Is there another way to avoid this?

  Richard> Not that I'm aware of.  I suppose you could put

  Richard> ${RELOCATING+. = ALIGN(${ALIGNMENT})}

  Richard> before the first label, which should have the same effect.

OK, that's what I did.  Could this be applied to the relevant branches?

Thanks,

	--david

---
bfd/ChangeLog:

2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* elflink.h (size_dynamic_sections): If section named
	".preinit_array" exists, create DT_PREINIT_ARRAY and
	DT_PREINIT_ARRAYSZ entries in dynamic table.  Analogously for
	".init_array" and ".fini_array".
	(elf_bfd_final_link): Handle DT_PREINIT_ARRAYSZ, DT_INIT_ARRAYSZ,
	DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY, DT_INIT_ARRAY, and
	DT_FINI_ARRAY.

---
ld/ChangeLog

2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* scripttempl/elf.sc (SECTIONS): Add entries for .preinit_array,
	.init_array, and .fini_array.

Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.141
diff -u -r1.141 elflink.h
--- bfd/elflink.h	2002/01/21 10:29:07	1.141
+++ bfd/elflink.h	2002/03/02 01:12:38
@@ -3029,7 +3029,9 @@
      struct bfd_elf_version_tree *verdefs;
 {
   bfd_size_type soname_indx;
-  bfd *dynobj;
+  bfd *dynobj, *sub;
+  asection *o;
+  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3200,6 +3202,43 @@
 	    return false;
 	}
 
+      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+	for (o = sub->sections; o != NULL; o = o->next)
+	  {
+	    /* yuck, more matching by name... */
+
+	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
+	      need_preinit_array = 1;
+	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
+	      need_init_array = 1;
+	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
+	      need_fini_array = 1;
+	  }
+      if (need_preinit_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (need_init_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (need_fini_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+
       dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
       /* If .dynstr is excluded from the link, we don't want any of
 	 these tags.  Strictly, we should be checking each section
@@ -5548,6 +5587,31 @@
 		  }
 	      }
 	      break;
+
+	    case DT_PREINIT_ARRAYSZ:
+	      name = ".preinit_array";
+	      goto get_size;
+	    case DT_INIT_ARRAYSZ:
+	      name = ".init_array";
+	      goto get_size;
+	    case DT_FINI_ARRAYSZ:
+	      name = ".fini_array";
+	    get_size:
+	      o = bfd_get_section_by_name (abfd, name);
+	      BFD_ASSERT (o != NULL);
+	      dyn.d_un.d_val = o->_raw_size;
+	      elf_swap_dyn_out (dynobj, &dyn, dyncon);
+	      break;
+
+	    case DT_PREINIT_ARRAY:
+	      name = ".preinit_array";
+	      goto get_vma;
+	    case DT_INIT_ARRAY:
+	      name = ".init_array";
+	      goto get_vma;
+	    case DT_FINI_ARRAY:
+	      name = ".fini_array";
+	      goto get_vma;
 
 	    case DT_HASH:
 	      name = ".hash";
Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.26
diff -u -r1.26 elf.sc
--- ld/scripttempl/elf.sc	2002/02/12 14:50:08	1.26
+++ ld/scripttempl/elf.sc	2002/03/02 01:12:39
@@ -246,6 +246,23 @@
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
+  /* Ensure the __preinit_array_start label is properly aligned.  We
+     could instead move the label definition inside the section, but
+     the linker would then create the section even if it turns out to
+     be empty, which isn't pretty.  */
+  ${RELOCATING+. = ALIGN(${ALIGNMENT})}
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
+  .init_array   ${RELOCATING-0} : { *(.init_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 17:20                       ` David Mosberger
@ 2002-03-01 17:26                         ` Richard Henderson
  2002-03-01 17:36                           ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: Richard Henderson @ 2002-03-01 17:26 UTC (permalink / raw)
  To: davidm; +Cc: H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

On Fri, Mar 01, 2002 at 05:16:12PM -0800, David Mosberger wrote:
> OK, that's what I did.  Could this be applied to the relevant branches?

Applied to mainline.  IIRC, the 2.12 branch is closed.


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 17:26                         ` Richard Henderson
@ 2002-03-01 17:36                           ` David Mosberger
  2002-03-02 19:59                             ` Daniel Jacobowitz
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-01 17:36 UTC (permalink / raw)
  To: Richard Henderson, drow; +Cc: GNU libc hacker, binutils

>>>>> On Fri, 1 Mar 2002 17:25:58 -0800, Richard Henderson <rth@redhat.com> said:

  Rich> On Fri, Mar 01, 2002 at 05:16:12PM -0800, David Mosberger wrote:
  >> OK, that's what I did.  Could this be applied to the relevant branches?

  Rich> Applied to mainline.

Thanks!


  Rich> IIRC, the 2.12 branch is closed.

Daniel, are you overseeing the 2.12 branch?  If so, any chance to make
an exception for this change?  My hope is the patch is trivial enough
to be considered safe and it would certainly help getting the
remaining unwind-related bugs ironed out of ia64 linux.  It should
also help freebsd/ia64 to get this right from the start.

	--david

---
bfd/ChangeLog:

2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* elflink.h (size_dynamic_sections): If section named
	".preinit_array" exists, create DT_PREINIT_ARRAY and
	DT_PREINIT_ARRAYSZ entries in dynamic table.  Analogously for
	".init_array" and ".fini_array".
	(elf_bfd_final_link): Handle DT_PREINIT_ARRAYSZ, DT_INIT_ARRAYSZ,
	DT_FINI_ARRAYSZ, DT_PREINIT_ARRAY, DT_INIT_ARRAY, and
	DT_FINI_ARRAY.

---
ld/ChangeLog

2002-02-28  David Mosberger  <davidm@hpl.hp.com>

	* scripttempl/elf.sc (SECTIONS): Add entries for .preinit_array,
	.init_array, and .fini_array.

Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.141
diff -u -r1.141 elflink.h
--- bfd/elflink.h	2002/01/21 10:29:07	1.141
+++ bfd/elflink.h	2002/03/02 01:12:38
@@ -3029,7 +3029,9 @@
      struct bfd_elf_version_tree *verdefs;
 {
   bfd_size_type soname_indx;
-  bfd *dynobj;
+  bfd *dynobj, *sub;
+  asection *o;
+  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3200,6 +3202,43 @@
 	    return false;
 	}
 
+      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
+	for (o = sub->sections; o != NULL; o = o->next)
+	  {
+	    /* yuck, more matching by name... */
+
+	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
+	      need_preinit_array = 1;
+	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
+	      need_init_array = 1;
+	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
+	      need_fini_array = 1;
+	  }
+      if (need_preinit_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (need_init_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+      if (need_fini_array)
+	{
+	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
+				      (bfd_vma) 0)
+	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
+					 (bfd_vma) 0))
+	    return false;
+	}
+
       dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
       /* If .dynstr is excluded from the link, we don't want any of
 	 these tags.  Strictly, we should be checking each section
@@ -5548,6 +5587,31 @@
 		  }
 	      }
 	      break;
+
+	    case DT_PREINIT_ARRAYSZ:
+	      name = ".preinit_array";
+	      goto get_size;
+	    case DT_INIT_ARRAYSZ:
+	      name = ".init_array";
+	      goto get_size;
+	    case DT_FINI_ARRAYSZ:
+	      name = ".fini_array";
+	    get_size:
+	      o = bfd_get_section_by_name (abfd, name);
+	      BFD_ASSERT (o != NULL);
+	      dyn.d_un.d_val = o->_raw_size;
+	      elf_swap_dyn_out (dynobj, &dyn, dyncon);
+	      break;
+
+	    case DT_PREINIT_ARRAY:
+	      name = ".preinit_array";
+	      goto get_vma;
+	    case DT_INIT_ARRAY:
+	      name = ".init_array";
+	      goto get_vma;
+	    case DT_FINI_ARRAY:
+	      name = ".fini_array";
+	      goto get_vma;
 
 	    case DT_HASH:
 	      name = ".hash";
Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.26
diff -u -r1.26 elf.sc
--- ld/scripttempl/elf.sc	2002/02/12 14:50:08	1.26
+++ ld/scripttempl/elf.sc	2002/03/02 01:12:39
@@ -246,6 +246,23 @@
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
+  /* Ensure the __preinit_array_start label is properly aligned.  We
+     could instead move the label definition inside the section, but
+     the linker would then create the section even if it turns out to
+     be empty, which isn't pretty.  */
+  ${RELOCATING+. = ALIGN(${ALIGNMENT})}
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
+  .init_array   ${RELOCATING-0} : { *(.init_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 17:00                     ` Richard Henderson
  2002-03-01 17:20                       ` David Mosberger
@ 2002-03-01 21:34                       ` Alan Modra
  1 sibling, 0 replies; 54+ messages in thread
From: Alan Modra @ 2002-03-01 21:34 UTC (permalink / raw)
  To: Richard Henderson
  Cc: davidm, H . J . Lu, Ulrich Drepper, GNU libc hacker, binutils

On Fri, Mar 01, 2002 at 05:00:10PM -0800, Richard Henderson wrote:
> On Fri, Mar 01, 2002 at 04:52:55PM -0800, David Mosberger wrote:
> > The reason I moved the labels outside is because
> > otherwise the linker seems to insist on creating the sections, even if
> > they're empty.  Is there another way to avoid this?
> 
> Not that I'm aware of.  I suppose you could put
> 
> 	${RELOCATING+. = ALIGN(${ALIGNMENT})}
> 
> before the first label, which should have the same effect.

Except when someone puts an .align <bignumber> in the segment in
question.  I might have a go at fixing PROVIDE one of these days.
It's a bit poor that PROVIDE (foo = something); inside a section
makes the section appear in the output when foo isn't referenced.
PROVIDE (foo = ABSOLUTE (something)); should similarly not cause
a section to be output by itself, even when foo _is_ referenced.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 10:24               ` David Mosberger
  2002-03-01 16:47                 ` Richard Henderson
@ 2002-03-02  0:36                 ` H . J . Lu
  2002-03-02  2:19                   ` Alan Modra
  1 sibling, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02  0:36 UTC (permalink / raw)
  To: davidm; +Cc: Richard Henderson, Ulrich Drepper, GNU libc hacker, binutils

On Fri, Mar 01, 2002 at 10:24:26AM -0800, David Mosberger wrote:
> >>>>> On Thu, 28 Feb 2002 22:57:57 -0800, Richard Henderson <rth@redhat.com> said:
> 
>   Richard> On Thu, Feb 28, 2002 at 10:41:51PM -0800, David Mosberger
>   Richard> wrote:
>   >> (I don't know what the ${RELOCATING+${INIT_ARRAY_START}} stuff
>   >> means in scripttempl/elf.sc; perhaps this does the right thing?)
> 
>   Richard> It's sh code.  If RELOCATING is set, then expand
>   Richard> INIT_ARRAY_START.  Which you havn't defined to anything, so
>   Richard> it's of course empty.
> 
>   Richard> You'd want to do something like
> 
>   Richard> 	INIT_ARRAY_START="PROVIDE(__init_array_start = .)"
>   Richard> ${RELOCATING+${CREATE_SHLIB-${INIT_ARRAY_START}}}
> 
> OK, so how about this patch?
> 
> With this version, the linker determines whether a DT_*_ARRAY is
> needed by search the input bfds for sections with the magic name.
> Is there a better way for doing such a check?
> 

.init_array, .fini_array and .preinit_array are new special sections.
We need to make sure their types and attributes are correct. Here is
a patch.


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

	* elf.c (elf_fake_sections): Handle special sections,
	.init_array, .fini_array and .preinit_array.

	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Check the
	section types instead of names for .init_array, .fini_array and
	.preinit_array.

2002-03-02  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.

--- binutils/bfd/elf.c.array	Tue Feb 19 15:17:40 2002
+++ binutils/bfd/elf.c	Sat Mar  2 00:25:51 2002
@@ -2178,6 +2178,12 @@ elf_fake_sections (abfd, asect, failedpt
       this_hdr->sh_type = SHT_REL;
       this_hdr->sh_entsize = bed->s->sizeof_rel;
     }
+  else if (strcmp (asect->name, ".init_array") == 0)
+    this_hdr->sh_type = SHT_INIT_ARRAY;
+  else if (strcmp (asect->name, ".fini_array") == 0)
+    this_hdr->sh_type = SHT_FINI_ARRAY;
+  else if (strcmp (asect->name, ".preinit_array") == 0)
+    this_hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strncmp (asect->name, ".note", 5) == 0)
     this_hdr->sh_type = SHT_NOTE;
   else if (strncmp (asect->name, ".stab", 5) == 0
--- binutils/bfd/elflink.h.array	Fri Mar  1 23:44:22 2002
+++ binutils/bfd/elflink.h	Sat Mar  2 00:22:26 2002
@@ -3200,6 +3200,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
   bfd *dynobj, *sub;
   asection *o;
   int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
+  int initfini_array = 0;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3370,18 +3371,27 @@ NAME(bfd_elf,size_dynamic_sections) (out
 	    return false;
 	}
 
-      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
-	for (o = sub->sections; o != NULL; o = o->next)
-	  {
-	    /* yuck, more matching by name... */
-
-	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
+      for (sub = info->input_bfds; sub != NULL && initfini_array != 3;
+	   sub = sub->link_next)
+	for (o = sub->sections; o != NULL && initfini_array != 3;
+	     o = o->next)
+	  switch (elf_section_data (o->output_section)->this_hdr.sh_type)
+	    {
+	    case SHT_PREINIT_ARRAY:
 	      need_preinit_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
+	      initfini_array++;
+	      break;
+	    case SHT_INIT_ARRAY:
 	      need_init_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
+	      initfini_array++;
+	      break;
+	    case SHT_FINI_ARRAY:
 	      need_fini_array = 1;
-	  }
+	      initfini_array++;
+	      break;
+	    default:
+	      break;
+	    }
       if (need_preinit_array)
 	{
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
--- binutils/gas/config/obj-elf.c.array	Fri Mar  1 23:44:32 2002
+++ binutils/gas/config/obj-elf.c	Sat Mar  2 00:10:52 2002
@@ -595,6 +595,9 @@ static struct special_section const spec
   { ".rodata",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".rodata1",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".text",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR	},
+  { ".init_array",SHT_INIT_ARRAY, SHF_ALLOC + SHF_WRITE         }, 
+  { ".fini_array",SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE         },
+  { ".preinit_array",SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE   }, 
 
 #ifdef ELF_TC_SPECIAL_SECTIONS
   ELF_TC_SPECIAL_SECTIONS
--- binutils/gas/config/tc-ia64.h.array	Tue Jan 15 11:30:50 2002
+++ binutils/gas/config/tc-ia64.h	Sat Mar  2 00:10:52 2002
@@ -124,8 +124,6 @@ extern void ia64_after_parse_args PARAMS
 #define WORKING_DOT_WORD	/* don't do broken word processing for now */
 
 #define ELF_TC_SPECIAL_SECTIONS						   \
-{ ".init_array",SHT_INIT_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
-{ ".fini_array",SHT_FINI_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
 { ".sbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, \
 { ".sdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
 

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02  0:36                 ` H . J . Lu
@ 2002-03-02  2:19                   ` Alan Modra
  2002-03-02  9:24                     ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: Alan Modra @ 2002-03-02  2:19 UTC (permalink / raw)
  To: H . J . Lu
  Cc: davidm, Richard Henderson, Ulrich Drepper, GNU libc hacker, binutils

On Sat, Mar 02, 2002 at 12:36:45AM -0800, H . J . Lu wrote:
> 
> .init_array, .fini_array and .preinit_array are new special sections.
> We need to make sure their types and attributes are correct. Here is
> a patch.

I like this, but there is a mistake in the following

> @@ -3370,18 +3371,27 @@ NAME(bfd_elf,size_dynamic_sections) (out
>  	    return false;
>  	}
>  
> -      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
> -	for (o = sub->sections; o != NULL; o = o->next)
> -	  {
> -	    /* yuck, more matching by name... */
> -
> -	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
> +      for (sub = info->input_bfds; sub != NULL && initfini_array != 3;
> +	   sub = sub->link_next)
> +	for (o = sub->sections; o != NULL && initfini_array != 3;
> +	     o = o->next)
> +	  switch (elf_section_data (o->output_section)->this_hdr.sh_type)
> +	    {
> +	    case SHT_PREINIT_ARRAY:
>  	      need_preinit_array = 1;
> -	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
> +	      initfini_array++;

Presumably, initfini_array is trying to cut short the section search
after finding one of each of the section types.  I can't see anything
in the ELF spec that precludes having, say, three SHT_PREINIT_ARRAY
input sections.  Best get rid of initfini_array entirely.

The other thing is that you'll need to extend your patch a little
to handle these section types in bfd_section_from_shdr.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02  2:19                   ` Alan Modra
@ 2002-03-02  9:24                     ` David Mosberger
  2002-03-02 10:59                       ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-02  9:24 UTC (permalink / raw)
  To: Alan Modra
  Cc: H . J . Lu, davidm, Richard Henderson, Ulrich Drepper,
	GNU libc hacker, binutils

>>>>> On Sat, 2 Mar 2002 20:49:31 +1030, Alan Modra <amodra@bigpond.net.au> said:

  Alan> On Sat, Mar 02, 2002 at 12:36:45AM -0800, H . J . Lu wrote:
  >>  .init_array, .fini_array and .preinit_array are new special
  >> sections.  We need to make sure their types and attributes are
  >> correct. Here is a patch.

  Alan> I like this, but there is a mistake in the following

  >> @@ -3370,18 +3371,27 @@ NAME(bfd_elf,size_dynamic_sections) (out
  >> return false; }
  >> 
  >> - for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
  >> - for (o = sub->sections; o != NULL; o = o->next) - { - /* yuck,
  >> more matching by name... */
  >> -
  >> - if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
  >> + for (sub = info->input_bfds; sub != NULL && initfini_array !=
  >> 3; + sub = sub->link_next) + for (o = sub->sections; o != NULL &&
  >> initfini_array != 3; + o = o->next) + switch (elf_section_data
  >> (o->output_section)->this_hdr.sh_type) + { + case
  >> SHT_PREINIT_ARRAY: need_preinit_array = 1; - if (strcmp
  >> (bfd_section_name (sub, o), ".init_array") == 0) +
  >> initfini_array++;

  Alan> Presumably, initfini_array is trying to cut short the section
  Alan> search after finding one of each of the section types.  I
  Alan> can't see anything in the ELF spec that precludes having, say,
  Alan> three SHT_PREINIT_ARRAY input sections.  Best get rid of
  Alan> initfini_array entirely.

The loop really only needs to determine whether any _input_ sections
contain the preinit/init/fini arrays.  You could use a bitmask and
stop the search as soon as all three array sections have occurred at
least once.

I considered doing that but opted not to do so for clarity and because
I wasn't sure how often preinit arrays will be used: if it turns out
that most executables do not use preinit arrays, then the optimization
won't be very useful.

  Alan> The other thing is that you'll need to extend your patch a
  Alan> little to handle these section types in bfd_section_from_shdr.

Also, note that elfxx-ia64.c already has code to set the section
types.  It's good if this can be moved to elf.c, but there is no point
in keeping two copies of this code.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02  9:24                     ` David Mosberger
@ 2002-03-02 10:59                       ` H . J . Lu
  2002-03-02 11:13                         ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 10:59 UTC (permalink / raw)
  To: davidm
  Cc: Alan Modra, Richard Henderson, Ulrich Drepper, GNU libc hacker, binutils

On Sat, Mar 02, 2002 at 09:19:16AM -0800, David Mosberger wrote:
> >>>>> On Sat, 2 Mar 2002 20:49:31 +1030, Alan Modra <amodra@bigpond.net.au> said:
> 
>   Alan> On Sat, Mar 02, 2002 at 12:36:45AM -0800, H . J . Lu wrote:
>   >>  .init_array, .fini_array and .preinit_array are new special
>   >> sections.  We need to make sure their types and attributes are
>   >> correct. Here is a patch.
> 
>   Alan> I like this, but there is a mistake in the following
> 
>   >> @@ -3370,18 +3371,27 @@ NAME(bfd_elf,size_dynamic_sections) (out
>   >> return false; }
>   >> 
>   >> - for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
>   >> - for (o = sub->sections; o != NULL; o = o->next) - { - /* yuck,
>   >> more matching by name... */
>   >> -
>   >> - if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
>   >> + for (sub = info->input_bfds; sub != NULL && initfini_array !=
>   >> 3; + sub = sub->link_next) + for (o = sub->sections; o != NULL &&
>   >> initfini_array != 3; + o = o->next) + switch (elf_section_data
>   >> (o->output_section)->this_hdr.sh_type) + { + case
>   >> SHT_PREINIT_ARRAY: need_preinit_array = 1; - if (strcmp
>   >> (bfd_section_name (sub, o), ".init_array") == 0) +
>   >> initfini_array++;
> 
>   Alan> Presumably, initfini_array is trying to cut short the section
>   Alan> search after finding one of each of the section types.  I
>   Alan> can't see anything in the ELF spec that precludes having, say,
>   Alan> three SHT_PREINIT_ARRAY input sections.  Best get rid of
>   Alan> initfini_array entirely.
> 
> The loop really only needs to determine whether any _input_ sections
> contain the preinit/init/fini arrays.  You could use a bitmask and
> stop the search as soon as all three array sections have occurred at
> least once.
> 
> I considered doing that but opted not to do so for clarity and because
> I wasn't sure how often preinit arrays will be used: if it turns out
> that most executables do not use preinit arrays, then the optimization
> won't be very useful.

The problem is you are searching all input files. It doesn't matter
they are used or not.

> 
>   Alan> The other thing is that you'll need to extend your patch a
>   Alan> little to handle these section types in bfd_section_from_shdr.
> 
> Also, note that elfxx-ia64.c already has code to set the section
> types.  It's good if this can be moved to elf.c, but there is no point
> in keeping two copies of this code.
> 
> 	--david


Here is a new patch. I made a few changes. I use

elf_section_data (o)->this_hdr.sh_type 

since 

elf_section_data (o->output_section)

is 0 when it is called. Also, those new sections should be in the
data segment. And I fixed a few typos.

BTW, should we allow both .init/.fini and the array sections. If both
exist, how should ld.so treat them?


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

	* elf.c (bfd_section_from_shdr): Handle special sections,
	.init_array, .fini_array and .preinit_array.
	(elf_fake_sections): Likewise.

	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Check the
	section types instead of names for .init_array, .fini_array and
	.preinit_array.

	* elfxx-ia64.c (elfNN_ia64_section_from_shdr): Remove
	SHT_INIT_ARRAY, SHT_FINI_ARRAY and SHT_PREINIT_ARRAY.
	(elfNN_ia64_fake_sections): Remove .init_array, .fini_array and
	.preinit_array.

2002-03-02  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.

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

	* scripttempl/elf.sc: Fix a few typos. Put .preinit_array,
	.init_array and .fini_array in the data segment.

--- binutils/bfd/elf.c.array	Tue Feb 19 15:17:40 2002
+++ binutils/bfd/elf.c	Sat Mar  2 09:55:43 2002
@@ -1564,6 +1564,9 @@ bfd_section_from_shdr (abfd, shindex)
     case SHT_NOBITS:	/* .bss section.  */
     case SHT_HASH:	/* .hash section.  */
     case SHT_NOTE:	/* .note section.  */
+    case SHT_INIT_ARRAY:	/* .init_array section.  */
+    case SHT_FINI_ARRAY:	/* .fini_array section.  */
+    case SHT_PREINIT_ARRAY:	/* .preinit_array section.  */
       return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
 
     case SHT_SYMTAB:		/* A symbol table */
@@ -2178,6 +2181,12 @@ elf_fake_sections (abfd, asect, failedpt
       this_hdr->sh_type = SHT_REL;
       this_hdr->sh_entsize = bed->s->sizeof_rel;
     }
+  else if (strcmp (asect->name, ".init_array") == 0)
+    this_hdr->sh_type = SHT_INIT_ARRAY;
+  else if (strcmp (asect->name, ".fini_array") == 0)
+    this_hdr->sh_type = SHT_FINI_ARRAY;
+  else if (strcmp (asect->name, ".preinit_array") == 0)
+    this_hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strncmp (asect->name, ".note", 5) == 0)
     this_hdr->sh_type = SHT_NOTE;
   else if (strncmp (asect->name, ".stab", 5) == 0
--- binutils/bfd/elflink.h.array	Fri Mar  1 23:44:22 2002
+++ binutils/bfd/elflink.h	Sat Mar  2 10:48:17 2002
@@ -3199,7 +3199,11 @@ NAME(bfd_elf,size_dynamic_sections) (out
   bfd_size_type soname_indx;
   bfd *dynobj, *sub;
   asection *o;
-  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
+#define PREINIT_ARRAY_MASK	1
+#define INIT_ARRAY_MASK		2
+#define FINI_ARRAY_MASK		4
+#define ALL_ARRAY_MASK		7
+  int dt_array = 0;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3373,39 +3377,50 @@ NAME(bfd_elf,size_dynamic_sections) (out
       for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
 	for (o = sub->sections; o != NULL; o = o->next)
 	  {
-	    /* yuck, more matching by name... */
+	    int array = 0, arraysz = 0;
 
-	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
-	      need_preinit_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
-	      need_init_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
-	      need_fini_array = 1;
-	  }
-      if (need_preinit_array)
-	{
-	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
-				      (bfd_vma) 0)
-	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
-					 (bfd_vma) 0))
-	    return false;
-	}
-      if (need_init_array)
-	{
-	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
-				      (bfd_vma) 0)
-	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
-					 (bfd_vma) 0))
-	    return false;
-	}
-      if (need_fini_array)
-	{
-	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
-				      (bfd_vma) 0)
-	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
-					 (bfd_vma) 0))
-	    return false;
+	    switch (elf_section_data (o)->this_hdr.sh_type)
+	      {
+	      case SHT_PREINIT_ARRAY:
+		if ((dt_array & PREINIT_ARRAY_MASK) == 0)
+		  {
+		    array = DT_PREINIT_ARRAY;
+		    arraysz = DT_PREINIT_ARRAYSZ;
+		    dt_array |= PREINIT_ARRAY_MASK;
+		  }
+		break;
+	      case SHT_INIT_ARRAY:
+		if ((dt_array & INIT_ARRAY_MASK) == 0)
+		  {
+		    array = DT_INIT_ARRAY;
+		    arraysz = DT_INIT_ARRAYSZ;
+		    dt_array |= INIT_ARRAY_MASK;
+		  }
+		break;
+	      case SHT_FINI_ARRAY:
+		if ((dt_array & FINI_ARRAY_MASK) == 0)
+		  {
+		    array = DT_FINI_ARRAY;
+		    arraysz = DT_FINI_ARRAYSZ;
+		    dt_array |= FINI_ARRAY_MASK;
+		  }
+		break;
+	      default:
+	      }
+
+	    if (array)
+	      {
+		if (!elf_add_dynamic_entry (info, (bfd_vma) array,
+					    (bfd_vma) 0)
+		    || !elf_add_dynamic_entry (info, (bfd_vma) arraysz,
+					       (bfd_vma) 0))
+		  return false;
+	      }
+
+	    if ((dt_array & ALL_ARRAY_MASK) == ALL_ARRAY_MASK)
+	      goto array_done;
 	}
+array_done:
 
       dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
       /* If .dynstr is excluded from the link, we don't want any of
--- binutils/bfd/elfxx-ia64.c.array	Tue Feb 19 15:18:24 2002
+++ binutils/bfd/elfxx-ia64.c	Sat Mar  2 10:21:20 2002
@@ -1016,9 +1016,6 @@ elfNN_ia64_section_from_shdr (abfd, hdr,
   switch (hdr->sh_type)
     {
     case SHT_IA_64_UNWIND:
-    case SHT_INIT_ARRAY:
-    case SHT_FINI_ARRAY:
-    case SHT_PREINIT_ARRAY:
     case SHT_IA_64_HP_OPT_ANOT:
       break;
 
@@ -1076,12 +1073,6 @@ elfNN_ia64_fake_sections (abfd, hdr, sec
     }
   else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
     hdr->sh_type = SHT_IA_64_EXT;
-  else if (strcmp (name, ".init_array") == 0)
-    hdr->sh_type = SHT_INIT_ARRAY;
-  else if (strcmp (name, ".fini_array") == 0)
-    hdr->sh_type = SHT_FINI_ARRAY;
-  else if (strcmp (name, ".preinit_array") == 0)
-    hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strcmp (name, ".HP.opt_annot") == 0)
     hdr->sh_type = SHT_IA_64_HP_OPT_ANOT;
   else if (strcmp (name, ".reloc") == 0)
--- binutils/gas/config/obj-elf.c.array	Fri Mar  1 23:44:32 2002
+++ binutils/gas/config/obj-elf.c	Sat Mar  2 00:10:52 2002
@@ -595,6 +595,9 @@ static struct special_section const spec
   { ".rodata",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".rodata1",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".text",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR	},
+  { ".init_array",SHT_INIT_ARRAY, SHF_ALLOC + SHF_WRITE         }, 
+  { ".fini_array",SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE         },
+  { ".preinit_array",SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE   }, 
 
 #ifdef ELF_TC_SPECIAL_SECTIONS
   ELF_TC_SPECIAL_SECTIONS
--- binutils/gas/config/tc-ia64.h.array	Tue Jan 15 11:30:50 2002
+++ binutils/gas/config/tc-ia64.h	Sat Mar  2 00:10:52 2002
@@ -124,8 +124,6 @@ extern void ia64_after_parse_args PARAMS
 #define WORKING_DOT_WORD	/* don't do broken word processing for now */
 
 #define ELF_TC_SPECIAL_SECTIONS						   \
-{ ".init_array",SHT_INIT_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
-{ ".fini_array",SHT_FINI_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
 { ".sbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, \
 { ".sdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
 
--- binutils/ld/scripttempl/elf.sc.array	Fri Mar  1 23:45:33 2002
+++ binutils/ld/scripttempl/elf.sc	Sat Mar  2 10:43:32 2002
@@ -246,23 +246,6 @@ cat <<EOF
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT})}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
-  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
-  .init_array   ${RELOCATING-0} : { *(.init_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
-  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
-
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {
@@ -293,6 +276,23 @@ cat <<EOF
   ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
+  /* Ensure the __preinit_array_start label is properly aligned.  We
+     could instead move the label definition inside the section, but
+     the linker would then create the section even if it turns out to
+     be empty, which isn't pretty.  */
+  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
+  .init_array   ${RELOCATING-0} : { *(.init_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+
   .data         ${RELOCATING-0} :
   {
     ${RELOCATING+${DATA_START_SYMBOLS}}

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 10:59                       ` H . J . Lu
@ 2002-03-02 11:13                         ` David Mosberger
  2002-03-02 11:27                           ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-02 11:13 UTC (permalink / raw)
  To: H . J . Lu
  Cc: davidm, Alan Modra, Richard Henderson, Ulrich Drepper,
	GNU libc hacker, binutils

>>>>> On Sat, 2 Mar 2002 10:59:39 -0800, "H . J . Lu" <hjl@lucon.org> said:

  HJ> The problem is you are searching all input files. It doesn't
  HJ> matter they are used or not.

Doesn't your patch do the same?  It's safe to create the entries
needlessly, though it would obviously be better if that didn't happen.
If you know a way to do that, great.

  HJ> Here is a new patch.

Looks to me like this could end up creating the same DT*ARRAY entries
multiple times, no?

  HJ> Also, those new sections should be in the data segment.

Good point.

  HJ> BTW, should we allow both .init/.fini and the array sections.

Yes.

  HJ> If both exist, how should ld.so treat them?

See the Sys V ABI.  IIRC, .init gets executed before .init_array and
.fini_array gets executed before .fini.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 11:13                         ` David Mosberger
@ 2002-03-02 11:27                           ` H . J . Lu
       [not found]                             ` <15489.10696.478128.294511@napali.hpl.hp.com>
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 11:27 UTC (permalink / raw)
  To: davidm
  Cc: Alan Modra, Richard Henderson, Ulrich Drepper, GNU libc hacker, binutils

On Sat, Mar 02, 2002 at 11:13:13AM -0800, David Mosberger wrote:
> >>>>> On Sat, 2 Mar 2002 10:59:39 -0800, "H . J . Lu" <hjl@lucon.org> said:
> 
>   HJ> The problem is you are searching all input files. It doesn't
>   HJ> matter they are used or not.
> 
> Doesn't your patch do the same?  It's safe to create the entries
> needlessly, though it would obviously be better if that didn't happen.
> If you know a way to do that, great.

Mine stops as soon as all 3 sections are found.

> 
>   HJ> Here is a new patch.
> 
> Looks to me like this could end up creating the same DT*ARRAY entries
> multiple times, no?

Mine checks the mask. It sets array/arraysz and the mask if the mask is
0. It only creates the DT entry if array is not 0. If the mask is not
0, array will be 0 and no duplicated DT entry will be added.

> 
>   HJ> Also, those new sections should be in the data segment.
> 
> Good point.
> 
>   HJ> BTW, should we allow both .init/.fini and the array sections.
> 
> Yes.
> 
>   HJ> If both exist, how should ld.so treat them?
> 
> See the Sys V ABI.  IIRC, .init gets executed before .init_array and
> .fini_array gets executed before .fini.
> 

How should we deal with "ld -init SYMBOL -fini SYMBOL"? Right now, ld
will replace .init/.fini sections with those symbols. Should we add
"-init-array SYMBOL"?


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
       [not found]                             ` <15489.10696.478128.294511@napali.hpl.hp.com>
@ 2002-03-02 12:28                               ` H . J . Lu
  2002-03-02 12:40                                 ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 12:28 UTC (permalink / raw)
  To: davidm; +Cc: binutils

On Sat, Mar 02, 2002 at 11:36:40AM -0800, David Mosberger wrote:
> 
> But it may still pick them up from files that end up not being used,
> no?

Here is a new patch. It checks if those sections is in output.

>   HJ> How should we deal with "ld -init SYMBOL -fini SYMBOL"? Right
>   HJ> now, ld will replace .init/.fini sections with those
>   HJ> symbols. Should we add "-init-array SYMBOL"?
> 
> I don't know how this option is being used so someone else will have
> to comment.
> 

The question is if ld allows setting DT_INIT/DT_FINI to any symbols,
should it do the same for those DT_XXX_ARRAY?


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

	* elf.c (bfd_section_from_shdr): Handle special sections,
	.init_array, .fini_array and .preinit_array.
	(elf_fake_sections): Likewise.

	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Create the
	DT entry only if the section is in output for .init_array,
	.fini_array and .preinit_array.

	* elfxx-ia64.c (elfNN_ia64_section_from_shdr): Remove
	SHT_INIT_ARRAY, SHT_FINI_ARRAY and SHT_PREINIT_ARRAY.
	(elfNN_ia64_fake_sections): Remove .init_array, .fini_array and
	.preinit_array.

2002-03-02  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.

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

	* scripttempl/elf.sc: Fix a few typos. Put .preinit_array,
	.init_array and .fini_array in the data segment.

--- binutils/bfd/elf.c.array	Tue Feb 19 15:17:40 2002
+++ binutils/bfd/elf.c	Sat Mar  2 09:55:43 2002
@@ -1564,6 +1564,9 @@ bfd_section_from_shdr (abfd, shindex)
     case SHT_NOBITS:	/* .bss section.  */
     case SHT_HASH:	/* .hash section.  */
     case SHT_NOTE:	/* .note section.  */
+    case SHT_INIT_ARRAY:	/* .init_array section.  */
+    case SHT_FINI_ARRAY:	/* .fini_array section.  */
+    case SHT_PREINIT_ARRAY:	/* .preinit_array section.  */
       return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
 
     case SHT_SYMTAB:		/* A symbol table */
@@ -2178,6 +2181,12 @@ elf_fake_sections (abfd, asect, failedpt
       this_hdr->sh_type = SHT_REL;
       this_hdr->sh_entsize = bed->s->sizeof_rel;
     }
+  else if (strcmp (asect->name, ".init_array") == 0)
+    this_hdr->sh_type = SHT_INIT_ARRAY;
+  else if (strcmp (asect->name, ".fini_array") == 0)
+    this_hdr->sh_type = SHT_FINI_ARRAY;
+  else if (strcmp (asect->name, ".preinit_array") == 0)
+    this_hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strncmp (asect->name, ".note", 5) == 0)
     this_hdr->sh_type = SHT_NOTE;
   else if (strncmp (asect->name, ".stab", 5) == 0
--- binutils/bfd/elflink.h.array	Fri Mar  1 23:44:22 2002
+++ binutils/bfd/elflink.h	Sat Mar  2 12:19:53 2002
@@ -3197,9 +3197,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
      struct bfd_elf_version_tree *verdefs;
 {
   bfd_size_type soname_indx;
-  bfd *dynobj, *sub;
-  asection *o;
-  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
+  bfd *dynobj;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3370,19 +3368,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
 	    return false;
 	}
 
-      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
-	for (o = sub->sections; o != NULL; o = o->next)
-	  {
-	    /* yuck, more matching by name... */
-
-	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
-	      need_preinit_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
-	      need_init_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
-	      need_fini_array = 1;
-	  }
-      if (need_preinit_array)
+      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
 	{
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
 				      (bfd_vma) 0)
@@ -3390,7 +3376,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
 					 (bfd_vma) 0))
 	    return false;
 	}
-      if (need_init_array)
+      if (bfd_get_section_by_name (output_bfd, ".init_array") != NULL)
 	{
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
 				      (bfd_vma) 0)
@@ -3398,7 +3384,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
 					 (bfd_vma) 0))
 	    return false;
 	}
-      if (need_fini_array)
+      if (bfd_get_section_by_name (output_bfd, ".fini_array") != NULL)
 	{
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
 				      (bfd_vma) 0)
--- binutils/bfd/elfxx-ia64.c.array	Tue Feb 19 15:18:24 2002
+++ binutils/bfd/elfxx-ia64.c	Sat Mar  2 10:21:20 2002
@@ -1016,9 +1016,6 @@ elfNN_ia64_section_from_shdr (abfd, hdr,
   switch (hdr->sh_type)
     {
     case SHT_IA_64_UNWIND:
-    case SHT_INIT_ARRAY:
-    case SHT_FINI_ARRAY:
-    case SHT_PREINIT_ARRAY:
     case SHT_IA_64_HP_OPT_ANOT:
       break;
 
@@ -1076,12 +1073,6 @@ elfNN_ia64_fake_sections (abfd, hdr, sec
     }
   else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
     hdr->sh_type = SHT_IA_64_EXT;
-  else if (strcmp (name, ".init_array") == 0)
-    hdr->sh_type = SHT_INIT_ARRAY;
-  else if (strcmp (name, ".fini_array") == 0)
-    hdr->sh_type = SHT_FINI_ARRAY;
-  else if (strcmp (name, ".preinit_array") == 0)
-    hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strcmp (name, ".HP.opt_annot") == 0)
     hdr->sh_type = SHT_IA_64_HP_OPT_ANOT;
   else if (strcmp (name, ".reloc") == 0)
--- binutils/gas/config/obj-elf.c.array	Fri Mar  1 23:44:32 2002
+++ binutils/gas/config/obj-elf.c	Sat Mar  2 00:10:52 2002
@@ -595,6 +595,9 @@ static struct special_section const spec
   { ".rodata",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".rodata1",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".text",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR	},
+  { ".init_array",SHT_INIT_ARRAY, SHF_ALLOC + SHF_WRITE         }, 
+  { ".fini_array",SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE         },
+  { ".preinit_array",SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE   }, 
 
 #ifdef ELF_TC_SPECIAL_SECTIONS
   ELF_TC_SPECIAL_SECTIONS
--- binutils/gas/config/tc-ia64.h.array	Tue Jan 15 11:30:50 2002
+++ binutils/gas/config/tc-ia64.h	Sat Mar  2 00:10:52 2002
@@ -124,8 +124,6 @@ extern void ia64_after_parse_args PARAMS
 #define WORKING_DOT_WORD	/* don't do broken word processing for now */
 
 #define ELF_TC_SPECIAL_SECTIONS						   \
-{ ".init_array",SHT_INIT_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
-{ ".fini_array",SHT_FINI_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
 { ".sbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, \
 { ".sdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
 
--- binutils/ld/scripttempl/elf.sc.array	Fri Mar  1 23:45:33 2002
+++ binutils/ld/scripttempl/elf.sc	Sat Mar  2 10:43:32 2002
@@ -246,23 +246,6 @@ cat <<EOF
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT})}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
-  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
-  .init_array   ${RELOCATING-0} : { *(.init_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
-  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
-
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {
@@ -293,6 +276,23 @@ cat <<EOF
   ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
+  /* Ensure the __preinit_array_start label is properly aligned.  We
+     could instead move the label definition inside the section, but
+     the linker would then create the section even if it turns out to
+     be empty, which isn't pretty.  */
+  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
+  .init_array   ${RELOCATING-0} : { *(.init_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+
   .data         ${RELOCATING-0} :
   {
     ${RELOCATING+${DATA_START_SYMBOLS}}

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 12:28                               ` H . J . Lu
@ 2002-03-02 12:40                                 ` David Mosberger
  2002-03-02 12:54                                   ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-02 12:40 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, binutils

>>>>> On Sat, 2 Mar 2002 12:28:20 -0800, "H . J . Lu" <hjl@lucon.org> said:

  HJ> +      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)

I don't think this works as intended: the section always exists in the
output_bfd at that time.  At least this is what it looked like when I
tried it.  That's why I switched to walking the input files and
sections.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 12:40                                 ` David Mosberger
@ 2002-03-02 12:54                                   ` H . J . Lu
  2002-03-02 12:57                                     ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 12:54 UTC (permalink / raw)
  To: davidm; +Cc: binutils

On Sat, Mar 02, 2002 at 12:40:27PM -0800, David Mosberger wrote:
> >>>>> On Sat, 2 Mar 2002 12:28:20 -0800, "H . J . Lu" <hjl@lucon.org> said:
> 
>   HJ> +      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
> 
> I don't think this works as intended: the section always exists in the
> output_bfd at that time.  At least this is what it looked like when I
> tried it.  That's why I switched to walking the input files and
> sections.

It seems to work for me.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 12:54                                   ` H . J . Lu
@ 2002-03-02 12:57                                     ` David Mosberger
  2002-03-02 13:43                                       ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-02 12:57 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, binutils

>>>>> On Sat, 2 Mar 2002 12:53:50 -0800, "H . J . Lu" <hjl@lucon.org> said:

  HJ> On Sat, Mar 02, 2002 at 12:40:27PM -0800, David Mosberger wrote:
  >> >>>>> On Sat, 2 Mar 2002 12:28:20 -0800, "H . J . Lu" <hjl@lucon.org> said:
  >> 
  HJ> +      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
  >> 
  >> I don't think this works as intended: the section always exists in the
  >> output_bfd at that time.  At least this is what it looked like when I
  >> tried it.  That's why I switched to walking the input files and
  >> sections.

  HJ> It seems to work for me.

Ah, that's good.  Perhaps it didn't work for me because I still had
the start/end labels defined inside the sections at that time.

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 12:57                                     ` David Mosberger
@ 2002-03-02 13:43                                       ` H . J . Lu
  2002-03-02 13:57                                         ` David Mosberger
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 13:43 UTC (permalink / raw)
  To: davidm; +Cc: binutils, GNU C Library, gcc

On Sat, Mar 02, 2002 at 12:57:11PM -0800, David Mosberger wrote:
> >>>>> On Sat, 2 Mar 2002 12:53:50 -0800, "H . J . Lu" <hjl@lucon.org> said:
> 
>   HJ> On Sat, Mar 02, 2002 at 12:40:27PM -0800, David Mosberger wrote:
>   >> >>>>> On Sat, 2 Mar 2002 12:28:20 -0800, "H . J . Lu" <hjl@lucon.org> said:
>   >> 
>   HJ> +      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
>   >> 
>   >> I don't think this works as intended: the section always exists in the
>   >> output_bfd at that time.  At least this is what it looked like when I
>   >> tried it.  That's why I switched to walking the input files and
>   >> sections.
> 
>   HJ> It seems to work for me.
> 
> Ah, that's good.  Perhaps it didn't work for me because I still had
> the start/end labels defined inside the sections at that time.

I noticed 2 problems:

1. glibc doesn't support .*_array in executales. elf/dl-init.c is not
used on executables. However, sysdeps/generic/libc-start.c doesn't
know how to do it. Glibc needs to be modified to call those functions
with __*_array_start/__*_array_end.
2. For

static void
foo ()
{
  printf ("hello world\n");
}

void (*array []) () __attribute__ ((section (".init_array"))) =
{
  &foo
};

main ()
{
 (array [0]) ();
}

I got

/tmp/f.s:23: Warning: setting incorrect section type for .init_array

The problem is

	.section        .init_array,"aw",@progbits

We can use

+  { ".init_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         }, 
+  { ".fini_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         },
+  { ".preinit_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE   }, 

in gas and let bfd to set the section type. Or we can teach gcc about
those special sections.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 13:43                                       ` H . J . Lu
@ 2002-03-02 13:57                                         ` David Mosberger
  2002-03-02 14:07                                           ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: David Mosberger @ 2002-03-02 13:57 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, binutils, GNU C Library, gcc

>>>>> On Sat, 2 Mar 2002 13:43:44 -0800, "H . J . Lu" <hjl@lucon.org> said:

  HJ> I noticed 2 problems:

  HJ> 1. glibc doesn't support .*_array in executales. elf/dl-init.c is not
  HJ> used on executables. However, sysdeps/generic/libc-start.c doesn't
  HJ> know how to do it. Glibc needs to be modified to call those functions
  HJ> with __*_array_start/__*_array_end.

Yes, I noticed that, too.  Wouldn't libc-start.c also have to call the
preinit array if the program is statically linked?

  HJ> We can use

  HJ> +  { ".init_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         }, 
  HJ> +  { ".fini_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         },
  HJ> +  { ".preinit_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE   }, 

  HJ> in gas and let bfd to set the section type. Or we can teach gcc about
  HJ> those special sections.

The latter seems better.  On targets where this is supported, we'll
want gcc to use the arrays at any rate (it's certainly true for ia64,
due to the unwind issues that started this discussion).

	--david

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 13:57                                         ` David Mosberger
@ 2002-03-02 14:07                                           ` H . J . Lu
  2002-03-02 23:22                                             ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 14:07 UTC (permalink / raw)
  To: davidm; +Cc: binutils, GNU C Library, gcc

On Sat, Mar 02, 2002 at 01:56:56PM -0800, David Mosberger wrote:
> >>>>> On Sat, 2 Mar 2002 13:43:44 -0800, "H . J . Lu" <hjl@lucon.org> said:
> 
>   HJ> I noticed 2 problems:
> 
>   HJ> 1. glibc doesn't support .*_array in executales. elf/dl-init.c is not
>   HJ> used on executables. However, sysdeps/generic/libc-start.c doesn't
>   HJ> know how to do it. Glibc needs to be modified to call those functions
>   HJ> with __*_array_start/__*_array_end.
> 
> Yes, I noticed that, too.  Wouldn't libc-start.c also have to call the
> preinit array if the program is statically linked?

Yes.

> 
>   HJ> We can use
> 
>   HJ> +  { ".init_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         }, 
>   HJ> +  { ".fini_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         },
>   HJ> +  { ".preinit_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE   }, 
> 
>   HJ> in gas and let bfd to set the section type. Or we can teach gcc about
>   HJ> those special sections.
> 
> The latter seems better.  On targets where this is supported, we'll
> want gcc to use the arrays at any rate (it's certainly true for ia64,
> due to the unwind issues that started this discussion).

Something like the `constructor_array' attribute? On the other hand,
it may be nice to use those special functions in the existing gcc.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-01 17:36                           ` David Mosberger
@ 2002-03-02 19:59                             ` Daniel Jacobowitz
  0 siblings, 0 replies; 54+ messages in thread
From: Daniel Jacobowitz @ 2002-03-02 19:59 UTC (permalink / raw)
  To: davidm; +Cc: Richard Henderson, GNU libc hacker, binutils

On Fri, Mar 01, 2002 at 05:36:43PM -0800, David Mosberger wrote:
> >>>>> On Fri, 1 Mar 2002 17:25:58 -0800, Richard Henderson <rth@redhat.com> said:
> 
>   Rich> On Fri, Mar 01, 2002 at 05:16:12PM -0800, David Mosberger wrote:
>   >> OK, that's what I did.  Could this be applied to the relevant branches?
> 
>   Rich> Applied to mainline.
> 
> Thanks!
> 
> 
>   Rich> IIRC, the 2.12 branch is closed.
> 
> Daniel, are you overseeing the 2.12 branch?  If so, any chance to make
> an exception for this change?  My hope is the patch is trivial enough
> to be considered safe and it would certainly help getting the
> remaining unwind-related bugs ironed out of ia64 linux.  It should
> also help freebsd/ia64 to get this right from the start.

Distributions can apply the patch, and we can try to put it in 2.12.1. 
As evidenced by the discussions of the past few days, and Christian's
comment on build failures, I think it's not quite ready.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 14:07                                           ` H . J . Lu
@ 2002-03-02 23:22                                             ` H . J . Lu
  2002-03-03  0:32                                               ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-02 23:22 UTC (permalink / raw)
  To: davidm; +Cc: binutils, GNU C Library, gcc

On Sat, Mar 02, 2002 at 02:07:49PM -0800, H . J . Lu wrote:
> On Sat, Mar 02, 2002 at 01:56:56PM -0800, David Mosberger wrote:
> > >>>>> On Sat, 2 Mar 2002 13:43:44 -0800, "H . J . Lu" <hjl@lucon.org> said:
> > 
> >   HJ> I noticed 2 problems:
> > 
> >   HJ> 1. glibc doesn't support .*_array in executales. elf/dl-init.c is not
> >   HJ> used on executables. However, sysdeps/generic/libc-start.c doesn't
> >   HJ> know how to do it. Glibc needs to be modified to call those functions
> >   HJ> with __*_array_start/__*_array_end.
> > 
> > Yes, I noticed that, too.  Wouldn't libc-start.c also have to call the
> > preinit array if the program is statically linked?
> 
> Yes.
> 

There is another problem. The preinit array is only allowed in
executables. ld should generate it for DSOs. We need to check
that.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-02 23:22                                             ` H . J . Lu
@ 2002-03-03  0:32                                               ` H . J . Lu
  2002-03-03  0:37                                                 ` Richard Henderson
  2002-03-04  3:06                                                 ` Alan Modra
  0 siblings, 2 replies; 54+ messages in thread
From: H . J . Lu @ 2002-03-03  0:32 UTC (permalink / raw)
  To: davidm; +Cc: binutils, GNU C Library, gcc

On Sat, Mar 02, 2002 at 11:22:01PM -0800, H . J . Lu wrote:
> On Sat, Mar 02, 2002 at 02:07:49PM -0800, H . J . Lu wrote:
> > On Sat, Mar 02, 2002 at 01:56:56PM -0800, David Mosberger wrote:
> > > >>>>> On Sat, 2 Mar 2002 13:43:44 -0800, "H . J . Lu" <hjl@lucon.org> said:
> > > 
> > >   HJ> I noticed 2 problems:
> > > 
> > >   HJ> 1. glibc doesn't support .*_array in executales. elf/dl-init.c is not
> > >   HJ> used on executables. However, sysdeps/generic/libc-start.c doesn't
> > >   HJ> know how to do it. Glibc needs to be modified to call those functions
> > >   HJ> with __*_array_start/__*_array_end.
> > > 
> > > Yes, I noticed that, too.  Wouldn't libc-start.c also have to call the
> > > preinit array if the program is statically linked?
> > 
> > Yes.
> > 
> 
> There is another problem. The preinit array is only allowed in
> executables. ld should generate it for DSOs. We need to check
> that.
> 
> 

Here is an updated patch. I also changed gas not to complain

	.section        .init_array,"aw",@progbits


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

	* elf.c (bfd_section_from_shdr): Handle special sections,
	.init_array, .fini_array and .preinit_array.
	(elf_fake_sections): Likewise.

	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Create the
	DT entry only if the section is in output for .init_array,
	.fini_array and .preinit_array. Complain about .preinit_array
	section in DSO.

	* elfxx-ia64.c (elfNN_ia64_section_from_shdr): Remove
	SHT_INIT_ARRAY, SHT_FINI_ARRAY and SHT_PREINIT_ARRAY.
	(elfNN_ia64_fake_sections): Remove .init_array, .fini_array and
	.preinit_array.

2002-03-02  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.

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

	* scripttempl/elf.sc: Fix a few typos. Put .preinit_array,
	.init_array and .fini_array in the data segment. Don't provide
	__preinit_array_start/__preinit_array_end labels for shared
	library.

--- binutils/bfd/elf.c.array	Tue Feb 19 15:17:40 2002
+++ binutils/bfd/elf.c	Sat Mar  2 09:55:43 2002
@@ -1564,6 +1564,9 @@ bfd_section_from_shdr (abfd, shindex)
     case SHT_NOBITS:	/* .bss section.  */
     case SHT_HASH:	/* .hash section.  */
     case SHT_NOTE:	/* .note section.  */
+    case SHT_INIT_ARRAY:	/* .init_array section.  */
+    case SHT_FINI_ARRAY:	/* .fini_array section.  */
+    case SHT_PREINIT_ARRAY:	/* .preinit_array section.  */
       return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
 
     case SHT_SYMTAB:		/* A symbol table */
@@ -2178,6 +2181,12 @@ elf_fake_sections (abfd, asect, failedpt
       this_hdr->sh_type = SHT_REL;
       this_hdr->sh_entsize = bed->s->sizeof_rel;
     }
+  else if (strcmp (asect->name, ".init_array") == 0)
+    this_hdr->sh_type = SHT_INIT_ARRAY;
+  else if (strcmp (asect->name, ".fini_array") == 0)
+    this_hdr->sh_type = SHT_FINI_ARRAY;
+  else if (strcmp (asect->name, ".preinit_array") == 0)
+    this_hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strncmp (asect->name, ".note", 5) == 0)
     this_hdr->sh_type = SHT_NOTE;
   else if (strncmp (asect->name, ".stab", 5) == 0
--- binutils/bfd/elflink.h.array	Fri Mar  1 23:44:22 2002
+++ binutils/bfd/elflink.h	Sun Mar  3 00:23:43 2002
@@ -3197,9 +3197,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
      struct bfd_elf_version_tree *verdefs;
 {
   bfd_size_type soname_indx;
-  bfd *dynobj, *sub;
-  asection *o;
-  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
+  bfd *dynobj;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3370,27 +3368,36 @@ NAME(bfd_elf,size_dynamic_sections) (out
 	    return false;
 	}
 
-      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
-	for (o = sub->sections; o != NULL; o = o->next)
-	  {
-	    /* yuck, more matching by name... */
-
-	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
-	      need_preinit_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
-	      need_init_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
-	      need_fini_array = 1;
-	  }
-      if (need_preinit_array)
+      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
 	{
+	  /* DT_PREINIT_ARRAY is not allowed in shared library.  */
+	  if (info->shared)
+	    {
+	      bfd *sub;
+	      asection *o;
+
+	      for (sub = info->input_bfds; sub != NULL;
+		   sub = sub->link_next)
+		for (o = sub->sections; o != NULL; o = o->next)
+		  if (elf_section_data (o)->this_hdr.sh_type
+		      == SHT_PREINIT_ARRAY)
+		    {
+		      (*_bfd_error_handler)
+			(_("%s: .preinit_array section not allowed in DSO"),
+			  bfd_archive_filename (sub));
+		      break;
+		    }
+
+	      return false;
+	    }
+
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
 				      (bfd_vma) 0)
 	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
 					 (bfd_vma) 0))
 	    return false;
 	}
-      if (need_init_array)
+      if (bfd_get_section_by_name (output_bfd, ".init_array") != NULL)
 	{
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
 				      (bfd_vma) 0)
@@ -3398,7 +3405,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
 					 (bfd_vma) 0))
 	    return false;
 	}
-      if (need_fini_array)
+      if (bfd_get_section_by_name (output_bfd, ".fini_array") != NULL)
 	{
 	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
 				      (bfd_vma) 0)
--- binutils/bfd/elfxx-ia64.c.array	Tue Feb 19 15:18:24 2002
+++ binutils/bfd/elfxx-ia64.c	Sat Mar  2 10:21:20 2002
@@ -1016,9 +1016,6 @@ elfNN_ia64_section_from_shdr (abfd, hdr,
   switch (hdr->sh_type)
     {
     case SHT_IA_64_UNWIND:
-    case SHT_INIT_ARRAY:
-    case SHT_FINI_ARRAY:
-    case SHT_PREINIT_ARRAY:
     case SHT_IA_64_HP_OPT_ANOT:
       break;
 
@@ -1076,12 +1073,6 @@ elfNN_ia64_fake_sections (abfd, hdr, sec
     }
   else if (strcmp (name, ELF_STRING_ia64_archext) == 0)
     hdr->sh_type = SHT_IA_64_EXT;
-  else if (strcmp (name, ".init_array") == 0)
-    hdr->sh_type = SHT_INIT_ARRAY;
-  else if (strcmp (name, ".fini_array") == 0)
-    hdr->sh_type = SHT_FINI_ARRAY;
-  else if (strcmp (name, ".preinit_array") == 0)
-    hdr->sh_type = SHT_PREINIT_ARRAY;
   else if (strcmp (name, ".HP.opt_annot") == 0)
     hdr->sh_type = SHT_IA_64_HP_OPT_ANOT;
   else if (strcmp (name, ".reloc") == 0)
--- binutils/gas/config/obj-elf.c.array	Fri Mar  1 23:44:32 2002
+++ binutils/gas/config/obj-elf.c	Sat Mar  2 23:54:01 2002
@@ -595,6 +595,27 @@ static struct special_section const spec
   { ".rodata",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".rodata1",	SHT_PROGBITS,	SHF_ALLOC			},
   { ".text",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR	},
+#if 0
+  /* FIXME: The current gcc, as of 2002-03-03, will emit
+
+	.section .init_array,"aw",@progbits
+
+     for __attribute__ ((section (".init_array"))). "@progbits" marks
+     the incorrect section type. For now, we make them with
+     SHT_PROGBITS. BFD will fix the section type. Gcc should be changed
+     to emit
+
+	.section .init_array
+
+   */
+  { ".init_array",SHT_INIT_ARRAY, SHF_ALLOC + SHF_WRITE         }, 
+  { ".fini_array",SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE         },
+  { ".preinit_array",SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE   }, 
+#else
+  { ".init_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         }, 
+  { ".fini_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE         },
+  { ".preinit_array",SHT_PROGBITS, SHF_ALLOC + SHF_WRITE   }, 
+#endif
 
 #ifdef ELF_TC_SPECIAL_SECTIONS
   ELF_TC_SPECIAL_SECTIONS
--- binutils/gas/config/tc-ia64.h.array	Tue Jan 15 11:30:50 2002
+++ binutils/gas/config/tc-ia64.h	Sat Mar  2 00:10:52 2002
@@ -124,8 +124,6 @@ extern void ia64_after_parse_args PARAMS
 #define WORKING_DOT_WORD	/* don't do broken word processing for now */
 
 #define ELF_TC_SPECIAL_SECTIONS						   \
-{ ".init_array",SHT_INIT_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
-{ ".fini_array",SHT_FINI_ARRAY,	SHF_ALLOC + SHF_WRITE                   }, \
 { ".sbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, \
 { ".sdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
 
--- binutils/ld/scripttempl/elf.sc.array	Fri Mar  1 23:45:33 2002
+++ binutils/ld/scripttempl/elf.sc	Sun Mar  3 00:11:08 2002
@@ -246,23 +246,6 @@ cat <<EOF
     ${RELOCATING+${INIT_END}}
   } =${NOP-0}
 
-  /* Ensure the __preinit_array_start label is properly aligned.  We
-     could instead move the label definition inside the section, but
-     the linker would then create the section even if it turns out to
-     be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT})}
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
-  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
-  .init_array   ${RELOCATING-0} : { *(.init_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
-  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
-
   ${DATA_PLT-${BSS_PLT-${PLT}}}
   .text         ${RELOCATING-0} :
   {
@@ -293,6 +276,36 @@ cat <<EOF
   ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
+  /* Ensure the __preinit_array_start label is properly aligned.  We
+     could instead move the label definition inside the section, but
+     the linker would then create the section even if it turns out to
+     be empty, which isn't pretty.  */
+  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+EOF
+
+  if test "$LD_FLAG" = "shared" || test "$LD_FLAG" = "cshared"; then
+cat <<EOF
+  /* The preinit array is not allowed in the shared library. No need
+     to provide __preinit_array_start/__preinit_array_end labels.  */
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+EOF
+  else
+cat <<EOF
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
+  .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
+EOF
+  fi
+
+cat <<EOF
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
+  .init_array   ${RELOCATING-0} : { *(.init_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
+  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+
   .data         ${RELOCATING-0} :
   {
     ${RELOCATING+${DATA_START_SYMBOLS}}

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-03  0:32                                               ` H . J . Lu
@ 2002-03-03  0:37                                                 ` Richard Henderson
  2002-03-03  0:45                                                   ` H . J . Lu
  2002-03-04  3:06                                                 ` Alan Modra
  1 sibling, 1 reply; 54+ messages in thread
From: Richard Henderson @ 2002-03-03  0:37 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, binutils, GNU C Library, gcc

On Sun, Mar 03, 2002 at 12:32:08AM -0800, H . J . Lu wrote:
> +  /* FIXME: The current gcc, as of 2002-03-03, will emit
> +
> +	.section .init_array,"aw",@progbits
> +
> +     for __attribute__ ((section (".init_array"))). "@progbits" marks
> +     the incorrect section type. For now, we make them with
> +     SHT_PROGBITS. BFD will fix the section type. Gcc should be changed
> +     to emit
> +
> +	.section .init_array

That would be incorrect.  GCC must continue to emit _something_,
particularly for allocate and write.  Really, it should emit
@init_array or similar.



r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-03  0:37                                                 ` Richard Henderson
@ 2002-03-03  0:45                                                   ` H . J . Lu
  2002-03-03  0:48                                                     ` Richard Henderson
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-03  0:45 UTC (permalink / raw)
  To: Richard Henderson; +Cc: davidm, binutils, GNU C Library, gcc

On Sun, Mar 03, 2002 at 12:37:01AM -0800, Richard Henderson wrote:
> On Sun, Mar 03, 2002 at 12:32:08AM -0800, H . J . Lu wrote:
> > +  /* FIXME: The current gcc, as of 2002-03-03, will emit
> > +
> > +	.section .init_array,"aw",@progbits
> > +
> > +     for __attribute__ ((section (".init_array"))). "@progbits" marks
> > +     the incorrect section type. For now, we make them with
> > +     SHT_PROGBITS. BFD will fix the section type. Gcc should be changed
> > +     to emit
> > +
> > +	.section .init_array
> 
> That would be incorrect.  GCC must continue to emit _something_,
> particularly for allocate and write.  Really, it should emit
> @init_array or similar.
> 

Gcc doesn't emit

	.section .text,"ax",@progbits

does it? .init_array is no different from .text. It is just another
special ELF section. Gas should treat it just like .text by looking up
"special_sections". With my patch, it does.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-03  0:45                                                   ` H . J . Lu
@ 2002-03-03  0:48                                                     ` Richard Henderson
  2002-03-03  7:58                                                       ` Ian Lance Taylor
  0 siblings, 1 reply; 54+ messages in thread
From: Richard Henderson @ 2002-03-03  0:48 UTC (permalink / raw)
  To: H . J . Lu; +Cc: davidm, binutils, GNU C Library, gcc

On Sun, Mar 03, 2002 at 12:45:23AM -0800, H . J . Lu wrote:
> Gcc doesn't emit
> 
> 	.section .text,"ax",@progbits
> 
> does it?

But it should.

Ideally _all_ section handling would go through the same
routine, no exceptions.


r~

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-03  0:48                                                     ` Richard Henderson
@ 2002-03-03  7:58                                                       ` Ian Lance Taylor
  2002-03-03  8:27                                                         ` Andreas Schwab
  0 siblings, 1 reply; 54+ messages in thread
From: Ian Lance Taylor @ 2002-03-03  7:58 UTC (permalink / raw)
  To: Richard Henderson; +Cc: H . J . Lu, davidm, binutils, GNU C Library, gcc

Richard Henderson <rth@twiddle.net> writes:

> Ideally _all_ section handling would go through the same
> routine, no exceptions.

I agree.

However, I note that some sections are called out by name in the ELF
standard, and those are the ones which appear in the special_sections
array.  I don't know whether .init_array is called out by name in new
versions of the ELF standard.

Ian

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-03  7:58                                                       ` Ian Lance Taylor
@ 2002-03-03  8:27                                                         ` Andreas Schwab
  0 siblings, 0 replies; 54+ messages in thread
From: Andreas Schwab @ 2002-03-03  8:27 UTC (permalink / raw)
  To: binutils; +Cc: davidm, hjl, libc-alpha, gcc, rth

Ian Lance Taylor <ian@airs.com> writes:

|> Richard Henderson <rth@twiddle.net> writes:
|> 
|> > Ideally _all_ section handling would go through the same
|> > routine, no exceptions.
|> 
|> I agree.
|> 
|> However, I note that some sections are called out by name in the ELF
|> standard, and those are the ones which appear in the special_sections
|> array.  I don't know whether .init_array is called out by name in new
|> versions of the ELF standard.

All three .*_array sections are called out by name in the current ELF
standard.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-03  0:32                                               ` H . J . Lu
  2002-03-03  0:37                                                 ` Richard Henderson
@ 2002-03-04  3:06                                                 ` Alan Modra
  2002-03-04  8:29                                                   ` H . J . Lu
                                                                     ` (2 more replies)
  1 sibling, 3 replies; 54+ messages in thread
From: Alan Modra @ 2002-03-04  3:06 UTC (permalink / raw)
  To: H . J . Lu; +Cc: binutils

On Sun, Mar 03, 2002 at 12:32:08AM -0800, H . J . Lu wrote:
> 2002-03-02  H.J. Lu <hjl@gnu.org>
> 
> 	* elf.c (bfd_section_from_shdr): Handle special sections,
> 	.init_array, .fini_array and .preinit_array.
> 	(elf_fake_sections): Likewise.
> 
> 	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Create the
> 	DT entry only if the section is in output for .init_array,
> 	.fini_array and .preinit_array. Complain about .preinit_array
> 	section in DSO.
> 
> 	* elfxx-ia64.c (elfNN_ia64_section_from_shdr): Remove
> 	SHT_INIT_ARRAY, SHT_FINI_ARRAY and SHT_PREINIT_ARRAY.
> 	(elfNN_ia64_fake_sections): Remove .init_array, .fini_array and
> 	.preinit_array.
> 
> 2002-03-02  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.
> 
> 2002-03-02  H.J. Lu <hjl@gnu.org>
> 
> 	* scripttempl/elf.sc: Fix a few typos. Put .preinit_array,
> 	.init_array and .fini_array in the data segment. Don't provide
> 	__preinit_array_start/__preinit_array_end labels for shared
> 	library.

This is OK to commit, although you might like to use the following
elflink.h patch instead.  It's based on one of your earlier patches,
and has the advantage of being immune to people using custom linker
scripts that define symbols in the .init_array, .fini_array or
.preinit_array output sections.

Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.143
diff -u -p -r1.143 elflink.h
--- elflink.h	2002/03/02 01:24:50	1.143
+++ elflink.h	2002/03/04 10:47:08
@@ -3029,9 +3029,7 @@ NAME(bfd_elf,size_dynamic_sections) (out
      struct bfd_elf_version_tree *verdefs;
 {
   bfd_size_type soname_indx;
-  bfd *dynobj, *sub;
-  asection *o;
-  int need_preinit_array = 0, need_init_array = 0, need_fini_array = 0;
+  bfd *dynobj;
   struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
@@ -3071,6 +3069,9 @@ NAME(bfd_elf,size_dynamic_sections) (out
       struct elf_info_failed eif;
       struct elf_link_hash_entry *h;
       asection *dynstr;
+      bfd *sub;
+      asection *o;
+      int dt_done;
 
       *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
       BFD_ASSERT (*sinterpptr != NULL || info->shared);
@@ -3202,42 +3203,57 @@ NAME(bfd_elf,size_dynamic_sections) (out
 	    return false;
 	}
 
+      dt_done = 0;
       for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
 	for (o = sub->sections; o != NULL; o = o->next)
 	  {
-	    /* yuck, more matching by name... */
+	    int tag1, tag2;
 
-	    if (strcmp (bfd_section_name (sub, o), ".preinit_array") == 0)
-	      need_preinit_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".init_array") == 0)
-	      need_init_array = 1;
-	    if (strcmp (bfd_section_name (sub, o), ".fini_array") == 0)
-	      need_fini_array = 1;
+	    if (o->output_section == bfd_abs_section_ptr)
+	      continue;
+
+	    switch (elf_section_data (o)->this_hdr.sh_type)
+	      {
+	      default:
+		continue;
+
+	      case SHT_INIT_ARRAY:
+		if (dt_done & 1)
+		  continue;
+		dt_done |= 1;
+		tag1 = DT_INIT_ARRAY;
+		tag2 = DT_INIT_ARRAYSZ;
+		break;
+
+	      case SHT_FINI_ARRAY:
+		if (dt_done & 2)
+		  continue;
+		dt_done |= 2;
+		tag1 = DT_FINI_ARRAY;
+		tag2 = DT_FINI_ARRAYSZ;
+		break;
+
+	      case SHT_PREINIT_ARRAY:
+		/* DT_PREINIT_ARRAY is not allowed in a shared library.  */
+		if (info->shared)
+		  {
+		    (*_bfd_error_handler)
+		      (_("%s: .preinit_array section is not allowed in DSO"),
+		       bfd_archive_filename (sub));
+		    return false;
+		  }
+		if (dt_done & 4)
+		  continue;
+		dt_done |= 4;
+		tag1 = DT_PREINIT_ARRAY;
+		tag2 = DT_PREINIT_ARRAYSZ;
+		break;
+	      }
+
+	    if (!elf_add_dynamic_entry (info, (bfd_vma) tag1, (bfd_vma) 0)
+		|| !elf_add_dynamic_entry (info, (bfd_vma) tag2, (bfd_vma) 0))
+	      return false;
 	  }
-      if (need_preinit_array)
-	{
-	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
-				      (bfd_vma) 0)
-	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
-					 (bfd_vma) 0))
-	    return false;
-	}
-      if (need_init_array)
-	{
-	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
-				      (bfd_vma) 0)
-	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
-					 (bfd_vma) 0))
-	    return false;
-	}
-      if (need_fini_array)
-	{
-	  if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
-				      (bfd_vma) 0)
-	      || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
-					 (bfd_vma) 0))
-	    return false;
-	}
 
       dynstr = bfd_get_section_by_name (dynobj, ".dynstr");
       /* If .dynstr is excluded from the link, we don't want any of

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-04  3:06                                                 ` Alan Modra
@ 2002-03-04  8:29                                                   ` H . J . Lu
  2002-03-04 12:47                                                   ` H . J . Lu
  2002-03-12 20:04                                                   ` [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections Alan Modra
  2 siblings, 0 replies; 54+ messages in thread
From: H . J . Lu @ 2002-03-04  8:29 UTC (permalink / raw)
  To: binutils

On Mon, Mar 04, 2002 at 09:36:01PM +1030, Alan Modra wrote:
> 
> This is OK to commit, although you might like to use the following
> elflink.h patch instead.  It's based on one of your earlier patches,
> and has the advantage of being immune to people using custom linker
> scripts that define symbols in the .init_array, .fini_array or
> .preinit_array output sections.
> 

I don't like to check all input files for them. If people use
different linker scripts, they have to deal with it. Maybe we
can give warnings for empty output sections.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-04  3:06                                                 ` Alan Modra
  2002-03-04  8:29                                                   ` H . J . Lu
@ 2002-03-04 12:47                                                   ` H . J . Lu
  2002-03-04 17:35                                                     ` Alan Modra
  2002-03-12 20:04                                                   ` [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections Alan Modra
  2 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-04 12:47 UTC (permalink / raw)
  To: binutils

On Mon, Mar 04, 2002 at 09:36:01PM +1030, Alan Modra wrote:
> 
> This is OK to commit, although you might like to use the following
> elflink.h patch instead.  It's based on one of your earlier patches,
> and has the advantage of being immune to people using custom linker
> scripts that define symbols in the .init_array, .fini_array or
> .preinit_array output sections.
> 

I checked in the following patch. I don't think we should check every
input file for .preinit_array. If people use a custom linker script,
they will get a warning if there is an empty section.


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

	* elf.c (bfd_section_from_shdr): Handle special sections,
	.init_array, .fini_array and .preinit_array.
	(elf_fake_sections): Likewise.

	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Create the
	DT entry only if the section is in output for .init_array,
	.fini_array and .preinit_array. Complain about .preinit_array
	section in DSO.
	(elf_bfd_final_link): Warn zero size for .init_array,
	.fini_array and .preinit_array sections.

	* elfxx-ia64.c (elfNN_ia64_section_from_shdr): Remove
	SHT_INIT_ARRAY, SHT_FINI_ARRAY and SHT_PREINIT_ARRAY.
	(elfNN_ia64_fake_sections): Remove .init_array, .fini_array and
	.preinit_array.

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.

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

	* scripttempl/elf.sc: Put .preinit_array, .init_array and
	.fini_array in the data segment.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-04 12:47                                                   ` H . J . Lu
@ 2002-03-04 17:35                                                     ` Alan Modra
  2002-03-04 18:12                                                       ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: Alan Modra @ 2002-03-04 17:35 UTC (permalink / raw)
  To: H . J . Lu; +Cc: binutils

On Mon, Mar 04, 2002 at 12:47:35PM -0800, H . J . Lu wrote:
> On Mon, Mar 04, 2002 at 09:36:01PM +1030, Alan Modra wrote:
> > 
> > This is OK to commit, although you might like to use the following
> > elflink.h patch instead.  It's based on one of your earlier patches,
> > and has the advantage of being immune to people using custom linker
> > scripts that define symbols in the .init_array, .fini_array or
> > .preinit_array output sections.
> > 
> 
> I checked in the following patch. I don't think we should check every
> input file for .preinit_array.

Huh?  The code you checked in does exactly that, at least when
finding an output section of that name.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-04 17:35                                                     ` Alan Modra
@ 2002-03-04 18:12                                                       ` H . J . Lu
  2002-03-04 18:44                                                         ` .preinit_array Alan Modra
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-04 18:12 UTC (permalink / raw)
  To: binutils

On Tue, Mar 05, 2002 at 12:05:07PM +1030, Alan Modra wrote:
> On Mon, Mar 04, 2002 at 12:47:35PM -0800, H . J . Lu wrote:
> > On Mon, Mar 04, 2002 at 09:36:01PM +1030, Alan Modra wrote:
> > > 
> > > This is OK to commit, although you might like to use the following
> > > elflink.h patch instead.  It's based on one of your earlier patches,
> > > and has the advantage of being immune to people using custom linker
> > > scripts that define symbols in the .init_array, .fini_array or
> > > .preinit_array output sections.
> > > 
> > 
> > I checked in the following patch. I don't think we should check every
> > input file for .preinit_array.
> 
> Huh?  The code you checked in does exactly that, at least when
> finding an output section of that name.
> 

There won't be an output .preinit_array section if there is no input
.preinit_array section. I think the .preinit_array is very rare.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* .preinit_array
  2002-03-04 18:12                                                       ` H . J . Lu
@ 2002-03-04 18:44                                                         ` Alan Modra
  2002-03-04 18:48                                                           ` .preinit_array H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: Alan Modra @ 2002-03-04 18:44 UTC (permalink / raw)
  To: H . J . Lu; +Cc: binutils

My copy of the draft spec says:

".preinit_array
This section holds an array of function pointers that contributes to a
single pre-initialization array for the executable or shared object
containing the section."

From the above, it seems incorrect to exclude .preinit_array from
shared libs.  Do you have an updated spec?

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: .preinit_array
  2002-03-04 18:44                                                         ` .preinit_array Alan Modra
@ 2002-03-04 18:48                                                           ` H . J . Lu
       [not found]                                                             ` <20020305030613.GN1090@bubble.sa.bigpond.net.au>
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-04 18:48 UTC (permalink / raw)
  To: binutils

On Tue, Mar 05, 2002 at 01:14:03PM +1030, Alan Modra wrote:
> My copy of the draft spec says:
> 
> ".preinit_array
> This section holds an array of function pointers that contributes to a
> single pre-initialization array for the executable or shared object
> containing the section."
> 
> >From the above, it seems incorrect to exclude .preinit_array from
> shared libs.  Do you have an updated spec?
> 

Mine says:

Initialization and Termination Functions

...

     Finally, an executable file may have pre-initialization functions. These   
     functions are executed after the dynamic linker has built the process      
     image and performed relocations but before any shared object               
     initialization functions. Pre-initialization functions are not permitted   
     in shared objects.                                                         


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: .preinit_array
       [not found]                                                             ` <20020305030613.GN1090@bubble.sa.bigpond.net.au>
@ 2002-03-04 23:00                                                               ` H . J . Lu
  0 siblings, 0 replies; 54+ messages in thread
From: H . J . Lu @ 2002-03-04 23:00 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

On Tue, Mar 05, 2002 at 01:36:13PM +1030, Alan Modra wrote:
> On Mon, Mar 04, 2002 at 06:48:06PM -0800, H . J . Lu wrote:
> > > shared libs.  Do you have an updated spec?
> > 
> > Mine says:
> 
> Where can I get spec update?
> 

http://www.caldera.com/developers/gabi/latest/ch5.dynamic.html#init_fini



H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-04  3:06                                                 ` Alan Modra
  2002-03-04  8:29                                                   ` H . J . Lu
  2002-03-04 12:47                                                   ` H . J . Lu
@ 2002-03-12 20:04                                                   ` Alan Modra
  2002-03-12 21:32                                                     ` H . J . Lu
  2 siblings, 1 reply; 54+ messages in thread
From: Alan Modra @ 2002-03-12 20:04 UTC (permalink / raw)
  To: binutils

On Mon, Mar 04, 2002 at 09:36:01PM +1030, Alan Modra wrote:
> 
> This is OK to commit, although you might like to use the following
> elflink.h patch instead.

Grumble.  OK, I'll commit it.

	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Use ELF section
	types instead of section names to determine whether init/fini array
	dynamic tags are needed.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-12 20:04                                                   ` [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections Alan Modra
@ 2002-03-12 21:32                                                     ` H . J . Lu
  2002-03-12 21:59                                                       ` Alan Modra
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-12 21:32 UTC (permalink / raw)
  To: binutils

On Wed, Mar 13, 2002 at 02:34:10PM +1030, Alan Modra wrote:
> On Mon, Mar 04, 2002 at 09:36:01PM +1030, Alan Modra wrote:
> > 
> > This is OK to commit, although you might like to use the following
> > elflink.h patch instead.
> 
> Grumble.  OK, I'll commit it.
> 
> 	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Use ELF section
> 	types instead of section names to determine whether init/fini array
> 	dynamic tags are needed.

I don't like this change. Those .xxxx_array sections are special
sections in the gABI. The linker script depends on that. Unless you
also change the linker script, it doesn't make much senses to use
section types here.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-12 21:32                                                     ` H . J . Lu
@ 2002-03-12 21:59                                                       ` Alan Modra
  2002-03-12 22:42                                                         ` H . J . Lu
  0 siblings, 1 reply; 54+ messages in thread
From: Alan Modra @ 2002-03-12 21:59 UTC (permalink / raw)
  To: H . J . Lu; +Cc: binutils

On Tue, Mar 12, 2002 at 09:32:10PM -0800, H . J . Lu wrote:
> On Wed, Mar 13, 2002 at 02:34:10PM +1030, Alan Modra wrote:
> > 	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Use ELF section
> > 	types instead of section names to determine whether init/fini array
> > 	dynamic tags are needed.
> 
> I don't like this change. Those .xxxx_array sections are special
> sections in the gABI. The linker script depends on that. Unless you
> also change the linker script, it doesn't make much senses to use
> section types here.

It is one less place where we do magic things depending on section
name.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-12 21:59                                                       ` Alan Modra
@ 2002-03-12 22:42                                                         ` H . J . Lu
  2002-03-12 23:24                                                           ` Alan Modra
  0 siblings, 1 reply; 54+ messages in thread
From: H . J . Lu @ 2002-03-12 22:42 UTC (permalink / raw)
  To: binutils

On Wed, Mar 13, 2002 at 04:29:07PM +1030, Alan Modra wrote:
> On Tue, Mar 12, 2002 at 09:32:10PM -0800, H . J . Lu wrote:
> > On Wed, Mar 13, 2002 at 02:34:10PM +1030, Alan Modra wrote:
> > > 	* elflink.h (NAME(bfd_elf,size_dynamic_sections)): Use ELF section
> > > 	types instead of section names to determine whether init/fini array
> > > 	dynamic tags are needed.
> > 
> > I don't like this change. Those .xxxx_array sections are special
> > sections in the gABI. The linker script depends on that. Unless you
> > also change the linker script, it doesn't make much senses to use
> > section types here.
> 
> It is one less place where we do magic things depending on section
> name.

It doesn't buy you anything. The only thing it does is to scan all
sections in input files for no good reason. However, I don't mind
checking the section type of the output section. But I don't think it
works.

BTW, those sections are magic in the gABI.


H.J.

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
  2002-03-12 22:42                                                         ` H . J . Lu
@ 2002-03-12 23:24                                                           ` Alan Modra
  0 siblings, 0 replies; 54+ messages in thread
From: Alan Modra @ 2002-03-12 23:24 UTC (permalink / raw)
  To: H . J . Lu; +Cc: binutils

On Tue, Mar 12, 2002 at 10:42:46PM -0800, H . J . Lu wrote:
> 
> The only thing it does is to scan all
> sections in input files for no good reason.

You've got a point there.  Reverting.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2002-03-13  7:24 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <m3g03lfd1g.fsf@myware.mynet>
2002-02-28 17:10 ` [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections H . J . Lu
2002-02-28 17:28   ` David Mosberger
2002-02-28 17:33     ` Ulrich Drepper
2002-02-28 17:43     ` H . J . Lu
2002-02-28 17:54       ` David Mosberger
2002-02-28 18:01         ` Richard Henderson
2002-02-28 18:05           ` David Mosberger
2002-02-28 18:14           ` H . J . Lu
2002-02-28 21:01             ` Richard Henderson
2002-02-28 22:52           ` David Mosberger
2002-02-28 23:18             ` Richard Henderson
2002-03-01 10:24               ` David Mosberger
2002-03-01 16:47                 ` Richard Henderson
2002-03-01 16:56                   ` David Mosberger
2002-03-01 17:00                     ` Richard Henderson
2002-03-01 17:20                       ` David Mosberger
2002-03-01 17:26                         ` Richard Henderson
2002-03-01 17:36                           ` David Mosberger
2002-03-02 19:59                             ` Daniel Jacobowitz
2002-03-01 21:34                       ` Alan Modra
2002-03-02  0:36                 ` H . J . Lu
2002-03-02  2:19                   ` Alan Modra
2002-03-02  9:24                     ` David Mosberger
2002-03-02 10:59                       ` H . J . Lu
2002-03-02 11:13                         ` David Mosberger
2002-03-02 11:27                           ` H . J . Lu
     [not found]                             ` <15489.10696.478128.294511@napali.hpl.hp.com>
2002-03-02 12:28                               ` H . J . Lu
2002-03-02 12:40                                 ` David Mosberger
2002-03-02 12:54                                   ` H . J . Lu
2002-03-02 12:57                                     ` David Mosberger
2002-03-02 13:43                                       ` H . J . Lu
2002-03-02 13:57                                         ` David Mosberger
2002-03-02 14:07                                           ` H . J . Lu
2002-03-02 23:22                                             ` H . J . Lu
2002-03-03  0:32                                               ` H . J . Lu
2002-03-03  0:37                                                 ` Richard Henderson
2002-03-03  0:45                                                   ` H . J . Lu
2002-03-03  0:48                                                     ` Richard Henderson
2002-03-03  7:58                                                       ` Ian Lance Taylor
2002-03-03  8:27                                                         ` Andreas Schwab
2002-03-04  3:06                                                 ` Alan Modra
2002-03-04  8:29                                                   ` H . J . Lu
2002-03-04 12:47                                                   ` H . J . Lu
2002-03-04 17:35                                                     ` Alan Modra
2002-03-04 18:12                                                       ` H . J . Lu
2002-03-04 18:44                                                         ` .preinit_array Alan Modra
2002-03-04 18:48                                                           ` .preinit_array H . J . Lu
     [not found]                                                             ` <20020305030613.GN1090@bubble.sa.bigpond.net.au>
2002-03-04 23:00                                                               ` .preinit_array H . J . Lu
2002-03-12 20:04                                                   ` [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections Alan Modra
2002-03-12 21:32                                                     ` H . J . Lu
2002-03-12 21:59                                                       ` Alan Modra
2002-03-12 22:42                                                         ` H . J . Lu
2002-03-12 23:24                                                           ` Alan Modra
2002-02-28 18:11         ` H . J . Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).