PATCH: Don't use section name to set ELF section data

H. J. Lu hjl@lucon.org
Fri Jul 25 17:43:00 GMT 2003


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.
-------------- next part --------------
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


More information about the Binutils mailing list