This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
- From: "H . J . Lu" <hjl at lucon dot org>
- To: davidm at hpl dot hp dot com
- Cc: Richard Henderson <rth at redhat dot com>,Ulrich Drepper <drepper at redhat dot com>,GNU libc hacker <libc-hacker at sources dot redhat dot com>,binutils at sources dot redhat dot com
- Date: Sat, 2 Mar 2002 00:36:45 -0800
- Subject: Re: [David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections
- References: <m3g03lfd1g.fsf@myware.mynet> <20020228165851.A26168@lucon.org> <15486.55079.333535.999190@napali.hpl.hp.com> <20020228173311.A26728@lucon.org> <15486.56491.696020.742674@napali.hpl.hp.com> <20020228175426.A30756@redhat.com> <15487.8879.719511.86715@napali.hpl.hp.com> <20020228225757.A30933@redhat.com> <15487.51034.573513.390031@napali.hpl.hp.com>
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 },