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: [Bug ld/4210] PE-COFF can't handle holes between sections


On Thu, Mar 22, 2007 at 02:40:56PM -0000, nickc at redhat dot com wrote:
> 
> ------- Additional Comments From nickc at redhat dot com  2007-03-22 14:40 -------
> Hi H.J.
> 
>   This patch is OK.  Please apply.
> 

I will check in this patch with the testcase.


H.J.
---
bfd/

2003-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4210
	* peXXigen.c (_bfd_XXi_swap_aouthdr_out): Use the virtual
	address and virtual size of the last section for the image
	size.

ld/testsuite/

2003-03-22  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4210
	* ld-pe/image_size.d: New file.
	* ld-pe/image_size.s: Likewise.
	* ld-pe/image_size.t: Likewise.

	* ld-pe/pe.exp: Run image_size.

--- binutils/bfd/peXXigen.c.size	2007-03-19 19:58:57.000000000 -0700
+++ binutils/bfd/peXXigen.c	2007-03-22 07:48:39.000000000 -0700
@@ -645,16 +645,22 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
 	   in the virt_size field).  Files have been seen (from MSVC
 	   5.0 link.exe) where the file size of the .data segment is
 	   quite small compared to the virtual size.  Without this
-	   fix, strip munges the file.  */
+	   fix, strip munges the file.
+
+	   FIXME: We need to handle holes between sections, which may
+	   happpen when we covert from another format.  We just use
+	   the virtual address and virtual size of the last section
+	   for the image size.  */
 	if (coff_section_data (abfd, sec) != NULL
 	    && pei_section_data (abfd, sec) != NULL)
-	  isize += SA (FA (pei_section_data (abfd, sec)->virt_size));
+	  isize = (sec->vma - extra->ImageBase
+		   + SA (FA (pei_section_data (abfd, sec)->virt_size)));
       }
 
     aouthdr_in->dsize = dsize;
     aouthdr_in->tsize = tsize;
     extra->SizeOfHeaders = hsize;
-    extra->SizeOfImage = SA (hsize) + isize;
+    extra->SizeOfImage = isize;
   }
 
   H_PUT_16 (abfd, aouthdr_in->magic, aouthdr_out->standard.magic);
--- binutils/ld/testsuite/ld-pe/image_size.d.size	2007-03-22 08:01:26.000000000 -0700
+++ binutils/ld/testsuite/ld-pe/image_size.d	2007-03-22 07:59:39.000000000 -0700
@@ -0,0 +1,9 @@
+#name: PE-COFF SizeOfImage
+#ld: -T image_size.t
+#objdump: -p
+#target: i*86-*-mingw32
+
+.*:     file format .*
+#...
+SizeOfImage		00004000
+#...
--- binutils/ld/testsuite/ld-pe/image_size.s.size	2007-03-22 08:01:29.000000000 -0700
+++ binutils/ld/testsuite/ld-pe/image_size.s	2007-03-17 13:59:03.000000000 -0700
@@ -0,0 +1,8 @@
+	.text
+	.global _start
+_start:
+	.byte 1
+	.global data
+	.data
+data:
+	.byte 2
--- binutils/ld/testsuite/ld-pe/image_size.t.size	2007-03-22 08:01:24.000000000 -0700
+++ binutils/ld/testsuite/ld-pe/image_size.t	2007-03-17 14:27:25.000000000 -0700
@@ -0,0 +1,15 @@
+SECTIONS
+{
+  . = SIZEOF_HEADERS;
+  . = ALIGN(__section_alignment__);
+  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :
+  {
+    *(.text)
+  }
+  . = . + 0x1000;
+  .data BLOCK(__section_alignment__) :
+  {
+    *(.data)
+  }
+  /DISCARD/ : { *(.*) }
+}
--- binutils/ld/testsuite/ld-pe/pe.exp.size	2007-01-08 09:28:56.000000000 -0800
+++ binutils/ld/testsuite/ld-pe/pe.exp	2007-03-22 07:53:57.000000000 -0700
@@ -32,3 +32,5 @@ set pe_tests {
 }
 
 run_ld_link_tests $pe_tests
+
+run_dump_test "image_size"


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