This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: .init_array/.fini_array


On Mon, Oct 21, 2002 at 09:37:34AM -0700, Steve Ellcey wrote:
> 
> I have a question about the .init_array and .fini_array ELF sections.
> In gas/config/obj-elf.c these are defined as standard SHT_PROGBITS
> sections instead of special SHT_INIT_ARRAY or SHT_FINI_ARRAY sections.
> The file contains the comment:
> 
>   /* 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
> 
> I was wondering if there has been any change in this status?  On HP-UX
> IA64 I am using the HP linker and it handles these sections so I would
> like them to have their correct definitions.
> 
> Rather then use
> 
> 	.section .init_array
> 
> in GCC I am currently putting out:
> 
> 	.section	.init_array,	"aw",	"init_array"
> 
> for this section based on CTORS_SECTION_ASM_OP in config/ia64/hpux.h and
> I need the correct definition of .init_array/.fini_array/.preinit_array
> for this to work.

Hmm, current gcc still emits

 .section .init_array,"aw",@progbits

for

int foo (void) { return 1; }
int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;

gcc really needs fixing first, otherwise we'll get flooded with bug
reports that gas is complaining about incorrect section types.

Like this.

gcc/ChangeLog
	* output.h (SECTION_NOTYPE): Define.
	* varasm.c (default_section_type_flags_1): Set SECTION_NOTYPE for
	init array sections.
	(default_elf_asm_named_section): Mind SECTION_NOTYPE.
	* config/arm/arm.c (arm_elf_asm_named_section): Likewise.  Also
	merge TLS support.

When the above is OK'd for mainline gcc I'll commit the following
gas patch.

gas/ChangeLog
	* config/obj-elf.c (special_sections): Use correct types for init
	array sections.
	(obj_elf_change_section): Don't mess with init array section type.

Index: gcc/output.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/output.h,v
retrieving revision 1.113
diff -u -p -r1.113 output.h
--- gcc/output.h	26 Sep 2002 22:25:12 -0000	1.113
+++ gcc/output.h	22 Oct 2002 02:03:28 -0000
@@ -485,7 +485,8 @@ extern void no_asm_to_stream PARAMS ((FI
 					   embedded zeros */
 #define SECTION_OVERRIDE 0x20000	/* allow override of default flags */
 #define SECTION_TLS	 0x40000	/* contains thread-local storage */
-#define SECTION_MACH_DEP 0x80000	/* subsequent bits reserved for target */
+#define SECTION_NOTYPE	 0x80000	/* don't output @progbits */
+#define SECTION_MACH_DEP 0x100000	/* subsequent bits reserved for target */
 
 extern unsigned int get_named_section_flags PARAMS ((const char *));
 extern bool set_named_section_flags	PARAMS ((const char *, unsigned int));
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.315
diff -u -p -r1.315 varasm.c
--- gcc/varasm.c	11 Oct 2002 01:28:24 -0000	1.315
+++ gcc/varasm.c	22 Oct 2002 02:03:36 -0000
@@ -4828,6 +4828,12 @@ default_section_type_flags_1 (decl, name
       || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
     flags |= SECTION_TLS;
 
+  if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
+      && (strcmp (name, ".init_array") == 0
+	  || strcmp (name, ".fini_array") == 0
+	  || strcmp (name, ".preinit_array") == 0))
+    flags |= SECTION_NOTYPE;
+
   return flags;
 }
 
@@ -4850,7 +4856,6 @@ default_elf_asm_named_section (name, fla
      unsigned int flags;
 {
   char flagchars[10], *f = flagchars;
-  const char *type;
 
   if (! named_section_first_declaration (name))
     {
@@ -4874,17 +4879,24 @@ default_elf_asm_named_section (name, fla
     *f++ = 'T';
   *f = '\0';
 
-  if (flags & SECTION_BSS)
-    type = "nobits";
-  else
-    type = "progbits";
-
-  if (flags & SECTION_ENTSIZE)
-    fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
-	     name, flagchars, type, flags & SECTION_ENTSIZE);
-  else
-    fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
-	     name, flagchars, type);
+  fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
+
+  if (!(flags & SECTION_NOTYPE))
+    {
+      const char *type;
+
+      if (flags & SECTION_BSS)
+	type = "nobits";
+      else
+	type = "progbits";
+
+      fprintf (asm_out_file, ",@%s", type);
+
+      if (flags & SECTION_ENTSIZE)
+	fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
+    }
+
+  putc ('\n', asm_out_file);
 }
 
 void
Index: gcc/config/arm/arm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.237
diff -u -p -r1.237 arm.c
--- gcc/config/arm/arm.c	20 Oct 2002 22:37:09 -0000	1.237
+++ gcc/config/arm/arm.c	22 Oct 2002 02:46:10 -0000
@@ -11068,8 +11068,13 @@ arm_elf_asm_named_section (name, flags)
      const char *name;
      unsigned int flags;
 {
-  char flagchars[8], *f = flagchars;
-  const char *type;
+  char flagchars[10], *f = flagchars;
+
+  if (! named_section_first_declaration (name))
+    {
+      fprintf (asm_out_file, "\t.section\t%s\n", name);
+      return;
+    }
 
   if (!(flags & SECTION_DEBUG))
     *f++ = 'a';
@@ -11083,19 +11088,28 @@ arm_elf_asm_named_section (name, flags)
     *f++ = 'M';
   if (flags & SECTION_STRINGS)
     *f++ = 'S';
+  if (flags & SECTION_TLS)
+    *f++ = 'T';
   *f = '\0';
 
-  if (flags & SECTION_BSS)
-    type = "nobits";
-  else
-    type = "progbits";
-
-  if (flags & SECTION_ENTSIZE)
-    fprintf (asm_out_file, "\t.section\t%s,\"%s\",%%%s,%d\n",
-	     name, flagchars, type, flags & SECTION_ENTSIZE);
-  else
-    fprintf (asm_out_file, "\t.section\t%s,\"%s\",%%%s\n",
-	     name, flagchars, type);
+  fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
+
+  if (!(flags & SECTION_NOTYPE))
+    {
+      const char *type;
+
+      if (flags & SECTION_BSS)
+	type = "nobits";
+      else
+	type = "progbits";
+
+      fprintf (asm_out_file, ",%%%s", type);
+
+      if (flags & SECTION_ENTSIZE)
+	fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
+    }
+
+  putc ('\n', asm_out_file);
 }
 #endif
 


Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.55
diff -u -p -r1.55 obj-elf.c
--- gas/config/obj-elf.c	17 Sep 2002 07:38:14 -0000	1.55
+++ gas/config/obj-elf.c	22 Oct 2002 00:25:59 -0000
@@ -617,27 +617,9 @@ static struct special_section const spec
   { ".tbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_TLS	},
   { ".tdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_TLS	},
   { ".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
@@ -707,7 +689,16 @@ obj_elf_change_section (name, type, attr
 	  type = special_sections[i].type;
 	else if (type != special_sections[i].type)
 	  {
-	    if (old_sec == NULL)
+	    if (old_sec == NULL
+		/* FIXME: gcc, as of 2002-10-22, will emit
+
+		   .section .init_array,"aw",@progbits
+
+		   for __attribute__ ((section (".init_array"))).
+		   "@progbits" is incorrect.  */
+		&& special_sections[i].type != SHT_INIT_ARRAY
+		&& special_sections[i].type != SHT_FINI_ARRAY
+		&& special_sections[i].type != SHT_PREINIT_ARRAY)
 	      {
 		as_warn (_("setting incorrect section type for %s"), name);
 	      }

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]