public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* RFC: Don't use section name to set ELF section data
@ 2003-06-14 19:14 H. J. Lu
  2003-06-19 19:17 ` Andreas Schwab
       [not found] ` <m3y901rluw.fsf@redhat.com>
  0 siblings, 2 replies; 11+ messages in thread
From: H. J. Lu @ 2003-06-14 19:14 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 140 bytes --]

Here is my first attempt. It passed "make check" on Linux/i386. I'd
like to know if I am on the right track before I finish my work.


H.J.

[-- Attachment #2: binutils-type-1.patch --]
[-- Type: text/plain, Size: 16883 bytes --]

bfd/

2003-06-14  H.J. Lu <hongjiu.lu@intel.com>

	* elf-bfd.h (elf_section_type). New.
	(elf_section_flags): New.

	* elf.c (special_section): New.
	(_bfd_elf_new_section_hook): Check special_section to set
	elf_section_type and elf_section_flags.
	(elf_fake_sections): Don't use section name to set ELF section
	data.

	* section.c (bfd_abs_section): Remove const.
	(bfd_und_section): Likewise.
	(bfd_com_section): Likewise.
	(bfd_ind_section): Likewise.

gas/

2003-06-14  H.J. Lu <hongjiu.lu@intel.com>

	* config/obj-elf.c (elf_get_sec_type_attr): New function.
	(special_section): Updated.
	(elf_sec_set_private_data): New function.
	(obj_elf_change_section): Call elf_get_sec_type_attr. Set
	elf_section_type and elf_section_flags.
	(obj_elf_section): Initialize type to -1.
	(elf_frob_file): Set SHT_GROUP.

	* config/obj-elf.h (obj_sec_set_private_data): New.
	(elf_sec_set_private_data): Declared.

	* subsegs.c (subseg_get): Call obj_sec_set_private_data if it
	is defined.

--- binutils/bfd/elf-bfd.h.type	2003-06-13 08:34:09.000000000 -0700
+++ binutils/bfd/elf-bfd.h	2003-06-14 09:55:40.000000000 -0700
@@ -1050,6 +1050,8 @@ struct bfd_elf_section_data
 };
 
 #define elf_section_data(sec)  ((struct bfd_elf_section_data*)sec->used_by_bfd)
+#define elf_section_type(sec)  (elf_section_data(sec)->this_hdr.sh_type)
+#define elf_section_flags(sec) (elf_section_data(sec)->this_hdr.sh_flags)
 #define elf_group_name(sec)    (elf_section_data(sec)->group.name)
 #define elf_group_id(sec)      (elf_section_data(sec)->group.id)
 #define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
--- binutils/bfd/elf.c.type	2003-06-13 08:34:09.000000000 -0700
+++ binutils/bfd/elf.c	2003-06-14 11:56:22.000000000 -0700
@@ -2231,6 +2231,35 @@ bfd_section_from_elf_index (abfd, index)
   return elf_elfsections (abfd)[index]->bfd_section;
 }
 
+struct special_section
+{
+  const char *name;
+  int type;
+  int attributes;
+  size_t length;
+};
+
+static struct special_section const special_sections[] =
+{
+  { ".dynamic",	SHT_DYNAMIC,	SHF_ALLOC,			0},
+  { ".dynstr",	SHT_STRTAB,	SHF_ALLOC,			0},
+  { ".dynsym",	SHT_DYNSYM,	SHF_ALLOC,			0},
+  { ".got",	SHT_PROGBITS,	0,				0},
+  { ".hash",	SHT_HASH,	SHF_ALLOC,			0},
+  { ".interp",	SHT_PROGBITS,	0,				0},
+  { ".plt",	SHT_PROGBITS,	0,				0},
+  { ".shstrtab",SHT_STRTAB,	0,				0},
+  { ".strtab",	SHT_STRTAB,	0,				0},
+  { ".symtab",	SHT_SYMTAB,	0,				0},
+  { ".gnu.version",SHT_GNU_versym,0,				0},
+  { ".gnu.version_d",SHT_GNU_verdef,0,				0},
+  { ".gnu.version_r",SHT_GNU_verneed,0,				0},
+  { ".note",	SHT_NOTE,	0,				5},
+  { ".rel",	SHT_REL,	0,				4},
+  { ".rela",	SHT_RELA,	0,				5},
+  { NULL,	0,		0,				0}
+};
+
 bfd_boolean
 _bfd_elf_new_section_hook (abfd, sec)
      bfd *abfd;
@@ -2241,11 +2270,37 @@ _bfd_elf_new_section_hook (abfd, sec)
   sdata = (struct bfd_elf_section_data *) sec->used_by_bfd;
   if (sdata == NULL)
     {
+      int i;
+
       bfd_size_type amt = sizeof (*sdata);
       sdata = (struct bfd_elf_section_data *) bfd_zalloc (abfd, amt);
       if (sdata == NULL)
 	return FALSE;
       sec->used_by_bfd = (PTR) sdata;
+
+      /* See if this is one of the special sections.  */
+      for (i = 0; special_sections[i].name != NULL; i++)
+	if (sec->name
+	    && ((special_sections[i].length
+		 && strncmp (sec->name, special_sections[i].name,
+			     special_sections[i].length) == 0)
+		|| strcmp (sec->name, special_sections[i].name) == 0))
+	  {
+	    elf_section_type (sec) = special_sections[i].type;
+	    elf_section_flags (sec) = special_sections[i].attributes;
+	    break;
+	  }
+      
+      if (special_sections[i].name == NULL)
+	{
+	  if (strncmp (sec->name, ".stab", 5) == 0
+	      && strcmp (sec->name
+			 + strlen (sec->name) - 3, "str") == 0)
+	    elf_section_type (sec) = SHT_STRTAB;
+	}
+
+      if (!elf_section_type (sec))
+	elf_section_type (sec) = (unsigned int) -1;
     }
 
   /* Indicate whether or not this section should use RELA relocations.  */
@@ -2486,55 +2541,52 @@ elf_fake_sections (abfd, asect, failedpt
   this_hdr->bfd_section = asect;
   this_hdr->contents = NULL;
 
-  /* FIXME: This should not be based on section names.  */
-  if (strcmp (asect->name, ".dynstr") == 0)
-    this_hdr->sh_type = SHT_STRTAB;
-  else if (strcmp (asect->name, ".hash") == 0)
+  switch (this_hdr->sh_type)
     {
-      this_hdr->sh_type = SHT_HASH;
+    default:
+      (*_bfd_error_handler)
+       (_("%s: Section `%s' has unknown type 0x%0x"),
+	bfd_get_filename (asect->owner), asect->name,
+	this_hdr->sh_type);
+      abort ();
+      break;
+
+    case SHT_STRTAB:
+    case SHT_INIT_ARRAY:
+    case SHT_FINI_ARRAY:
+    case SHT_PREINIT_ARRAY:
+    case SHT_NOTE:
+    case SHT_NOBITS:
+    case SHT_PROGBITS:
+      break;
+
+    case SHT_HASH:
       this_hdr->sh_entsize = bed->s->sizeof_hash_entry;
-    }
-  else if (strcmp (asect->name, ".dynsym") == 0)
-    {
-      this_hdr->sh_type = SHT_DYNSYM;
+      break;
+  
+    case SHT_DYNSYM:
       this_hdr->sh_entsize = bed->s->sizeof_sym;
-    }
-  else if (strcmp (asect->name, ".dynamic") == 0)
-    {
-      this_hdr->sh_type = SHT_DYNAMIC;
+      break;
+
+    case SHT_DYNAMIC:
       this_hdr->sh_entsize = bed->s->sizeof_dyn;
-    }
-  else if (strncmp (asect->name, ".rela", 5) == 0
-	   && get_elf_backend_data (abfd)->may_use_rela_p)
-    {
-      this_hdr->sh_type = SHT_RELA;
-      this_hdr->sh_entsize = bed->s->sizeof_rela;
-    }
-  else if (strncmp (asect->name, ".rel", 4) == 0
-	   && get_elf_backend_data (abfd)->may_use_rel_p)
-    {
-      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
-	   && strcmp (asect->name + strlen (asect->name) - 3, "str") == 0)
-    this_hdr->sh_type = SHT_STRTAB;
-  else if (strcmp (asect->name, ".gnu.version") == 0)
-    {
-      this_hdr->sh_type = SHT_GNU_versym;
+      break;
+
+    case SHT_RELA:
+      if (get_elf_backend_data (abfd)->may_use_rela_p)
+	this_hdr->sh_entsize = bed->s->sizeof_rela;
+      break;
+
+     case SHT_REL:
+      if (get_elf_backend_data (abfd)->may_use_rel_p)
+	this_hdr->sh_entsize = bed->s->sizeof_rel;
+      break;
+
+     case SHT_GNU_versym:
       this_hdr->sh_entsize = sizeof (Elf_External_Versym);
-    }
-  else if (strcmp (asect->name, ".gnu.version_d") == 0)
-    {
-      this_hdr->sh_type = SHT_GNU_verdef;
+      break;
+
+     case SHT_GNU_verdef:
       this_hdr->sh_entsize = 0;
       /* objcopy or strip will copy over sh_info, but may not set
          cverdefs.  The linker will set cverdefs, but sh_info will be
@@ -2544,10 +2596,9 @@ elf_fake_sections (abfd, asect, failedpt
       else
 	BFD_ASSERT (elf_tdata (abfd)->cverdefs == 0
 		    || this_hdr->sh_info == elf_tdata (abfd)->cverdefs);
-    }
-  else if (strcmp (asect->name, ".gnu.version_r") == 0)
-    {
-      this_hdr->sh_type = SHT_GNU_verneed;
+      break;
+
+    case SHT_GNU_verneed:
       this_hdr->sh_entsize = 0;
       /* objcopy or strip will copy over sh_info, but may not set
          cverrefs.  The linker will set cverrefs, but sh_info will be
@@ -2557,18 +2608,21 @@ elf_fake_sections (abfd, asect, failedpt
       else
 	BFD_ASSERT (elf_tdata (abfd)->cverrefs == 0
 		    || this_hdr->sh_info == elf_tdata (abfd)->cverrefs);
-    }
-  else if ((asect->flags & SEC_GROUP) != 0)
-    {
-      this_hdr->sh_type = SHT_GROUP;
+      break;
+
+    case SHT_GROUP:
       this_hdr->sh_entsize = 4;
-    }
-  else if ((asect->flags & SEC_ALLOC) != 0
-	   && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+      break;
+
+    case (unsigned int) -1:
+      if ((asect->flags & SEC_ALLOC) != 0
+	  && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
 	       || (asect->flags & SEC_NEVER_LOAD) != 0))
-    this_hdr->sh_type = SHT_NOBITS;
-  else
-    this_hdr->sh_type = SHT_PROGBITS;
+	this_hdr->sh_type = SHT_NOBITS;
+      else
+	this_hdr->sh_type = SHT_PROGBITS;
+      break;
+    }
 
   if ((asect->flags & SEC_ALLOC) != 0)
     this_hdr->sh_flags |= SHF_ALLOC;
--- binutils/bfd/section.c.type	2003-06-13 09:41:32.000000000 -0700
+++ binutils/bfd/section.c	2003-06-14 09:47:21.000000000 -0700
@@ -532,18 +532,18 @@ CODE_FRAGMENT
 .#define BFD_IND_SECTION_NAME "*IND*"
 .
 .{* The absolute section.  *}
-.extern const asection bfd_abs_section;
+.extern asection bfd_abs_section;
 .#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
 .#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
 .{* Pointer to the undefined section.  *}
-.extern const asection bfd_und_section;
+.extern asection bfd_und_section;
 .#define bfd_und_section_ptr ((asection *) &bfd_und_section)
 .#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
 .{* Pointer to the common section.  *}
-.extern const asection bfd_com_section;
+.extern asection bfd_com_section;
 .#define bfd_com_section_ptr ((asection *) &bfd_com_section)
 .{* Pointer to the indirect section.  *}
-.extern const asection bfd_ind_section;
+.extern asection bfd_ind_section;
 .#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
 .#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
 .
@@ -616,7 +616,7 @@ static const asymbol global_syms[] =
 
 #define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX)				\
   const asymbol * const SYM = (asymbol *) &global_syms[IDX]; 		\
-  const asection SEC = 							\
+  asection SEC = 							\
     /* name, id,  index, next, flags, user_set_vma, reloc_done,      */	\
     { NAME,  IDX, 0,     NULL, FLAGS, 0,            0,			\
 									\
--- binutils/gas/config/obj-elf.c.type	2003-06-13 08:34:09.000000000 -0700
+++ binutils/gas/config/obj-elf.c	2003-06-14 11:53:17.000000000 -0700
@@ -86,6 +86,8 @@ static void obj_elf_symver PARAMS ((int)
 static void obj_elf_subsection PARAMS ((int));
 static void obj_elf_popsection PARAMS ((int));
 static void obj_elf_tls_common PARAMS ((int));
+static bfd_boolean elf_get_sec_type_attr (const char *, bfd_boolean,
+					  int *, int *);
 
 static const pseudo_typeS elf_pseudo_table[] =
 {
@@ -631,9 +633,13 @@ 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	},
-  { ".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   },
+  { ".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	},
+  { ".debug_line",SHT_PROGBITS,	0				},
+  { ".debug_info",SHT_PROGBITS,	0				},
+  { ".debug_abbrev",SHT_PROGBITS,0				},
+  { ".debug_aranges",SHT_PROGBITS,0				},
 
 #ifdef ELF_TC_SPECIAL_SECTIONS
   ELF_TC_SPECIAL_SECTIONS
@@ -658,52 +664,22 @@ static struct special_section const spec
   { NULL,	0,		0				}
 };
 
-void
-obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push)
-     const char *name;
-     int type;
-     int attr;
-     int entsize;
-     const char *group_name;
-     int linkonce;
-     int push;
+static bfd_boolean
+elf_get_sec_type_attr (const char *name, bfd_boolean new,
+		       int *type, int *attr)
 {
-  asection *old_sec;
-  segT sec;
-  flagword flags;
   int i;
-
-#ifdef md_flush_pending_output
-  md_flush_pending_output ();
-#endif
-
-  /* Switch to the section, creating it if necessary.  */
-  if (push)
-    {
-      struct section_stack *elt;
-      elt = xmalloc (sizeof (struct section_stack));
-      elt->next = section_stack;
-      elt->seg = now_seg;
-      elt->prev_seg = previous_section;
-      elt->subseg = now_subseg;
-      elt->prev_subseg = previous_subsection;
-      section_stack = elt;
-    }
-  previous_section = now_seg;
-  previous_subsection = now_subseg;
-
-  old_sec = bfd_get_section_by_name (stdoutput, name);
-  sec = subseg_new (name, 0);
+  bfd_boolean found = FALSE;
 
   /* See if this is one of the special sections.  */
   for (i = 0; special_sections[i].name != NULL; i++)
     if (strcmp (name, special_sections[i].name) == 0)
       {
-	if (type == SHT_NULL)
-	  type = special_sections[i].type;
-	else if (type != special_sections[i].type)
+	if (*type == -1)
+	  *type = special_sections[i].type;
+	else if (*type != special_sections[i].type)
 	  {
-	    if (old_sec == NULL
+	    if (new
 		/* FIXME: gcc, as of 2002-10-22, will emit
 
 		   .section .init_array,"aw",@progbits
@@ -719,25 +695,89 @@ obj_elf_change_section (name, type, attr
 	    else
 	      {
 		as_warn (_("ignoring incorrect section type for %s"), name);
-		type = special_sections[i].type;
+		*type = special_sections[i].type;
 	      }
 	  }
-	if ((attr &~ special_sections[i].attributes) != 0
-	    && old_sec == NULL)
+	if (new && (*attr &~ special_sections[i].attributes) != 0)
 	  {
 	    /* As a GNU extension, we permit a .note section to be
 	       allocatable.  If the linker sees an allocateable .note
 	       section, it will create a PT_NOTE segment in the output
 	       file.  */
 	    if (strcmp (name, ".note") != 0
-		|| attr != SHF_ALLOC)
+		|| *attr != SHF_ALLOC)
 	      as_warn (_("setting incorrect section attributes for %s"),
 		       name);
 	  }
-	attr |= special_sections[i].attributes;
+	*attr |= special_sections[i].attributes;
+	found = TRUE;
 	break;
       }
 
+  return found;
+}
+
+void
+elf_sec_set_private_data (bfd *abfd, asection *sec)
+{
+  if (!_bfd_elf_new_section_hook (abfd, sec))
+    as_fatal (_("can't allocate ELF private section data: %s"),
+	      bfd_errmsg (bfd_get_error ()));
+
+  if (elf_section_type (sec) == (unsigned int) -1)
+    {
+      unsigned int type = -1, attr = 0;
+
+      if (elf_get_sec_type_attr (sec->name, TRUE, &type, &attr))
+	{
+	  elf_section_type (sec) = type;
+	  elf_section_flags (sec) = attr;
+	}
+    }
+}
+
+void
+obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push)
+     const char *name;
+     int type;
+     int attr;
+     int entsize;
+     const char *group_name;
+     int linkonce;
+     int push;
+{
+  asection *old_sec;
+  segT sec;
+  flagword flags;
+
+#ifdef md_flush_pending_output
+  md_flush_pending_output ();
+#endif
+
+  /* Switch to the section, creating it if necessary.  */
+  if (push)
+    {
+      struct section_stack *elt;
+      elt = xmalloc (sizeof (struct section_stack));
+      elt->next = section_stack;
+      elt->seg = now_seg;
+      elt->prev_seg = previous_section;
+      elt->subseg = now_subseg;
+      elt->prev_subseg = previous_subsection;
+      section_stack = elt;
+    }
+  previous_section = now_seg;
+  previous_subsection = now_subseg;
+
+  old_sec = bfd_get_section_by_name (stdoutput, name);
+  sec = subseg_new (name, 0);
+
+  if (elf_get_sec_type_attr (name, old_sec == NULL, &type, &attr))
+    {
+      elf_section_type (sec) = type;
+      elf_section_flags (sec) = attr;
+    }
+
   /* Convert ELF type and flags to BFD flags.  */
   flags = (SEC_RELOC
 	   | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
@@ -986,7 +1026,7 @@ obj_elf_section (push)
   name = obj_elf_section_name ();
   if (name == NULL)
     return;
-  type = SHT_NULL;
+  type = -1;
   attr = 0;
   group_name = NULL;
   entsize = 0;
@@ -2078,6 +2118,7 @@ elf_frob_file ()
 	  as_fatal (_("can't create group: %s"),
 		    bfd_errmsg (bfd_get_error ()));
 	}
+      elf_section_type (s) = SHT_GROUP;
 
       /* Pass a pointer to the first section in this group.  */
       elf_next_in_group (s) = list.head[i];
--- binutils/gas/config/obj-elf.h.type	2002-09-18 22:11:17.000000000 -0700
+++ binutils/gas/config/obj-elf.h	2003-06-14 11:06:34.000000000 -0700
@@ -134,6 +134,11 @@ int elf_s_get_other PARAMS ((symbolS *))
 
 extern asection *gdb_section;
 
+#ifndef obj_sec_set_private_data
+#define obj_sec_set_private_data elf_sec_set_private_data
+#endif
+extern void elf_sec_set_private_data (bfd *, asection *);
+
 #ifndef obj_frob_file
 #define obj_frob_file  elf_frob_file
 #endif
--- binutils/gas/subsegs.c.type	2002-12-08 13:41:58.000000000 -0800
+++ binutils/gas/subsegs.c	2003-06-14 11:06:45.000000000 -0700
@@ -422,6 +422,10 @@ subseg_get (segname, force_new)
   else
     secptr = bfd_make_section_anyway (stdoutput, segname);
 
+#ifdef obj_sec_set_private_data
+  obj_sec_set_private_data (stdoutput, secptr);
+#endif
+
   seginfo = seg_info (secptr);
   if (! seginfo)
     {

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: RFC: Don't use section name to set ELF section data
  2003-06-14 19:14 RFC: Don't use section name to set ELF section data H. J. Lu
@ 2003-06-19 19:17 ` Andreas Schwab
       [not found] ` <m3y901rluw.fsf@redhat.com>
  1 sibling, 0 replies; 11+ messages in thread
From: Andreas Schwab @ 2003-06-19 19:17 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> writes:

|> +  { ".rel",	SHT_REL,	0,				4},
|> +  { ".rela",	SHT_RELA,	0,				5},

I think you need to swap those two.  Otherwise a RELA section will always
be indentified as REL.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 11+ messages in thread

* PATCH: Don't use section name to set ELF section data
       [not found] ` <m3y901rluw.fsf@redhat.com>
@ 2003-07-25  1:36   ` H. J. Lu
  2003-07-25  4:48     ` Alan Modra
  2003-07-25 12:29     ` Nick Clifton
  0 siblings, 2 replies; 11+ messages in thread
From: H. J. Lu @ 2003-07-25  1:36 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

On Tue, Jun 17, 2003 at 12:20:55PM +0100, Nick Clifton wrote:
> Hi H.J.
> 
> > Here is my first attempt. It passed "make check" on Linux/i386. I'd 
> > like to know if I am on the right track before I finish my work.
> 
> In general this looks good.  Why is it necessary ?
> 
> A couple of points:
> 
> > +  { ".rel",	SHT_REL,	0,				4},
> > +  { ".rela",	SHT_RELA,	0,				5},
> 
> > +      for (i = 0; special_sections[i].name != NULL; i++)
> > +	if (sec->name
> > +	    && ((special_sections[i].length
> > +		 && strncmp (sec->name, special_sections[i].name,
> > +			     special_sections[i].length) == 0)
> > +		|| strcmp (sec->name, special_sections[i].name) == 0))
> > +	  {
> 
> This looks slightly wrong to me.  The ".rel" section name will always
> match a ".rela" section since it is tested first.  Plus the code does
> not check "get_elf_backend (abfd)->may_use_rela_p".
> 
> 
> 
> > +      if (special_sections[i].name == NULL)
> > +	{
> > +	  if (strncmp (sec->name, ".stab", 5) == 0
> > +	      && strcmp (sec->name
> > +			 + strlen (sec->name) - 3, "str") == 0)
> > +	    elf_section_type (sec) = SHT_STRTAB;
> > +	}
> 
> It would be more elegant, though probably less efficient, if this test
> could be incorporated into the special_sections[] array.
> 

Here is the new patch. It caused no regressions on all targets
affected. It fixed an ELF/ppc64 bug.


H.J.

[-- Attachment #2: binutils-type-2.patch --]
[-- Type: text/plain, Size: 49282 bytes --]

bfd/

2003-07-24  H.J. Lu  <hongjiu.lu@intel.com>

	* elf-bfd.h (bfd_elf_special_section): New.
	(elf_backend_data): Add special_sections, a pointer to
	bfd_elf_special_section.
	(elf_section_type). New.
	(elf_section_flags): New.
	(_bfd_elf_get_sec_type_attr): New.

	* elf.c (_bfd_elf_make_section_from_shdr): Always use the
	real section type/flags.
	(special_sections): New.
	(get_special_section): New.
	(_bfd_elf_get_sec_type_attr): New.
	(_bfd_elf_new_section_hook): Check special_section to set
	elf_section_type and elf_section_flags.
	(elf_fake_sections): Don't use section name to set ELF section
	data.

	* elf32-m32r.c (m32r_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf32-m68hc11.c (elf32_m68hc11_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf32-mcore.c (mcore_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf32-ppc.c (ppc_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf32-sh64.c (sh64_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf32-v850.c (v850_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf32-xtensa.c (elf_xtensa_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf64-alpha.c (elf64_alpha_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf64-hppa.c (elf64_hppa_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf64-ppc.c (ppc64_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elf64-sh64.c (sh64_elf64_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elfxx-ia64.c (elfNN_ia64_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elfxx-mips.c (_bfd_mips_elf_special_sections): New.

	* elfxx-mips.h (_bfd_mips_elf_special_sections): New.
	(elf_backend_special_sections): Defined.

	* elfxx-target.h (elf_backend_special_sections): New. Default
	to NULL.
	(elfNN_bed): Initialize special_sections.

	* section.c (bfd_abs_section): Remove const.
	(bfd_und_section): Likewise.
	(bfd_com_section): Likewise.
	(bfd_ind_section): Likewise.

gas/

2003-07-24  H.J. Lu  <hongjiu.lu@intel.com>

	* config/obj-elf.c (special_sections): Removed.
	(obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set
	elf_section_type and elf_section_flags.
	(elf_frob_file): Set SHT_GROUP.

	* config/obj-elf.h (obj_sec_set_private_data): New.

	* config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed.
	* config/tc-ia64.h: Likewise.
	* config/tc-m32r.h: Likewise.
	* config/tc-m68hc11.h: Likewise.
	* config/tc-mcore.h: Likewise.
	* config/tc-mips.h: Likewise.
	* config/tc-ppc.h: Likewise.
	* config/tc-sh64.h: Likewise.
	* config/tc-v850.h: Likewise.
	* config/tc-xtensa.h: Likewise.

	* config/tc-v850.h (SHF_V850_GPREL): Removed.
	(SHF_V850_EPREL): Likewise.
	(SHF_V850_R0REL): Likewise.

	* subsegs.c (subseg_get): Call obj_sec_set_private_data if it
	is defined.

include/elf/

2003-07-24  H.J. Lu  <hongjiu.lu@intel.com>

	* v850.h (SHF_V850_GPREL): New.
	(SHF_V850_EPREL): Likewise.
	(SHF_V850_R0REL): Likewise.

--- binutils/bfd/elf-bfd.h.type	2003-07-21 07:34:13.000000000 -0700
+++ binutils/bfd/elf-bfd.h	2003-07-24 10:02:04.000000000 -0700
@@ -510,6 +510,17 @@ typedef enum {
   ict_irix6
 } irix_compat_t;
 
+/* Mapping of ELF section names and types.  */
+struct bfd_elf_special_section
+{
+  const char *prefix;
+  size_t prefix_length;
+  const char *suffix;
+  size_t suffix_length;
+  int type;
+  int attributes;
+};
+
 struct elf_backend_data
 {
   /* The architecture for this backend.  */
@@ -871,6 +882,9 @@ struct elf_backend_data
 
   const struct elf_size_info *s;
 
+  /* An array of target specific special section map.  */
+  const struct bfd_elf_special_section *special_sections;
+
   /* offset of the _GLOBAL_OFFSET_TABLE_ symbol from the start of the
      .got section */
   bfd_vma got_symbol_offset;
@@ -1006,6 +1020,8 @@ struct bfd_elf_section_data
 };
 
 #define elf_section_data(sec)  ((struct bfd_elf_section_data*)sec->used_by_bfd)
+#define elf_section_type(sec)  (elf_section_data(sec)->this_hdr.sh_type)
+#define elf_section_flags(sec) (elf_section_data(sec)->this_hdr.sh_flags)
 #define elf_group_name(sec)    (elf_section_data(sec)->group.name)
 #define elf_group_id(sec)      (elf_section_data(sec)->group.id)
 #define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
@@ -1374,6 +1390,8 @@ extern bfd_boolean _bfd_elf_new_section_
   PARAMS ((bfd *, asection *));
 extern bfd_boolean _bfd_elf_init_reloc_shdr
   PARAMS ((bfd *, Elf_Internal_Shdr *, asection *, bfd_boolean));
+extern bfd_boolean _bfd_elf_get_sec_type_attr (bfd *, const char *,
+					       int *, int *);
 
 /* If the target doesn't have reloc handling written yet:  */
 extern void _bfd_elf_no_info_to_howto
--- binutils/bfd/elf.c.type	2003-07-08 07:22:49.000000000 -0700
+++ binutils/bfd/elf.c	2003-07-24 11:45:37.000000000 -0700
@@ -741,6 +741,10 @@ _bfd_elf_make_section_from_shdr (abfd, h
   if (newsect == NULL)
     return FALSE;
 
+  /* Always use the real type/flags.  */
+  elf_section_type (newsect) = hdr->sh_type;
+  elf_section_flags (newsect) = hdr->sh_flags;
+
   newsect->filepos = hdr->sh_offset;
 
   if (! bfd_set_section_vma (abfd, newsect, hdr->sh_addr)
@@ -2139,12 +2143,145 @@ bfd_section_from_elf_index (abfd, index)
   return elf_elfsections (abfd)[index]->bfd_section;
 }
 
+static struct bfd_elf_special_section const special_sections[] =
+{
+  { ".bss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE },
+  { ".comment",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".data",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".data1",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".debug",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".fini",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
+  { ".init",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
+  { ".line",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".rodata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".rodata1",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".tbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_TLS },
+  { ".tdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_TLS },
+  { ".text",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
+  { ".init_array",	0,	NULL,	0,
+    SHT_INIT_ARRAY,	SHF_ALLOC + SHF_WRITE },
+  { ".fini_array",	0,	NULL,	0,
+    SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE },
+  { ".preinit_array",	0,	NULL,	0,
+    SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE },
+  { ".debug_line",	0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".debug_info",	0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".debug_abbrev",	0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".debug_aranges",	0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".dynamic",		0,	NULL,	0,
+    SHT_DYNAMIC,	SHF_ALLOC },
+  { ".dynstr",		0,	NULL,	0,
+    SHT_STRTAB,		SHF_ALLOC },
+  { ".dynsym",		0,	NULL,	0,
+    SHT_DYNSYM,		SHF_ALLOC },
+  { ".got",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".hash",		0,	NULL,	0,
+    SHT_HASH,		SHF_ALLOC },
+  { ".interp",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".plt",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { ".shstrtab",	0,	NULL,	0,
+    SHT_STRTAB,		0 },
+  { ".strtab",		0,	NULL,	0,
+    SHT_STRTAB,		0 },
+  { ".symtab",		0,	NULL,	0,
+    SHT_SYMTAB,		0 },
+  { ".gnu.version",	0,	NULL,	0,
+    SHT_GNU_versym,	0 },
+  { ".gnu.version_d",	0,	NULL,	0,
+    SHT_GNU_verdef,	0 },
+  { ".gnu.version_r",	0,	NULL,	0,
+    SHT_GNU_verneed,	0 },
+  { ".note",		5,	NULL,	0,
+    SHT_NOTE,		0 },
+  { ".rela",		5,	NULL,	0,
+    SHT_RELA,		0 },
+  { ".rel",		4,	NULL,	0,
+    SHT_REL,	0 },
+  { ".stab",		5,	"str",	3,
+    SHT_STRTAB,		0 },
+  { NULL,		0,	NULL,	0,
+    0,		0 }
+};
+
+static const struct bfd_elf_special_section *
+get_special_section (const char *name,
+		     const struct bfd_elf_special_section *special_sections,
+		     unsigned int rela)
+{
+  int i;
+
+  for (i = 0; special_sections[i].prefix != NULL; i++)
+    if (((special_sections[i].prefix_length
+	  && strncmp (name, special_sections[i].prefix,
+		      special_sections[i].prefix_length) == 0
+	  && (! special_sections[i].suffix_length
+	      || strcmp ((name + strlen (name)
+			  - special_sections[i].suffix_length),
+			 special_sections[i].suffix) == 0))
+	 || strcmp (name, special_sections[i].prefix) == 0)
+	&& (rela || special_sections[i].type != SHT_RELA))
+      return &special_sections[i];
+
+  return NULL;
+}
+
+bfd_boolean
+_bfd_elf_get_sec_type_attr (bfd *abfd, const char *name,
+			    int *type, int *attr)
+{
+  bfd_boolean found = FALSE;
+  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+
+  /* See if this is one of the special sections.  */
+  if (name)
+    {
+      const struct bfd_elf_special_section *ssect = NULL;
+      unsigned int rela = get_elf_backend_data (abfd)->default_use_rela_p;
+
+      if (bed->special_sections)
+	ssect = get_special_section (name, bed->special_sections, rela);
+
+      if (! ssect)
+	ssect = get_special_section (name, special_sections, rela);
+
+      if (ssect)
+	{
+	  *type = ssect->type;
+	  *attr = ssect->attributes;
+	  found = TRUE;
+	}
+    }
+
+  return found;
+}
+
 bfd_boolean
 _bfd_elf_new_section_hook (abfd, sec)
      bfd *abfd;
      asection *sec;
 {
   struct bfd_elf_section_data *sdata;
+  int type, attr;
 
   sdata = (struct bfd_elf_section_data *) sec->used_by_bfd;
   if (sdata == NULL)
@@ -2156,6 +2293,19 @@ _bfd_elf_new_section_hook (abfd, sec)
       sec->used_by_bfd = (PTR) sdata;
     }
 
+  if ((sec->flags & SEC_ALLOC) != 0
+      && (((sec->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+	  || (sec->flags & SEC_NEVER_LOAD) != 0))
+    elf_section_type (sec) = SHT_NOBITS;
+  else
+    elf_section_type (sec) = SHT_PROGBITS;
+  if (sec->name && _bfd_elf_get_sec_type_attr (abfd, sec->name,
+					       &type, &attr))
+    {
+      elf_section_type (sec) = type;
+      elf_section_flags (sec) = attr;
+    }
+
   /* Indicate whether or not this section should use RELA relocations.  */
   sec->use_rela_p = get_elf_backend_data (abfd)->default_use_rela_p;
 
@@ -2394,55 +2544,52 @@ elf_fake_sections (abfd, asect, failedpt
   this_hdr->bfd_section = asect;
   this_hdr->contents = NULL;
 
-  /* FIXME: This should not be based on section names.  */
-  if (strcmp (asect->name, ".dynstr") == 0)
-    this_hdr->sh_type = SHT_STRTAB;
-  else if (strcmp (asect->name, ".hash") == 0)
+  switch (this_hdr->sh_type)
     {
-      this_hdr->sh_type = SHT_HASH;
+    default:
+      (*_bfd_error_handler)
+       (_("%s: Section `%s' has unknown type 0x%0x"),
+	bfd_get_filename (asect->owner), asect->name,
+	this_hdr->sh_type);
+      abort ();
+      break;
+
+    case SHT_STRTAB:
+    case SHT_INIT_ARRAY:
+    case SHT_FINI_ARRAY:
+    case SHT_PREINIT_ARRAY:
+    case SHT_NOTE:
+    case SHT_NOBITS:
+    case SHT_PROGBITS:
+      break;
+
+    case SHT_HASH:
       this_hdr->sh_entsize = bed->s->sizeof_hash_entry;
-    }
-  else if (strcmp (asect->name, ".dynsym") == 0)
-    {
-      this_hdr->sh_type = SHT_DYNSYM;
+      break;
+  
+    case SHT_DYNSYM:
       this_hdr->sh_entsize = bed->s->sizeof_sym;
-    }
-  else if (strcmp (asect->name, ".dynamic") == 0)
-    {
-      this_hdr->sh_type = SHT_DYNAMIC;
+      break;
+
+    case SHT_DYNAMIC:
       this_hdr->sh_entsize = bed->s->sizeof_dyn;
-    }
-  else if (strncmp (asect->name, ".rela", 5) == 0
-	   && get_elf_backend_data (abfd)->may_use_rela_p)
-    {
-      this_hdr->sh_type = SHT_RELA;
-      this_hdr->sh_entsize = bed->s->sizeof_rela;
-    }
-  else if (strncmp (asect->name, ".rel", 4) == 0
-	   && get_elf_backend_data (abfd)->may_use_rel_p)
-    {
-      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
-	   && strcmp (asect->name + strlen (asect->name) - 3, "str") == 0)
-    this_hdr->sh_type = SHT_STRTAB;
-  else if (strcmp (asect->name, ".gnu.version") == 0)
-    {
-      this_hdr->sh_type = SHT_GNU_versym;
+      break;
+
+    case SHT_RELA:
+      if (get_elf_backend_data (abfd)->may_use_rela_p)
+	this_hdr->sh_entsize = bed->s->sizeof_rela;
+      break;
+
+     case SHT_REL:
+      if (get_elf_backend_data (abfd)->may_use_rel_p)
+	this_hdr->sh_entsize = bed->s->sizeof_rel;
+      break;
+
+     case SHT_GNU_versym:
       this_hdr->sh_entsize = sizeof (Elf_External_Versym);
-    }
-  else if (strcmp (asect->name, ".gnu.version_d") == 0)
-    {
-      this_hdr->sh_type = SHT_GNU_verdef;
+      break;
+
+     case SHT_GNU_verdef:
       this_hdr->sh_entsize = 0;
       /* objcopy or strip will copy over sh_info, but may not set
          cverdefs.  The linker will set cverdefs, but sh_info will be
@@ -2452,10 +2599,9 @@ elf_fake_sections (abfd, asect, failedpt
       else
 	BFD_ASSERT (elf_tdata (abfd)->cverdefs == 0
 		    || this_hdr->sh_info == elf_tdata (abfd)->cverdefs);
-    }
-  else if (strcmp (asect->name, ".gnu.version_r") == 0)
-    {
-      this_hdr->sh_type = SHT_GNU_verneed;
+      break;
+
+    case SHT_GNU_verneed:
       this_hdr->sh_entsize = 0;
       /* objcopy or strip will copy over sh_info, but may not set
          cverrefs.  The linker will set cverrefs, but sh_info will be
@@ -2465,18 +2611,12 @@ elf_fake_sections (abfd, asect, failedpt
       else
 	BFD_ASSERT (elf_tdata (abfd)->cverrefs == 0
 		    || this_hdr->sh_info == elf_tdata (abfd)->cverrefs);
-    }
-  else if ((asect->flags & SEC_GROUP) != 0)
-    {
-      this_hdr->sh_type = SHT_GROUP;
+      break;
+
+    case SHT_GROUP:
       this_hdr->sh_entsize = 4;
+      break;
     }
-  else if ((asect->flags & SEC_ALLOC) != 0
-	   && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
-	       || (asect->flags & SEC_NEVER_LOAD) != 0))
-    this_hdr->sh_type = SHT_NOBITS;
-  else
-    this_hdr->sh_type = SHT_PROGBITS;
 
   if ((asect->flags & SEC_ALLOC) != 0)
     this_hdr->sh_flags |= SHF_ALLOC;
--- binutils/bfd/elf32-m32r.c.type	2003-06-26 07:34:48.000000000 -0700
+++ binutils/bfd/elf32-m32r.c	2003-07-24 10:24:53.000000000 -0700
@@ -2091,6 +2091,16 @@ m32r_elf_check_relocs (abfd, info, sec, 
 
   return TRUE;
 }
+
+static struct bfd_elf_special_section const m32r_elf_special_sections[]=
+{
+  { ".sdata",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".sbss",	0,	NULL,	0,
+    SHT_NOBITS,	SHF_ALLOC + SHF_WRITE },
+  { NULL,	0,	NULL,	0,
+    0,		0 }
+};
 \f
 #define ELF_ARCH		bfd_arch_m32r
 #define ELF_MACHINE_CODE	EM_M32R
@@ -2126,5 +2136,6 @@ m32r_elf_check_relocs (abfd, info, sec, 
 #define bfd_elf32_bfd_merge_private_bfd_data 	m32r_elf_merge_private_bfd_data
 #define bfd_elf32_bfd_set_private_flags		m32r_elf_set_private_flags
 #define bfd_elf32_bfd_print_private_bfd_data	m32r_elf_print_private_bfd_data
+#define elf_backend_special_sections		m32r_elf_special_sections
 
 #include "elf32-target.h"
--- binutils/bfd/elf32-m68hc11.c.type	2003-06-26 07:34:48.000000000 -0700
+++ binutils/bfd/elf32-m68hc11.c	2003-07-24 10:26:00.000000000 -0700
@@ -1281,6 +1281,25 @@ m68hc11_elf_relax_delete_bytes (abfd, se
     }
 }
 
+/* Specific sections:
+   - The .page0 is a data section that is mapped in [0x0000..0x00FF].
+     Page0 accesses are faster on the M68HC11. Soft registers used by GCC-m6811
+     are located in .page0.
+   - The .vectors is the data section that represents the interrupt
+     vectors.  */
+static struct bfd_elf_special_section const elf32_m68hc11_special_sections[]=
+{
+  { ".eeprom",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".softregs",	0,	NULL,	0,
+    SHT_NOBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".page0",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".vectors",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
 \f
 #define ELF_ARCH		bfd_arch_m68hc11
 #define ELF_MACHINE_CODE	EM_68HC11
@@ -1300,6 +1319,7 @@ m68hc11_elf_relax_delete_bytes (abfd, se
 #define elf_backend_object_p	0
 #define elf_backend_final_write_processing	0
 #define elf_backend_can_gc_sections		1
+#define elf_backend_special_sections elf32_m68hc11_special_sections
 
 #define bfd_elf32_bfd_link_hash_table_create \
                                 m68hc11_elf_bfd_link_hash_table_create
--- binutils/bfd/elf32-mcore.c.type	2003-06-26 07:34:48.000000000 -0700
+++ binutils/bfd/elf32-mcore.c	2003-07-24 10:26:52.000000000 -0700
@@ -681,6 +681,16 @@ mcore_elf_check_relocs (abfd, info, sec,
   return TRUE;
 }
 
+static struct bfd_elf_special_section const mcore_elf_special_sections[]=
+{
+  { ".ctors",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".dtors",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 #define TARGET_BIG_SYM		bfd_elf32_mcore_big_vec
 #define TARGET_BIG_NAME		"elf32-mcore-big"
 #define TARGET_LITTLE_SYM       bfd_elf32_mcore_little_vec
@@ -699,6 +709,7 @@ mcore_elf_check_relocs (abfd, info, sec,
 #define elf_backend_gc_mark_hook		mcore_elf_gc_mark_hook
 #define elf_backend_gc_sweep_hook		mcore_elf_gc_sweep_hook
 #define elf_backend_check_relocs                mcore_elf_check_relocs
+#define elf_backend_special_sections		mcore_elf_special_sections
 
 #define elf_backend_can_gc_sections		1
 #define elf_backend_rela_normal			1
--- binutils/bfd/elf32-ppc.c.type	2003-07-21 07:34:13.000000000 -0700
+++ binutils/bfd/elf32-ppc.c	2003-07-24 12:42:35.000000000 -0700
@@ -6020,6 +6020,35 @@ ppc_elf_final_write_processing (bfd *abf
 
   apuinfo_list_finish ();
 }
+
+/* Add extra PPC sections -- Note, for now, make .sbss2 and
+   .PPC.EMB.sbss0 a normal section, and not a bss section so
+   that the linker doesn't crater when trying to make more than
+   2 sections.  */
+
+static struct bfd_elf_special_section const ppc_elf_special_sections[]=
+{
+  { ".tags",		0,	NULL,	0,
+    SHT_ORDERED,	SHF_ALLOC },
+  { ".sdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".sbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE },
+  { ".sdata2",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".sbss2",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".PPC.EMB.apuinfo",	0,	NULL,	0,
+    SHT_NOTE,		0 },
+  { ".PPC.EMB.sdata0",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".PPC.EMB.sbss0",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".plt",		0,	NULL,	0,
+    SHT_NOBITS,		0 },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
 \f
 #define TARGET_LITTLE_SYM	bfd_elf32_powerpcle_vec
 #define TARGET_LITTLE_NAME	"elf32-powerpcle"
@@ -6079,5 +6108,6 @@ ppc_elf_final_write_processing (bfd *abf
 #define elf_backend_begin_write_processing	ppc_elf_begin_write_processing
 #define elf_backend_final_write_processing	ppc_elf_final_write_processing
 #define elf_backend_write_section		ppc_elf_write_section
+#define elf_backend_special_sections		ppc_elf_special_sections
 
 #include "elf32-target.h"
--- binutils/bfd/elf32-sh64.c.type	2003-06-26 07:34:48.000000000 -0700
+++ binutils/bfd/elf32-sh64.c	2003-07-24 10:29:21.000000000 -0700
@@ -87,6 +87,7 @@ static void sh64_find_section_for_addres
 	sh64_elf_link_output_symbol_hook
 #define elf_backend_final_write_processing 	sh64_elf_final_write_processing
 #define elf_backend_section_from_shdr		sh64_backend_section_from_shdr
+#define elf_backend_special_sections		sh64_elf_special_sections
 
 #define bfd_elf32_new_section_hook		sh64_elf_new_section_hook
 
@@ -764,6 +765,14 @@ sh64_elf_final_write_processing (abfd, l
     }
 }
 
+static struct bfd_elf_special_section const sh64_elf_special_sections[]=
+{
+  { ".cranges",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 #undef	TARGET_BIG_SYM
 #define	TARGET_BIG_SYM		bfd_elf32_sh64_vec
 #undef	TARGET_BIG_NAME
--- binutils/bfd/elf32-v850.c.type	2003-06-26 07:34:48.000000000 -0700
+++ binutils/bfd/elf32-v850.c	2003-07-24 10:32:37.000000000 -0700
@@ -3139,6 +3139,38 @@ v850_elf_relax_section (abfd, sec, link_
   result = FALSE;
   goto finish;
 }
+
+static struct bfd_elf_special_section const v850_elf_special_sections[]=
+{
+  { ".sdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_V850_GPREL },
+  { ".rosdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_V850_GPREL },
+  { ".sbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_GPREL },
+  { ".scommon",		0,	NULL,	0,
+    SHT_V850_SCOMMON, 	SHF_ALLOC + SHF_WRITE + SHF_V850_GPREL },
+  { ".tdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_V850_EPREL },
+  { ".tbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_EPREL },
+  { ".tcommon",		0,	NULL,	0,
+    SHT_V850_TCOMMON,	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL },
+  { ".zdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL },
+  { ".rozdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_V850_R0REL },
+  { ".zbss",		0,	NULL,	0,
+    SHT_NOBITS,	  	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL },
+  { ".zcommon",		0,	NULL,	0,
+    SHT_V850_ZCOMMON, 	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL },
+  { ".call_table_data",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".call_table_text",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_EXECINSTR },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
 \f
 #define TARGET_LITTLE_SYM			bfd_elf32_v850_vec
 #define TARGET_LITTLE_NAME			"elf32-v850"
@@ -3162,6 +3194,7 @@ v850_elf_relax_section (abfd, sec, link_
 #define elf_backend_fake_sections		v850_elf_fake_sections
 #define elf_backend_gc_mark_hook                v850_elf_gc_mark_hook
 #define elf_backend_gc_sweep_hook               v850_elf_gc_sweep_hook
+#define elf_backend_special_sections		v850_elf_special_sections
 
 #define elf_backend_can_gc_sections 1
 #define elf_backend_rela_normal 1
--- binutils/bfd/elf32-xtensa.c.type	2003-07-18 21:25:28.000000000 -0700
+++ binutils/bfd/elf32-xtensa.c	2003-07-24 10:33:26.000000000 -0700
@@ -5843,6 +5843,21 @@ xtensa_callback_required_dependence (abf
   return ok;
 }
 
+/* The default literal sections should always be marked as "code" (i.e.,
+   SHF_EXECINSTR).  This is particularly important for the Linux kernel
+   module loader so that the literals are not placed after the text.  */
+static struct bfd_elf_special_section const elf_xtensa_special_sections[]=
+{
+  { ".literal",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
+  { ".init.literal",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
+  { ".fini.literal",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 \f
 #ifndef ELF_ARCH
 #define TARGET_LITTLE_SYM		bfd_elf32_xtensa_le_vec
@@ -5903,5 +5918,6 @@ xtensa_callback_required_dependence (abf
 #define elf_backend_reloc_type_class	     elf_xtensa_reloc_type_class
 #define elf_backend_relocate_section	     elf_xtensa_relocate_section
 #define elf_backend_size_dynamic_sections    elf_xtensa_size_dynamic_sections
+#define elf_backend_special_sections	     elf_xtensa_special_sections
 
 #include "elf32-target.h"
--- binutils/bfd/elf64-alpha.c.type	2003-07-18 21:25:28.000000000 -0700
+++ binutils/bfd/elf64-alpha.c	2003-07-24 10:34:23.000000000 -0700
@@ -5465,6 +5465,16 @@ elf64_alpha_reloc_type_class (rela)
     }
 }
 \f
+static struct bfd_elf_special_section const elf64_alpha_special_sections[]=
+{
+  { ".sdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
+  { ".sbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 /* ECOFF swapping routines.  These are used when dealing with the
    .mdebug section, which is in the ECOFF debugging format.  Copied
    from elf32-mips.c.  */
@@ -5603,6 +5613,9 @@ static const struct elf_size_info alpha_
 #define elf_backend_size_info \
   alpha_elf_size_info
 
+#define elf_backend_special_sections \
+  elf64_alpha_special_sections
+
 /* A few constants that determine how the .plt section is set up.  */
 #define elf_backend_want_got_plt 0
 #define elf_backend_plt_readonly 0
--- binutils/bfd/elf64-hppa.c.type	2003-07-18 21:25:28.000000000 -0700
+++ binutils/bfd/elf64-hppa.c	2003-07-24 10:34:59.000000000 -0700
@@ -2667,6 +2667,16 @@ elf64_hppa_elf_get_symbol_type (elf_sym,
     return type;
 }
 
+static struct bfd_elf_special_section const elf64_hppa_special_sections[]=
+{
+  { ".fini",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".init",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 /* The hash bucket size is the standard one, namely 4.  */
 
 const struct elf_size_info hppa64_elf_size_info =
@@ -2764,6 +2774,7 @@ const struct elf_size_info hppa64_elf_si
 #define elf_backend_get_symbol_type	elf64_hppa_elf_get_symbol_type
 #define elf_backend_reloc_type_class	elf64_hppa_reloc_type_class
 #define elf_backend_rela_normal		1
+#define elf_backend_special_sections	elf64_hppa_special_sections
 
 #include "elf64-target.h"
 
@@ -2772,5 +2783,7 @@ const struct elf_size_info hppa64_elf_si
 #undef TARGET_BIG_NAME
 #define TARGET_BIG_NAME			"elf64-hppa-linux"
 
+#undef elf_backend_special_sections
+
 #define INCLUDED_TARGET_FILE 1
 #include "elf64-target.h"
--- binutils/bfd/elf64-ppc.c.type	2003-07-21 07:34:13.000000000 -0700
+++ binutils/bfd/elf64-ppc.c	2003-07-24 12:42:51.000000000 -0700
@@ -28,6 +28,7 @@
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "elf/ppc.h"
 #include "elf/ppc64.h"
 #include "elf64-ppc.h"
 
@@ -90,6 +91,7 @@ static bfd_reloc_status_type ppc64_elf_u
 #define elf_backend_finish_dynamic_symbol     ppc64_elf_finish_dynamic_symbol
 #define elf_backend_reloc_type_class	      ppc64_elf_reloc_type_class
 #define elf_backend_finish_dynamic_sections   ppc64_elf_finish_dynamic_sections
+#define elf_backend_special_sections	      ppc64_elf_special_sections
 
 /* The name of the dynamic interpreter.  This is put in the .interp
    section.  */
@@ -8760,4 +8762,37 @@ ppc64_elf_finish_dynamic_sections (bfd *
   return TRUE;
 }
 
+/* Add extra PPC sections -- Note, for now, make .sbss2 and
+   .PPC.EMB.sbss0 a normal section, and not a bss section so
+   that the linker doesn't crater when trying to make more than
+   2 sections.  */
+
+static struct bfd_elf_special_section const ppc64_elf_special_sections[]=
+{
+  { ".tags",		0,	NULL,	0,
+    SHT_ORDERED,	SHF_ALLOC },
+  { ".sdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".sbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE },
+  { ".sdata2",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".sbss2",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".PPC.EMB.apuinfo",	0,	NULL,	0,
+    SHT_NOTE,		0 },
+  { ".PPC.EMB.sdata0",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".PPC.EMB.sbss0",	0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC },
+  { ".plt",		0,	NULL,	0,
+    SHT_NOBITS,		0 },
+  { ".toc",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },
+  { ".tocbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 #include "elf64-target.h"
--- binutils/bfd/elf64-sh64.c.type	2003-06-26 07:34:49.000000000 -0700
+++ binutils/bfd/elf64-sh64.c	2003-07-24 10:38:54.000000000 -0700
@@ -4172,6 +4172,14 @@ sh64_elf64_finish_dynamic_sections (outp
   return TRUE;
 }
 
+static struct bfd_elf_special_section const sh64_elf64_special_sections[]=
+{
+  { ".cranges",		0,	NULL,	0,
+    SHT_PROGBITS,	0 },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 #define TARGET_BIG_SYM		bfd_elf64_sh64_vec
 #define TARGET_BIG_NAME		"elf64-sh64"
 #define TARGET_LITTLE_SYM	bfd_elf64_sh64l_vec
@@ -4227,6 +4235,7 @@ sh64_elf64_finish_dynamic_sections (outp
 					sh64_elf64_finish_dynamic_symbol
 #define elf_backend_finish_dynamic_sections \
 					sh64_elf64_finish_dynamic_sections
+#define elf_backend_special_sections	sh64_elf64_special_sections
 
 #define elf_backend_want_got_plt	1
 #define elf_backend_plt_readonly	1
--- binutils/bfd/elfxx-ia64.c.type	2003-07-22 09:09:11.000000000 -0700
+++ binutils/bfd/elfxx-ia64.c	2003-07-24 10:39:38.000000000 -0700
@@ -4773,6 +4773,16 @@ elfNN_ia64_reloc_type_class (rela)
     }
 }
 
+static struct bfd_elf_special_section const elfNN_ia64_special_sections[]=
+{
+  { ".sbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
+  { ".sdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
+
 static bfd_boolean
 elfNN_ia64_hpux_vec (const bfd_target *vec)
 {
@@ -4880,6 +4890,7 @@ elfNN_hpux_backend_section_from_bfd_sect
 #define elf_backend_hide_symbol		elfNN_ia64_hash_hide_symbol
 #define elf_backend_reloc_type_class	elfNN_ia64_reloc_type_class
 #define elf_backend_rela_normal		1
+#define elf_backend_special_sections	elfNN_ia64_special_sections
 
 #include "elfNN-target.h"
 
--- binutils/bfd/elfxx-mips.c.type	2003-07-16 09:08:55.000000000 -0700
+++ binutils/bfd/elfxx-mips.c	2003-07-24 10:41:12.000000000 -0700
@@ -9290,3 +9290,21 @@ _bfd_mips_elf_print_private_bfd_data (ab
 
   return TRUE;
 }
+
+struct bfd_elf_special_section const _bfd_mips_elf_special_sections[]=
+{
+  { ".sdata",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL },
+  { ".sbss",		0,	NULL,	0,
+    SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL },
+  { ".lit4",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL },
+  { ".lit8",		0,	NULL,	0,
+    SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL },
+  { ".ucode",		0,	NULL,	0,
+    SHT_MIPS_UCODE,	0 },
+  { ".mdebug",		0,	NULL,	0,
+    SHT_MIPS_DEBUG,	0 },
+  { NULL,		0,	NULL,	0,
+    0,			0 }
+};
--- binutils/bfd/elfxx-mips.h.type	2003-06-12 07:12:52.000000000 -0700
+++ binutils/bfd/elfxx-mips.h	2003-07-24 08:41:54.000000000 -0700
@@ -112,3 +112,6 @@ extern bfd_boolean _bfd_mips_relax_secti
   PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
 extern bfd_vma _bfd_mips_elf_sign_extend
   PARAMS ((bfd_vma, int));
+
+extern struct bfd_elf_special_section const _bfd_mips_elf_special_sections[];
+#define elf_backend_special_sections _bfd_mips_elf_special_sections
--- binutils/bfd/elfxx-target.h.type	2003-07-23 14:58:02.000000000 -0700
+++ binutils/bfd/elfxx-target.h	2003-07-23 14:55:12.000000000 -0700
@@ -434,6 +434,10 @@
 #define elf_backend_size_info _bfd_elfNN_size_info
 #endif
 
+#ifndef elf_backend_special_sections
+#define elf_backend_special_sections NULL
+#endif
+
 #ifndef elf_backend_sign_extend_vma
 #define elf_backend_sign_extend_vma 0
 #endif
@@ -497,6 +501,7 @@ static const struct elf_backend_data elf
   ELF_MACHINE_ALT1,
   ELF_MACHINE_ALT2,
   &elf_backend_size_info,
+  elf_backend_special_sections,
   elf_backend_got_symbol_offset,
   elf_backend_got_header_size,
   elf_backend_plt_header_size,
--- binutils/bfd/section.c.type	2003-07-08 07:22:49.000000000 -0700
+++ binutils/bfd/section.c	2003-07-23 14:38:43.000000000 -0700
@@ -532,18 +532,18 @@ CODE_FRAGMENT
 .#define BFD_IND_SECTION_NAME "*IND*"
 .
 .{* The absolute section.  *}
-.extern const asection bfd_abs_section;
+.extern asection bfd_abs_section;
 .#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
 .#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
 .{* Pointer to the undefined section.  *}
-.extern const asection bfd_und_section;
+.extern asection bfd_und_section;
 .#define bfd_und_section_ptr ((asection *) &bfd_und_section)
 .#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
 .{* Pointer to the common section.  *}
-.extern const asection bfd_com_section;
+.extern asection bfd_com_section;
 .#define bfd_com_section_ptr ((asection *) &bfd_com_section)
 .{* Pointer to the indirect section.  *}
-.extern const asection bfd_ind_section;
+.extern asection bfd_ind_section;
 .#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
 .#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
 .
@@ -616,7 +616,7 @@ static const asymbol global_syms[] =
 
 #define STD_SECTION(SEC, FLAGS, SYM, NAME, IDX)				\
   const asymbol * const SYM = (asymbol *) &global_syms[IDX]; 		\
-  const asection SEC = 							\
+  asection SEC = 							\
     /* name, id,  index, next, flags, user_set_vma, reloc_done,      */	\
     { NAME,  IDX, 0,     NULL, FLAGS, 0,            0,			\
 									\
--- binutils/gas/config/obj-elf.c.type	2003-07-23 09:57:48.000000000 -0700
+++ binutils/gas/config/obj-elf.c	2003-07-24 09:29:33.000000000 -0700
@@ -601,63 +601,6 @@ static struct section_stack *section_sta
    other possibilities, but I don't know what they are.  In any case,
    BFD doesn't really let us set the section type.  */
 
-/* Certain named sections have particular defined types, listed on p.
-   4-19 of the ABI.  */
-struct special_section
-{
-  const char *name;
-  int type;
-  int attributes;
-};
-
-static struct special_section const special_sections[] =
-{
-  { ".bss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE		},
-  { ".comment",	SHT_PROGBITS,	0				},
-  { ".data",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE		},
-  { ".data1",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE		},
-  { ".debug",	SHT_PROGBITS,	0				},
-#if defined (TC_HPPA) && !defined (TE_LINUX) && TARGET_ARCH_SIZE == 64
-  { ".fini",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE		},
-  { ".init",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE		},
-#else
-  { ".fini",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR	},
-  { ".init",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR	},
-#endif
-  { ".line",	SHT_PROGBITS,	0				},
-  { ".note",	SHT_NOTE,	0				},
-  { ".rodata",	SHT_PROGBITS,	SHF_ALLOC			},
-  { ".rodata1",	SHT_PROGBITS,	SHF_ALLOC			},
-  { ".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	},
-  { ".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
-#endif
-
-#if 0
-  /* The following section names are special, but they can not
-     reasonably appear in assembler code.  Some of the attributes are
-     processor dependent.  */
-  { ".dynamic",	SHT_DYNAMIC,	SHF_ALLOC /* + SHF_WRITE */ 	},
-  { ".dynstr",	SHT_STRTAB,	SHF_ALLOC			},
-  { ".dynsym",	SHT_DYNSYM,	SHF_ALLOC			},
-  { ".got",	SHT_PROGBITS,	0				},
-  { ".hash",	SHT_HASH,	SHF_ALLOC			},
-  { ".interp",	SHT_PROGBITS,	/* SHF_ALLOC */			},
-  { ".plt",	SHT_PROGBITS,	0				},
-  { ".shstrtab",SHT_STRTAB,	0				},
-  { ".strtab",	SHT_STRTAB,	/* SHF_ALLOC */			},
-  { ".symtab",	SHT_SYMTAB,	/* SHF_ALLOC */			},
-#endif
-
-  { NULL,	0,		0				}
-};
-
 void
 obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push)
      const char *name;
@@ -671,7 +614,8 @@ obj_elf_change_section (name, type, attr
   asection *old_sec;
   segT sec;
   flagword flags;
-  int i;
+  int def_type;
+  int def_attr;
 
 #ifdef md_flush_pending_output
   md_flush_pending_output ();
@@ -695,48 +639,52 @@ obj_elf_change_section (name, type, attr
   old_sec = bfd_get_section_by_name (stdoutput, name);
   sec = subseg_new (name, 0);
 
-  /* See if this is one of the special sections.  */
-  for (i = 0; special_sections[i].name != NULL; i++)
-    if (strcmp (name, special_sections[i].name) == 0)
-      {
-	if (type == SHT_NULL)
-	  type = special_sections[i].type;
-	else if (type != special_sections[i].type)
-	  {
-	    if (old_sec == NULL
-		/* FIXME: gcc, as of 2002-10-22, will emit
+  if (_bfd_elf_get_sec_type_attr (stdoutput, name, &def_type,
+				  &def_attr))
+    {
+      if (type == SHT_NULL)
+	type = def_type;
+      else if (type != def_type)
+	{
+	  if (old_sec == NULL
+	      /* FIXME: gcc, as of 2002-10-22, will emit
 
-		   .section .init_array,"aw",@progbits
+		 .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);
-	      }
-	    else
-	      {
-		as_warn (_("ignoring incorrect section type for %s"), name);
-		type = special_sections[i].type;
-	      }
-	  }
-	if ((attr &~ special_sections[i].attributes) != 0
-	    && old_sec == NULL)
-	  {
-	    /* As a GNU extension, we permit a .note section to be
-	       allocatable.  If the linker sees an allocateable .note
-	       section, it will create a PT_NOTE segment in the output
-	       file.  */
-	    if (strcmp (name, ".note") != 0
-		|| attr != SHF_ALLOC)
-	      as_warn (_("setting incorrect section attributes for %s"),
+		 for __attribute__ ((section (".init_array"))).
+		 "@progbits" is incorrect.  */
+	      && def_type != SHT_INIT_ARRAY
+	      && def_type != SHT_FINI_ARRAY
+	      && def_type != SHT_PREINIT_ARRAY)
+	    {
+	      /* We allow to specify any type for a .note section.  */
+	      if (def_type != SHT_NOTE)
+		as_warn (_("setting incorrect section type for %s"),
+			 name);
+	    }
+	  else
+	    {
+	      as_warn (_("ignoring incorrect section type for %s"),
 		       name);
-	  }
-	attr |= special_sections[i].attributes;
-	break;
-      }
+	      type = def_type;
+	    }
+	}
+
+      if (old_sec == NULL && (attr &~ def_attr) != 0)
+	{
+	  /* As a GNU extension, we permit a .note section to be
+	     allocatable.  If the linker sees an allocateable .note
+	     section, it will create a PT_NOTE segment in the output
+	     file.  */
+	  if (strcmp (name, ".note") != 0 || attr != SHF_ALLOC)
+	    as_warn (_("setting incorrect section attributes for %s"),
+		     name);
+	}
+      attr |= def_attr;
+
+      elf_section_type (sec) = type;
+      elf_section_flags (sec) = attr;
+    }
 
   /* Convert ELF type and flags to BFD flags.  */
   flags = (SEC_RELOC
@@ -2078,6 +2026,7 @@ elf_frob_file ()
 	  as_fatal (_("can't create group: %s"),
 		    bfd_errmsg (bfd_get_error ()));
 	}
+      elf_section_type (s) = SHT_GROUP;
 
       /* Pass a pointer to the first section in this group.  */
       elf_next_in_group (s) = list.head[i];
--- binutils/gas/config/obj-elf.h.type	2002-09-18 22:11:17.000000000 -0700
+++ binutils/gas/config/obj-elf.h	2003-07-24 07:08:21.000000000 -0700
@@ -134,6 +134,13 @@ int elf_s_get_other PARAMS ((symbolS *))
 
 extern asection *gdb_section;
 
+#ifndef obj_sec_set_private_data
+#define obj_sec_set_private_data(B, S) \
+  if (!_bfd_elf_new_section_hook ((B), (S)))			\
+    as_fatal (_("can't allocate ELF private section data: %s"),	\
+	      bfd_errmsg (bfd_get_error ()))
+#endif
+
 #ifndef obj_frob_file
 #define obj_frob_file  elf_frob_file
 #endif
--- binutils/gas/config/tc-alpha.h.type	2003-07-24 08:21:09.000000000 -0700
+++ binutils/gas/config/tc-alpha.h	2003-07-24 08:22:21.000000000 -0700
@@ -104,10 +104,6 @@ extern void alpha_frob_file_before_adjus
 #define DIFF_EXPR_OK   /* foo-. gets turned into PC relative relocs */
 
 #ifdef OBJ_ELF
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".sdata",   SHT_PROGBITS,   SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL  }, \
-  { ".sbss",    SHT_NOBITS,     SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL  },
-
 #define md_elf_section_letter		alpha_elf_section_letter
 extern int alpha_elf_section_letter PARAMS ((int, char **));
 #define md_elf_section_flags		alpha_elf_section_flags
--- binutils/gas/config/tc-ia64.h.type	2003-05-07 22:18:16.000000000 -0700
+++ binutils/gas/config/tc-ia64.h	2003-07-24 08:21:15.000000000 -0700
@@ -151,10 +151,6 @@ extern void ia64_check_label PARAMS ((sy
 
 #define WORKING_DOT_WORD	/* don't do broken word processing for now */
 
-#define ELF_TC_SPECIAL_SECTIONS						   \
-{ ".sbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, \
-{ ".sdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT },
-
 #define DWARF2_LINE_MIN_INSN_LENGTH 1	/* so slot-multipliers can be 1 */
 
 /* This is the information required for unwind records in an ia64
--- binutils/gas/config/tc-m32r.h.type	2002-12-16 09:31:40.000000000 -0800
+++ binutils/gas/config/tc-m32r.h	2003-07-24 08:21:22.000000000 -0700
@@ -98,11 +98,6 @@ int m32r_fill_insn PARAMS ((int));
 #define md_after_pass_hook()	m32r_fill_insn (1)
 #define TC_START_LABEL(ch, ptr)	(ch == ':' && m32r_fill_insn (0))
 
-/* Add extra M32R sections.  */
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".sdata",		SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE }, \
-  { ".sbss",		SHT_NOBITS,	SHF_ALLOC + SHF_WRITE },
-
 #define md_cleanup                 m32r_elf_section_change_hook
 #define md_elf_section_change_hook m32r_elf_section_change_hook
 extern void m32r_elf_section_change_hook PARAMS ((void));
--- binutils/gas/config/tc-m68hc11.h.type	2002-12-04 09:03:42.000000000 -0800
+++ binutils/gas/config/tc-m68hc11.h	2003-07-24 08:22:29.000000000 -0700
@@ -53,18 +53,6 @@ extern int m68hc11_mach PARAMS ((void));
 #define TARGET_FORMAT (m68hc11_arch_format ())
 extern const char *m68hc11_arch_format PARAMS ((void));
 
-/* Specific sections:
-   - The .page0 is a data section that is mapped in [0x0000..0x00FF].
-     Page0 accesses are faster on the M68HC11. Soft registers used by GCC-m6811
-     are located in .page0.
-   - The .vectors is the data section that represents the interrupt
-     vectors.  */
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".eeprom",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE	}, \
-  { ".softregs",SHT_NOBITS,	SHF_ALLOC + SHF_WRITE	}, \
-  { ".page0",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE	}, \
-  { ".vectors",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE	},
-
 #define LISTING_WORD_SIZE 1	/* A word is 1 bytes */
 #define LISTING_LHS_WIDTH 4	/* One word on the first line */
 #define LISTING_LHS_WIDTH_SECOND 4	/* One word on the second line */
--- binutils/gas/config/tc-mcore.h.type	2003-01-23 09:20:48.000000000 -0800
+++ binutils/gas/config/tc-mcore.h	2003-07-24 08:23:08.000000000 -0700
@@ -83,12 +83,6 @@ struct mcore_tc_sy
 
 #define TARGET_FORMAT (target_big_endian ? "elf32-mcore-big" : "elf32-mcore-little")
 
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".ctors",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE }, \
-  { ".dtors",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE }, \
-/* Other special sections not generated by the assembler: .reginfo,
-   .liblist, .conflict, .gptab, .got, .dynamic, .rel.dyn.  */
-
 /* No shared lib support, so we don't need to ensure externally
    visible symbols can be overridden.  */
 #define EXTERN_FORCE_RELOC 0
--- binutils/gas/config/tc-mips.h.type	2003-06-30 08:05:25.000000000 -0700
+++ binutils/gas/config/tc-mips.h	2003-07-24 08:23:17.000000000 -0700
@@ -162,16 +162,6 @@ extern unsigned long mips_cprmask[4];
 #define elf_tc_final_processing mips_elf_final_processing
 extern void mips_elf_final_processing (void);
 
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".sdata",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL	}, \
-  { ".sbss",	SHT_NOBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL	}, \
-  { ".lit4",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL	}, \
-  { ".lit8",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_MIPS_GPREL	}, \
-  { ".ucode",	SHT_MIPS_UCODE,	0					}, \
-  { ".mdebug",	SHT_MIPS_DEBUG,	0					},
-/* Other special sections not generated by the assembler: .reginfo,
-   .liblist, .conflict, .gptab, .got, .dynamic, .rel.dyn.  */
-
 #endif
 
 extern void md_mips_end (void);
--- binutils/gas/config/tc-ppc.h.type	2003-07-14 12:49:14.000000000 -0700
+++ binutils/gas/config/tc-ppc.h	2003-07-24 08:24:51.000000000 -0700
@@ -222,22 +222,6 @@ extern int ppc_section_flags PARAMS ((in
 #define md_elf_section_word(STR, LEN)		ppc_section_word (STR, LEN)
 #define md_elf_section_flags(FLAGS, ATTR, TYPE)	ppc_section_flags (FLAGS, ATTR, TYPE)
 
-/* Add extra PPC sections -- Note, for now, make .sbss2 and .PPC.EMB.sbss0 a
-   normal section, and not a bss section so that the linker doesn't crater
-   when trying to make more than 2 sections.  */
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".tags",		SHT_ORDERED,	SHF_ALLOC },			\
-  { ".sdata",		SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },	\
-  { ".sbss",		SHT_NOBITS,	SHF_ALLOC + SHF_WRITE },	\
-  { ".sdata2",		SHT_PROGBITS,	SHF_ALLOC },			\
-  { ".sbss2",		SHT_PROGBITS,	SHF_ALLOC },			\
-  { ".PPC.EMB.apuinfo",       SHT_NOTE,       0 }, \
-  { ".PPC.EMB.sdata0",	SHT_PROGBITS,	SHF_ALLOC },			\
-  { ".PPC.EMB.sbss0",	SHT_PROGBITS,	SHF_ALLOC },			\
-  /* Extra sections for 64-bit ELF PPC.  */				\
-  { ".toc",		SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE},		\
-  { ".tocbss",		SHT_NOBITS,	SHF_ALLOC + SHF_WRITE},
-
 #define tc_comment_chars ppc_comment_chars
 extern const char *ppc_comment_chars;
 
--- binutils/gas/config/tc-sh64.h.type	2003-04-24 14:19:07.000000000 -0700
+++ binutils/gas/config/tc-sh64.h	2003-07-24 08:24:55.000000000 -0700
@@ -174,9 +174,6 @@ extern void sh64_flush_pending_output PA
 #define tc_frob_section(sec) shmedia_frob_section_type (sec)
 extern void shmedia_frob_section_type PARAMS ((asection *));
 
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".cranges",	SHT_PROGBITS,	0 },
-
 /* We need to emit fixups relative to the frag in which the instruction
    resides.  Safest way without calculating max fragment growth or making
    it a fixed number is to provide a pointer to the opcode frag.
--- binutils/gas/config/tc-v850.h.type	2002-12-04 09:03:45.000000000 -0800
+++ binutils/gas/config/tc-v850.h	2003-07-24 08:48:46.000000000 -0700
@@ -74,28 +74,6 @@ extern const struct relax_type md_relax_
 #define HANDLE_ALIGN(frag) v850_handle_align (frag)
 extern void v850_handle_align PARAMS ((fragS *));
 
-/* This section must be in the small data area (pointed to by GP).  */
-#define SHF_V850_GPREL		0x10000000
-/* This section must be in the tiny data area (pointed to by EP).  */
-#define SHF_V850_EPREL		0x20000000
-/* This section must be in the zero data area (pointed to by R0).  */
-#define SHF_V850_R0REL		0x40000000
-
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".sdata",	SHT_PROGBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_GPREL	}, \
-  { ".rosdata",	SHT_PROGBITS,		SHF_ALLOC +             SHF_V850_GPREL	}, \
-  { ".sbss",	SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_GPREL	}, \
-  { ".scommon",	SHT_V850_SCOMMON, 	SHF_ALLOC + SHF_WRITE + SHF_V850_GPREL	}, \
-  { ".tdata",	SHT_PROGBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_EPREL	}, \
-  { ".tbss",	SHT_NOBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_EPREL	}, \
-  { ".tcommon",	SHT_V850_TCOMMON,	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL	}, \
-  { ".zdata",	SHT_PROGBITS,		SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL	}, \
-  { ".rozdata",	SHT_PROGBITS,		SHF_ALLOC +             SHF_V850_R0REL	}, \
-  { ".zbss",	SHT_NOBITS,	  	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL	}, \
-  { ".zcommon",	SHT_V850_ZCOMMON, 	SHF_ALLOC + SHF_WRITE + SHF_V850_R0REL	}, \
-  { ".call_table_data",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE },	   \
-  { ".call_table_text",	SHT_PROGBITS,	SHF_ALLOC + SHF_WRITE + SHF_EXECINSTR },
-
 #define MD_PCREL_FROM_SECTION(FIX, SEC) v850_pcrel_from_section (FIX, SEC)
 extern long v850_pcrel_from_section PARAMS ((struct fix *, asection *));
 
--- binutils/gas/config/tc-xtensa.h.type	2003-04-01 12:47:16.000000000 -0800
+++ binutils/gas/config/tc-xtensa.h	2003-07-24 08:25:36.000000000 -0700
@@ -189,12 +189,4 @@ extern long xtensa_relax_frag
 
 #define MD_APPLY_SYM_VALUE(FIX) 0
 
-/* The default literal sections should always be marked as "code" (i.e.,
-   SHF_EXECINSTR).  This is particularly important for the Linux kernel
-   module loader so that the literals are not placed after the text.  */
-#define ELF_TC_SPECIAL_SECTIONS \
-  { ".literal",		SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR }, \
-  { ".init.literal",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR }, \
-  { ".fini.literal",	SHT_PROGBITS,	SHF_ALLOC + SHF_EXECINSTR },
-
 #endif /* TC_XTENSA */
--- binutils/gas/subsegs.c.type	2002-12-08 13:41:58.000000000 -0800
+++ binutils/gas/subsegs.c	2003-07-23 14:38:43.000000000 -0700
@@ -422,6 +422,10 @@ subseg_get (segname, force_new)
   else
     secptr = bfd_make_section_anyway (stdoutput, segname);
 
+#ifdef obj_sec_set_private_data
+  obj_sec_set_private_data (stdoutput, secptr);
+#endif
+
   seginfo = seg_info (secptr);
   if (! seginfo)
     {
--- binutils/include/elf/v850.h.type	2003-06-04 07:31:07.000000000 -0700
+++ binutils/include/elf/v850.h	2003-07-24 08:48:37.000000000 -0700
@@ -104,4 +104,15 @@ END_RELOC_NUMBERS (R_V850_max)
 /* Section contains the .scommon data.  */
 #define SHT_V850_ZCOMMON	0x70000002
 
+/* Processor specific section flags.  */
+
+/* This section must be in the small data area (pointed to by GP).  */
+#define SHF_V850_GPREL		0x10000000
+
+/* This section must be in the tiny data area (pointed to by EP).  */
+#define SHF_V850_EPREL		0x20000000
+
+/* This section must be in the zero data area (pointed to by R0).  */
+#define SHF_V850_R0REL		0x40000000
+
 #endif /* _ELF_V850_H */

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25  1:36   ` PATCH: " H. J. Lu
@ 2003-07-25  4:48     ` Alan Modra
  2003-07-25 14:39       ` H. J. Lu
  2003-07-25 12:29     ` Nick Clifton
  1 sibling, 1 reply; 11+ messages in thread
From: Alan Modra @ 2003-07-25  4:48 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Nick Clifton, binutils

On Thu, Jul 24, 2003 at 06:36:03PM -0700, H. J. Lu wrote:
> 	* config/obj-elf.h (obj_sec_set_private_data): New.
> 
> 	* subsegs.c (subseg_get): Call obj_sec_set_private_data if it
> 	is defined.

This is presumably to tack bfd_elf_section_data onto the standard abs,
com, und and ind sections.  Howver, some targets allocate a larger
structure.  You should be going via bfd_target._new_section_hook.  ie.
BFD_SEND (stdoutput, _new_section_hook, (stdoutput, secptr))
This will also fix a possible problem with multi-obj gas support, where
obj-elf.h is included but you might be producing COFF output.

Also, I think the initialization should be done elsewhere, probably
gas/output-file.c:output_file_create.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25  1:36   ` PATCH: " H. J. Lu
  2003-07-25  4:48     ` Alan Modra
@ 2003-07-25 12:29     ` Nick Clifton
  2003-07-25 14:38       ` H. J. Lu
  1 sibling, 1 reply; 11+ messages in thread
From: Nick Clifton @ 2003-07-25 12:29 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

Hi H.J.

> Here is the new patch. It caused no regressions on all targets
> affected. It fixed an ELF/ppc64 bug.

Excellent.

> bfd/
>
> 2003-07-24  H.J. Lu  <hongjiu.lu@intel.com>
>
> 	* elf-bfd.h (bfd_elf_special_section): New.
> 	(elf_backend_data): Add special_sections, a pointer to
> 	bfd_elf_special_section.
> 	(elf_section_type). New.
> 	(elf_section_flags): New.
> 	(_bfd_elf_get_sec_type_attr): New.
>
> 	* elf.c (_bfd_elf_make_section_from_shdr): Always use the
> 	real section type/flags.
> 	(special_sections): New.
> 	(get_special_section): New.
> 	(_bfd_elf_get_sec_type_attr): New.
> 	(_bfd_elf_new_section_hook): Check special_section to set
> 	elf_section_type and elf_section_flags.
> 	(elf_fake_sections): Don't use section name to set ELF section
> 	data.
>
> 	* elf32-m32r.c (m32r_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf32-m68hc11.c (elf32_m68hc11_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf32-mcore.c (mcore_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf32-ppc.c (ppc_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf32-sh64.c (sh64_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf32-v850.c (v850_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf32-xtensa.c (elf_xtensa_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf64-alpha.c (elf64_alpha_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf64-hppa.c (elf64_hppa_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf64-ppc.c (ppc64_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elf64-sh64.c (sh64_elf64_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elfxx-ia64.c (elfNN_ia64_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elfxx-mips.c (_bfd_mips_elf_special_sections): New.
>
> 	* elfxx-mips.h (_bfd_mips_elf_special_sections): New.
> 	(elf_backend_special_sections): Defined.
>
> 	* elfxx-target.h (elf_backend_special_sections): New. Default
> 	to NULL.
> 	(elfNN_bed): Initialize special_sections.
>
> 	* section.c (bfd_abs_section): Remove const.
> 	(bfd_und_section): Likewise.
> 	(bfd_com_section): Likewise.
> 	(bfd_ind_section): Likewise.
>
> gas/
>
> 2003-07-24  H.J. Lu  <hongjiu.lu@intel.com>
>
> 	* config/obj-elf.c (special_sections): Removed.
> 	(obj_elf_change_section): Call _bfd_elf_get_sec_type_attr. Set
> 	elf_section_type and elf_section_flags.
> 	(elf_frob_file): Set SHT_GROUP.
>
> 	* config/obj-elf.h (obj_sec_set_private_data): New.
>
> 	* config/tc-alpha.h (ELF_TC_SPECIAL_SECTIONS): Removed.
> 	* config/tc-ia64.h: Likewise.
> 	* config/tc-m32r.h: Likewise.
> 	* config/tc-m68hc11.h: Likewise.
> 	* config/tc-mcore.h: Likewise.
> 	* config/tc-mips.h: Likewise.
> 	* config/tc-ppc.h: Likewise.
> 	* config/tc-sh64.h: Likewise.
> 	* config/tc-v850.h: Likewise.
> 	* config/tc-xtensa.h: Likewise.
>
> 	* config/tc-v850.h (SHF_V850_GPREL): Removed.
> 	(SHF_V850_EPREL): Likewise.
> 	(SHF_V850_R0REL): Likewise.
>
> 	* subsegs.c (subseg_get): Call obj_sec_set_private_data if it
> 	is defined.
>
> include/elf/
>
> 2003-07-24  H.J. Lu  <hongjiu.lu@intel.com>
>
> 	* v850.h (SHF_V850_GPREL): New.
> 	(SHF_V850_EPREL): Likewise.
> 	(SHF_V850_R0REL): Likewise.

Approved - please apply.

Cheers
        Nick
        

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25 12:29     ` Nick Clifton
@ 2003-07-25 14:38       ` H. J. Lu
  2003-07-25 16:10         ` H. J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H. J. Lu @ 2003-07-25 14:38 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Fri, Jul 25, 2003 at 01:25:31PM +0100, Nick Clifton wrote:
> Hi H.J.
> 
> > Here is the new patch. It caused no regressions on all targets
> > affected. It fixed an ELF/ppc64 bug.
> 
> Excellent.

...

> Approved - please apply.
> 

Done. I made a small change. I used

  if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \

instead of

  if (!_bfd_elf_new_section_hook ((B), (S)))                  \
 

H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25  4:48     ` Alan Modra
@ 2003-07-25 14:39       ` H. J. Lu
  0 siblings, 0 replies; 11+ messages in thread
From: H. J. Lu @ 2003-07-25 14:39 UTC (permalink / raw)
  To: Nick Clifton, binutils

On Fri, Jul 25, 2003 at 02:15:15PM +0930, Alan Modra wrote:
> On Thu, Jul 24, 2003 at 06:36:03PM -0700, H. J. Lu wrote:
> > 	* config/obj-elf.h (obj_sec_set_private_data): New.
> > 
> > 	* subsegs.c (subseg_get): Call obj_sec_set_private_data if it
> > 	is defined.
> 
> This is presumably to tack bfd_elf_section_data onto the standard abs,
> com, und and ind sections.  Howver, some targets allocate a larger
> structure.  You should be going via bfd_target._new_section_hook.  ie.
> BFD_SEND (stdoutput, _new_section_hook, (stdoutput, secptr))
> This will also fix a possible problem with multi-obj gas support, where
> obj-elf.h is included but you might be producing COFF output.

Done.

> 
> Also, I think the initialization should be done elsewhere, probably
> gas/output-file.c:output_file_create.

It is a per section initialization. subseg_get seems a logical place.


H.J.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25 14:38       ` H. J. Lu
@ 2003-07-25 16:10         ` H. J. Lu
  2003-07-25 17:43           ` H. J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H. J. Lu @ 2003-07-25 16:10 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

On Fri, Jul 25, 2003 at 07:38:06AM -0700, H. J. Lu wrote:
> On Fri, Jul 25, 2003 at 01:25:31PM +0100, Nick Clifton wrote:
> > Hi H.J.
> > 
> > > Here is the new patch. It caused no regressions on all targets
> > > affected. It fixed an ELF/ppc64 bug.
> > 
> > Excellent.
> 
> ...
> 
> > Approved - please apply.
> > 
> 
> Done. I made a small change. I used
> 
>   if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \
> 
> instead of
> 
>   if (!_bfd_elf_new_section_hook ((B), (S)))                  \
>  

My patch mishandled the case:

	.section .foo,"aw",@nobits

I checked in the following patch as an obvious fix.


H.J.

[-- Attachment #2: gas-type.patch --]
[-- Type: text/plain, Size: 641 bytes --]

2003-07-25  H.J. Lu  <hongjiu.lu@intel.com>

	* config/obj-elf.c (obj_elf_change_section): Always set section
	type and flags.

--- gas/config/obj-elf.c.type	2003-07-25 09:03:06.000000000 -0700
+++ gas/config/obj-elf.c	2003-07-25 08:59:49.000000000 -0700
@@ -681,11 +681,11 @@ obj_elf_change_section (name, type, attr
 		     name);
 	}
       attr |= def_attr;
-
-      elf_section_type (sec) = type;
-      elf_section_flags (sec) = attr;
     }
 
+  elf_section_type (sec) = type;
+  elf_section_flags (sec) = attr;
+
   /* Convert ELF type and flags to BFD flags.  */
   flags = (SEC_RELOC
 	   | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25 16:10         ` H. J. Lu
@ 2003-07-25 17:43           ` H. J. Lu
  2003-07-25 17:59             ` H. J. Lu
  0 siblings, 1 reply; 11+ messages in thread
From: H. J. Lu @ 2003-07-25 17:43 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 846 bytes --]

On Fri, Jul 25, 2003 at 09:10:18AM -0700, H. J. Lu wrote:
> On Fri, Jul 25, 2003 at 07:38:06AM -0700, H. J. Lu wrote:
> > On Fri, Jul 25, 2003 at 01:25:31PM +0100, Nick Clifton wrote:
> > > Hi H.J.
> > > 
> > > > Here is the new patch. It caused no regressions on all targets
> > > > affected. It fixed an ELF/ppc64 bug.
> > > 
> > > Excellent.
> > 
> > ...
> > 
> > > Approved - please apply.
> > > 
> > 
> > Done. I made a small change. I used
> > 
> >   if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \
> > 
> > instead of
> > 
> >   if (!_bfd_elf_new_section_hook ((B), (S)))                  \
> >  
> 
> My patch mishandled the case:
> 
> 	.section .foo,"aw",@nobits
> 
> I checked in the following patch as an obvious fix.
> 

It is not enough. "ld -r" is broken with

	.section .foo,"aw",@nobits
	.space 20

Here is a patch.


H.J.

[-- Attachment #2: binutils-type-fix.patch --]
[-- Type: text/plain, Size: 2060 bytes --]

bfd/

2003-07-25  H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (_bfd_elf_new_section_hook): Set the default section
	type to SHT_NULL.
	(elf_fake_sections): Set the section type based on asect->flags
	if it is SHT_NULL.

gas/

2003-07-25  H.J. Lu  <hongjiu.lu@intel.com>

	* config/obj-elf.c (obj_elf_change_section): Update
	elf_section_type and elf_section_flags only when they are
	specified.

--- binutils/bfd/elf.c.type	2003-07-25 07:49:14.000000000 -0700
+++ binutils/bfd/elf.c	2003-07-25 10:37:02.000000000 -0700
@@ -2293,12 +2293,7 @@ _bfd_elf_new_section_hook (abfd, sec)
       sec->used_by_bfd = (PTR) sdata;
     }
 
-  if ((sec->flags & SEC_ALLOC) != 0
-      && (((sec->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
-	  || (sec->flags & SEC_NEVER_LOAD) != 0))
-    elf_section_type (sec) = SHT_NOBITS;
-  else
-    elf_section_type (sec) = SHT_PROGBITS;
+  elf_section_type (sec) = SHT_NULL;
   if (sec->name && _bfd_elf_get_sec_type_attr (abfd, sec->name,
 					       &type, &attr))
     {
@@ -2544,6 +2539,18 @@ elf_fake_sections (abfd, asect, failedpt
   this_hdr->bfd_section = asect;
   this_hdr->contents = NULL;
 
+  /* If the section type is unspecified, we set it based on
+     asect->flags.  */
+  if (this_hdr->sh_type == SHT_NULL)
+    {
+      if ((asect->flags & SEC_ALLOC) != 0
+	  && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+	      || (asect->flags & SEC_NEVER_LOAD) != 0))
+	this_hdr->sh_type = SHT_NOBITS;
+      else
+	this_hdr->sh_type = SHT_PROGBITS;
+    }
+
   switch (this_hdr->sh_type)
     {
     default:
--- binutils/gas/config/obj-elf.c.type	2003-07-25 09:37:41.000000000 -0700
+++ binutils/gas/config/obj-elf.c	2003-07-25 09:52:59.000000000 -0700
@@ -683,8 +683,10 @@ obj_elf_change_section (name, type, attr
       attr |= def_attr;
     }
 
-  elf_section_type (sec) = type;
-  elf_section_flags (sec) = attr;
+  if (type != SHT_NULL)
+    elf_section_type (sec) = type;
+  if (attr != 0)
+    elf_section_flags (sec) = attr;
 
   /* Convert ELF type and flags to BFD flags.  */
   flags = (SEC_RELOC

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25 17:43           ` H. J. Lu
@ 2003-07-25 17:59             ` H. J. Lu
  2003-07-26  0:09               ` Alan Modra
  0 siblings, 1 reply; 11+ messages in thread
From: H. J. Lu @ 2003-07-25 17:59 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]

On Fri, Jul 25, 2003 at 10:43:07AM -0700, H. J. Lu wrote:
> On Fri, Jul 25, 2003 at 09:10:18AM -0700, H. J. Lu wrote:
> > On Fri, Jul 25, 2003 at 07:38:06AM -0700, H. J. Lu wrote:
> > > On Fri, Jul 25, 2003 at 01:25:31PM +0100, Nick Clifton wrote:
> > > > Hi H.J.
> > > > 
> > > > > Here is the new patch. It caused no regressions on all targets
> > > > > affected. It fixed an ELF/ppc64 bug.
> > > > 
> > > > Excellent.
> > > 
> > > ...
> > > 
> > > > Approved - please apply.
> > > > 
> > > 
> > > Done. I made a small change. I used
> > > 
> > >   if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \
> > > 
> > > instead of
> > > 
> > >   if (!_bfd_elf_new_section_hook ((B), (S)))                  \
> > >  
> > 
> > My patch mishandled the case:
> > 
> > 	.section .foo,"aw",@nobits
> > 
> > I checked in the following patch as an obvious fix.
> > 
> 
> It is not enough. "ld -r" is broken with
> 
> 	.section .foo,"aw",@nobits
> 	.space 20
> 
> Here is a patch.
> 
> 

It is still not enough. We shouldn't abort on processor specific
section types.


H.J.

[-- Attachment #2: binutils-type-fix.patch --]
[-- Type: text/plain, Size: 2399 bytes --]

bfd/

2003-07-25  H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (_bfd_elf_new_section_hook): Set the default section
	type to SHT_NULL.
	(elf_fake_sections): Set the section type based on asect->flags
	if it is SHT_NULL. Don't abort on processor specific section
	types.

gas/

2003-07-25  H.J. Lu  <hongjiu.lu@intel.com>

	* config/obj-elf.c (obj_elf_change_section): Update
	elf_section_type and elf_section_flags only when they are
	specified.

--- binutils/bfd/elf.c.type	2003-07-25 07:49:14.000000000 -0700
+++ binutils/bfd/elf.c	2003-07-25 10:55:04.000000000 -0700
@@ -2293,12 +2293,7 @@ _bfd_elf_new_section_hook (abfd, sec)
       sec->used_by_bfd = (PTR) sdata;
     }
 
-  if ((sec->flags & SEC_ALLOC) != 0
-      && (((sec->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
-	  || (sec->flags & SEC_NEVER_LOAD) != 0))
-    elf_section_type (sec) = SHT_NOBITS;
-  else
-    elf_section_type (sec) = SHT_PROGBITS;
+  elf_section_type (sec) = SHT_NULL;
   if (sec->name && _bfd_elf_get_sec_type_attr (abfd, sec->name,
 					       &type, &attr))
     {
@@ -2544,14 +2539,29 @@ elf_fake_sections (abfd, asect, failedpt
   this_hdr->bfd_section = asect;
   this_hdr->contents = NULL;
 
+  /* If the section type is unspecified, we set it based on
+     asect->flags.  */
+  if (this_hdr->sh_type == SHT_NULL)
+    {
+      if ((asect->flags & SEC_ALLOC) != 0
+	  && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+	      || (asect->flags & SEC_NEVER_LOAD) != 0))
+	this_hdr->sh_type = SHT_NOBITS;
+      else
+	this_hdr->sh_type = SHT_PROGBITS;
+    }
+
   switch (this_hdr->sh_type)
     {
     default:
+#if 0
+      /* FIXME: How to handle processor specific sections?  */
       (*_bfd_error_handler)
        (_("%s: Section `%s' has unknown type 0x%0x"),
 	bfd_get_filename (asect->owner), asect->name,
 	this_hdr->sh_type);
       abort ();
+#endif
       break;
 
     case SHT_STRTAB:
--- binutils/gas/config/obj-elf.c.type	2003-07-25 09:37:41.000000000 -0700
+++ binutils/gas/config/obj-elf.c	2003-07-25 09:52:59.000000000 -0700
@@ -683,8 +683,10 @@ obj_elf_change_section (name, type, attr
       attr |= def_attr;
     }
 
-  elf_section_type (sec) = type;
-  elf_section_flags (sec) = attr;
+  if (type != SHT_NULL)
+    elf_section_type (sec) = type;
+  if (attr != 0)
+    elf_section_flags (sec) = attr;
 
   /* Convert ELF type and flags to BFD flags.  */
   flags = (SEC_RELOC

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: PATCH: Don't use section name to set ELF section data
  2003-07-25 17:59             ` H. J. Lu
@ 2003-07-26  0:09               ` Alan Modra
  0 siblings, 0 replies; 11+ messages in thread
From: Alan Modra @ 2003-07-26  0:09 UTC (permalink / raw)
  To: H. J. Lu; +Cc: Nick Clifton, binutils

On Fri, Jul 25, 2003 at 10:59:40AM -0700, H. J. Lu wrote:
> 	* elf.c (_bfd_elf_new_section_hook): Set the default section
> 	type to SHT_NULL.
> 	(elf_fake_sections): Set the section type based on asect->flags
> 	if it is SHT_NULL. Don't abort on processor specific section
> 	types.
> 
> 	* config/obj-elf.c (obj_elf_change_section): Update
> 	elf_section_type and elf_section_flags only when they are
> 	specified.

OK.

> +#if 0
> +      /* FIXME: How to handle processor specific sections?  */

Except that you may as well remove the #if 0 code (unless you think
you might re-enable it soon).

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-07-26  0:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-14 19:14 RFC: Don't use section name to set ELF section data H. J. Lu
2003-06-19 19:17 ` Andreas Schwab
     [not found] ` <m3y901rluw.fsf@redhat.com>
2003-07-25  1:36   ` PATCH: " H. J. Lu
2003-07-25  4:48     ` Alan Modra
2003-07-25 14:39       ` H. J. Lu
2003-07-25 12:29     ` Nick Clifton
2003-07-25 14:38       ` H. J. Lu
2003-07-25 16:10         ` H. J. Lu
2003-07-25 17:43           ` H. J. Lu
2003-07-25 17:59             ` H. J. Lu
2003-07-26  0:09               ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).