From 25e2787005c2139fd4d92b1c78ce170da77c1672 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 4 Mar 2002 20:41:55 +0000 Subject: [PATCH] 2002-03-04 H.J. Lu * 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. --- bfd/ChangeLog | 18 ++++++++++++++++++ bfd/elf.c | 9 +++++++++ bfd/elflink.h | 46 ++++++++++++++++++++++++++++------------------ bfd/elfxx-ia64.c | 9 --------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8c034facf0..cea2712dbb 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,21 @@ +2002-03-04 H.J. Lu + + * 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 Alan Modra * configure.in (WIN32LIBADD): Don't eval PICFLAG assignment. diff --git a/bfd/elf.c b/bfd/elf.c index 7f63b34adc..5221f722f4 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1563,6 +1563,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 */ @@ -2177,6 +2180,12 @@ elf_fake_sections (abfd, asect, failedptrarg) 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 diff --git a/bfd/elflink.h b/bfd/elflink.h index 7fd8b531d7..9f8f5f66b4 100644 --- a/bfd/elflink.h +++ b/bfd/elflink.h @@ -3029,9 +3029,7 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath, 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; @@ -3202,27 +3200,36 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath, 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 is 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) @@ -3230,7 +3237,7 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath, (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) @@ -5600,6 +5607,9 @@ elf_bfd_final_link (abfd, info) get_size: o = bfd_get_section_by_name (abfd, name); BFD_ASSERT (o != NULL); + if (o->_raw_size == 0) + (*_bfd_error_handler) + (_("warning: %s section has zero size"), name); dyn.d_un.d_val = o->_raw_size; elf_swap_dyn_out (dynobj, &dyn, dyncon); break; diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c index e458477010..8d71defb4b 100644 --- a/bfd/elfxx-ia64.c +++ b/bfd/elfxx-ia64.c @@ -1016,9 +1016,6 @@ elfNN_ia64_section_from_shdr (abfd, hdr, name) 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)