public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR12921
@ 2011-06-24  3:58 Alan Modra
  2011-06-24 14:04 ` PR12921 H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2011-06-24  3:58 UTC (permalink / raw)
  To: binutils

I've committed this patch to both mainline and 2.21.

	PR ld/12921
	* elf.c (assign_file_positions_for_load_sections): Don't align
	sh_offset for all SHT_NOBITS sections here, just .tbss sections
	that don't get a PT_LOAD.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.541
diff -u -p -r1.541 elf.c
--- bfd/elf.c	16 Jun 2011 12:34:19 -0000	1.541
+++ bfd/elf.c	23 Jun 2011 15:26:38 -0000
@@ -4684,24 +4684,26 @@ assign_file_positions_for_load_sections 
 	    }
 	  else
 	    {
-	      if (p->p_type == PT_LOAD
-		  || (this_hdr->sh_type == SHT_NOBITS
-		      && (this_hdr->sh_flags & SHF_TLS) != 0
-		      && this_hdr->sh_offset == 0))
+	      if (p->p_type == PT_LOAD)
 		{
-		  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;
-		    }
+		  this_hdr->sh_offset = sec->filepos = off;
+		  if (this_hdr->sh_type != SHT_NOBITS)
+		    off += this_hdr->sh_size;
+		}
+	      else if (this_hdr->sh_type == SHT_NOBITS
+		       && (this_hdr->sh_flags & SHF_TLS) != 0
+		       && this_hdr->sh_offset == 0)
+		{
+		  /* This is a .tbss section that didn't get a PT_LOAD.
+		     (See _bfd_elf_map_sections_to_segments "Create a
+		     final PT_LOAD".)  Set sh_offset to the value it
+		     would have if we had created a zero p_filesz and
+		     p_memsz PT_LOAD header for the section.  This
+		     also makes the PT_TLS header have the same
+		     p_offset value.  */
+		  bfd_vma adjust = vma_page_aligned_bias (this_hdr->sh_addr,
+							  off, align);
+		  this_hdr->sh_offset = sec->filepos = off + adjust;
 		}
 
 	      if (this_hdr->sh_type != SHT_NOBITS)

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: PR12921
  2011-06-24  3:58 PR12921 Alan Modra
@ 2011-06-24 14:04 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2011-06-24 14:04 UTC (permalink / raw)
  To: binutils

On Thu, Jun 23, 2011 at 8:58 PM, Alan Modra <amodra@gmail.com> wrote:
> I've committed this patch to both mainline and 2.21.
>
>        PR ld/12921
>        * elf.c (assign_file_positions_for_load_sections): Don't align
>        sh_offset for all SHT_NOBITS sections here, just .tbss sections
>        that don't get a PT_LOAD.

I checked in this patch to add a testcase:

diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 75c0c09..4817ef2 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2011-06-24  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/12921
+	* ld-i386/i386.exp: Run pr12921.
+	* ld-x86-64/x86-64.exp: Likewise.
+
+	* ld-i386/pr12921.d: New.
+	* ld-i386/pr12921.s: Likewise.
+	* ld-x86-64/pr12921.d: Likewise.
+	* ld-x86-64/pr12921.s: Likewise.
+
 2011-06-22  Thomas Schwinge  <thomas@schwinge.name>

 	* ld-elf/elf.exp: Execute array_tests_pie tests on *-*-gnu*, too.
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index ae798c0..68b71fb 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -200,6 +200,7 @@ run_dump_test "nogot1"
 run_dump_test "nogot2"
 run_dump_test "discarded1"
 run_dump_test "pr12718"
+run_dump_test "pr12921"

 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr12921.d b/ld/testsuite/ld-i386/pr12921.d
new file mode 100644
index 0000000..4b75888
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr12921.d
@@ -0,0 +1,21 @@
+#name: PR ld/12921
+#as: --32
+#ld: -melf_i386
+#readelf: -S --wide
+
+There are 7 section headers, starting at offset 0x204c:
+
+Section Headers:
+  \[Nr\] Name              Type            Addr     Off    Size   ES
Flg Lk Inf Al
+  \[ 0\]                   NULL            00000000 000000 000000 00
    0   0  0
+  \[ 1\] .text             PROGBITS        08049000 001000 000001 00
AX  0   0 4096
+  \[ 2\] .data             PROGBITS        0804b000 002000 000020 00
WA  0   0 4096
+  \[ 3\] .bss              NOBITS          0804c000 002020 010000 00
WA  0   0 4096
+  \[ 4\] .shstrtab         STRTAB          00000000 002020 00002c 00
    0   0  1
+  \[ 5\] .symtab           SYMTAB          00000000 002164 0000c0 10
    6   6  4
+  \[ 6\] .strtab           STRTAB          00000000 002224 000037 00
    0   0  1
+Key to Flags:
+  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\)
+  I \(info\), L \(link order\), G \(group\), T \(TLS\), E
\(exclude\), x \(unknown\)
+  O \(extra OS processing required\) o \(OS specific\), p \(processor
specific\)
+#pass
diff --git a/ld/testsuite/ld-i386/pr12921.s b/ld/testsuite/ld-i386/pr12921.s
new file mode 100644
index 0000000..9c4966f
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr12921.s
@@ -0,0 +1,25 @@
+	.text
+	.balign 4096
+vtext:
+	.p2align 4,,15
+	.globl	_start
+	.type	_start, @function
+_start:
+	ret
+	.size	_start, .-_start
+	.globl	vdata
+	.data
+	.align 4096
+	.type	vdata, @object
+	.size	vdata, 4
+vdata:
+	.long	5
+	.comm	vbss,65536,4096
+	.align 16
+	.type	local, @object
+	.size	local, 24
+local:
+	.byte	77
+	.zero	7
+	.dc.a	local
+	.dc.a	0
diff --git a/ld/testsuite/ld-x86-64/pr12921.d b/ld/testsuite/ld-x86-64/pr12921.d
new file mode 100644
index 0000000..c0fe8ab
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr12921.d
@@ -0,0 +1,21 @@
+#name: PR ld/12921
+#as: --64
+#ld: -melf_x86_64
+#readelf: -S --wide
+
+There are 7 section headers, starting at offset 0x2058:
+
+Section Headers:
+  \[Nr\] Name              Type            Address          Off
Size   ES Flg Lk Inf Al
+  \[ 0\]                   NULL            0000000000000000 000000
000000 00      0   0  0
+  \[ 1\] .text             PROGBITS        0000000000401000 001000
000001 00  AX  0   0 4096
+  \[ 2\] .data             PROGBITS        0000000000602000 002000
000028 00  WA  0   0 4096
+  \[ 3\] .bss              NOBITS          0000000000603000 002028
010000 00  WA  0   0 4096
+  \[ 4\] .shstrtab         STRTAB          0000000000000000 002028
00002c 00      0   0  1
+  \[ 5\] .symtab           SYMTAB          0000000000000000 002218
000120 18      6   6  8
+  \[ 6\] .strtab           STRTAB          0000000000000000 002338
000037 00      0   0  1
+Key to Flags:
+  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S
\(strings\), l \(large\)
+  I \(info\), L \(link order\), G \(group\), T \(TLS\), E
\(exclude\), x \(unknown\)
+  O \(extra OS processing required\) o \(OS specific\), p \(processor
specific\)
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr12921.s b/ld/testsuite/ld-x86-64/pr12921.s
new file mode 100644
index 0000000..9c4966f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr12921.s
@@ -0,0 +1,25 @@
+	.text
+	.balign 4096
+vtext:
+	.p2align 4,,15
+	.globl	_start
+	.type	_start, @function
+_start:
+	ret
+	.size	_start, .-_start
+	.globl	vdata
+	.data
+	.align 4096
+	.type	vdata, @object
+	.size	vdata, 4
+vdata:
+	.long	5
+	.comm	vbss,65536,4096
+	.align 16
+	.type	local, @object
+	.size	local, 24
+local:
+	.byte	77
+	.zero	7
+	.dc.a	local
+	.dc.a	0
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp
b/ld/testsuite/ld-x86-64/x86-64.exp
index 58e4bc0..bf75d00 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -161,6 +161,7 @@ run_dump_test "nogot1"
 run_dump_test "nogot2"
 run_dump_test "discarded1"
 run_dump_test "pr12718"
+run_dump_test "pr12921"

 if { ![istarget "x86_64-*-linux*"] } {
     return

-- 
H.J.

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

end of thread, other threads:[~2011-06-24 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-24  3:58 PR12921 Alan Modra
2011-06-24 14:04 ` PR12921 H.J. Lu

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).