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: PATCH: PR ld/5522: Section contents partially overwritten with zero


On Wed, Dec 26, 2007 at 05:25:29PM -0800, H.J. Lu wrote:
> ELF linker may write out a section even when its output section is
> marked with SEC_NEVER_LOAD and override the next section. This patch
> fixes it.
> 

Here is the updated patch with a testcase.


H.J.
---
bfd/

2007-12-27  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/5522
	* elflink.c (elf_link_input_bfd): Don't write out a section if
	its output section is marked with SEC_NEVER_LOAD.

ld/testsuite/

2007-12-27  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/5522
	* ld-elf/noload-3.d: New file.
	* ld-elf/noload-3.s: Likewise.
	* ld-elf/noload-3.t: Likewise.

--- binutils/bfd/elflink.c.noload	2007-12-27 09:48:01.000000000 -0800
+++ binutils/bfd/elflink.c	2007-12-27 09:48:01.000000000 -0800
@@ -9599,6 +9599,7 @@ elf_link_input_bfd (struct elf_final_lin
 	default:
 	  {
 	    if (! (o->flags & SEC_EXCLUDE)
+		&& ! (o->output_section->flags & SEC_NEVER_LOAD)
 		&& ! bfd_set_section_contents (output_bfd, o->output_section,
 					       contents,
 					       (file_ptr) o->output_offset,
--- binutils/ld/testsuite/ld-elf/noload-3.d.noload	2007-12-27 09:48:01.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/noload-3.d	2007-12-27 09:48:01.000000000 -0800
@@ -0,0 +1,7 @@
+#ld: -T noload-3.t
+#objdump: -s -j .foo1
+
+#...
+Contents of section .foo1:
+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9a-f]+[ \t]+This is a test.*
+#pass
--- binutils/ld/testsuite/ld-elf/noload-3.s.noload	2007-12-27 09:48:01.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/noload-3.s	2007-12-27 09:49:53.000000000 -0800
@@ -0,0 +1,6 @@
+	.section .foo2,"aw",%progbits
+	.byte 1
+	.section .foo1,"w",%progbits
+	.string "This is a test."
+	.section .foo,"aw",%progbits
+	.space 16
--- binutils/ld/testsuite/ld-elf/noload-3.t.noload	2007-12-27 09:48:01.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/noload-3.t	2007-12-27 09:48:01.000000000 -0800
@@ -0,0 +1,7 @@
+SECTIONS
+{
+  .foo2 : { *(.foo2) }
+  .foo1 : { *(.foo1) }
+  .foo (NOLOAD) : { *(.foo) }
+  /DISCARD/ : { *(*) }
+}


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