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
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}}