[David Mosberger <davidm@hpl.hp.com>] problem with unwind info for .init/.fini sections

H . J . Lu hjl@lucon.org
Sat Mar 2 12:28:00 GMT 2002


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



More information about the Binutils mailing list