This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: Fix PR12763, .tbss mishandling


This fixes further fallout.

i370-linux  +FAIL: objcopy  (tbss1)
i370-linux  +FAIL: objcopy -z relro (tbss1)
i370-linux  +FAIL: objcopy -z max-page-size=0x100000 (tbss1)
i370-linux  +FAIL: objcopy -z max-page-size=0x100000 -z common-page-size=0x1000 (tbss1)

These failures are due to this target using its own scripts that lack
mention of .tdata/.bss rather than using elf.sc, which exposed bugs in
orphan .tbss handling.  While looking at this, I noticed that
lang_output_section_find_by_flags had the curious property that an
orphan .sdata2 like section wouldn't be placed after .sdata2, and
similarly for orphan TLS sections.

bfd/
	PR 12763
	* elf.c (assign_file_positions_for_load_sections): Set sh_offset for
	.tbss, and page align same for all SHT_NOBITS sections.
ld/
	PR 12763
	* ldlang.c (lang_output_section_find_by_flags): Match orphan .sdata2
	like sections to existing .sdata2, and similarly for orphan TLS
	sections.
	* emultempl/elf32.em (place_orphan): Exclude .tbss from orphan_bss.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.537
diff -u -p -r1.537 elf.c
--- bfd/elf.c	20 May 2011 15:32:24 -0000	1.537
+++ bfd/elf.c	23 May 2011 01:15:28 -0000
@@ -4684,11 +4684,24 @@ assign_file_positions_for_load_sections 
 	    }
 	  else
 	    {
-	      if (p->p_type == PT_LOAD)
+	      if (p->p_type == PT_LOAD
+		  || (this_hdr->sh_type == SHT_NOBITS
+		      && (this_hdr->sh_flags & SHF_TLS) != 0
+		      && this_hdr->sh_offset == 0))
 		{
-		  this_hdr->sh_offset = sec->filepos = off;
-		  if (this_hdr->sh_type != SHT_NOBITS)
-		    off += this_hdr->sh_size;
+		  if (this_hdr->sh_type == SHT_NOBITS)
+		    {
+		      /* These sections don't really need sh_offset,
+			 but give them one anyway.  */
+		      bfd_vma adjust = vma_page_aligned_bias (this_hdr->sh_addr,
+							      off, align);
+		      this_hdr->sh_offset = sec->filepos = off + adjust;
+		    }
+		  else
+		    {
+		      this_hdr->sh_offset = sec->filepos = off;
+		      off += this_hdr->sh_size;
+		    }
 		}
 
 	      if (this_hdr->sh_type != SHT_NOBITS)
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.369
diff -u -p -r1.369 ldlang.c
--- ld/ldlang.c	16 May 2011 11:34:48 -0000	1.369
+++ ld/ldlang.c	23 May 2011 01:16:19 -0000
@@ -1579,8 +1579,14 @@ lang_output_section_find_by_flags (const
 	    }
 	  flags ^= sec->flags;
 	  if (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD
-			 | SEC_READONLY))
-	      && !(look->flags & (SEC_SMALL_DATA | SEC_THREAD_LOCAL)))
+			 | SEC_READONLY | SEC_SMALL_DATA))
+	      || (!(flags & (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD
+			     | SEC_READONLY))
+		  && !(look->flags & SEC_SMALL_DATA))
+	      || (!(flags & (SEC_THREAD_LOCAL | SEC_ALLOC))
+		  && (look->flags & SEC_THREAD_LOCAL)
+		  && (!(flags & SEC_LOAD)
+		      || (look->flags & SEC_LOAD))))
 	    found = look;
 	}
     }
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.218
diff -u -p -r1.218 elf32.em
--- ld/emultempl/elf32.em	28 Feb 2011 18:34:52 -0000	1.218
+++ ld/emultempl/elf32.em	23 May 2011 01:16:21 -0000
@@ -1920,7 +1920,7 @@ gld${EMULATION_NAME}_place_orphan (asect
 	   && ((iself && sh_type == SHT_NOTE)
 	       || (!iself && CONST_STRNEQ (secname, ".note"))))
     place = &hold[orphan_interp];
-  else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
+  else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
     place = &hold[orphan_bss];
   else if ((s->flags & SEC_SMALL_DATA) != 0)
     place = &hold[orphan_sdata];

-- 
Alan Modra
Australia Development Lab, IBM


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