This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Strip 2.13 corrupts exe file
- From: Christian Groessler <chris at groessler dot org>
- To: Richard van den Berg <richard at trust-factory dot com>
- Cc: Nick Clifton <nickc at redhat dot com>, binutils at sources dot redhat dot com, chris at groessler dot org, dj at delorie dot com
- Date: Thu, 27 Mar 2003 18:35:00 +0100 (MET)
- Subject: Re: Strip 2.13 corrupts exe file
Hi,
On Fri, 21 Mar 2003, Richard van den Berg wrote:
> Christian Groessler wrote:
> > There are also problems mixing vc++ and binutils object files, see
> > http://sources.redhat.com/ml/binutils/2001-12/msg00327.html
>
> That link talks about a problem with linking binutils object file using
> the VC++ linker. I haven't tried that myself. I did link a VC++ object
> file with gcc object files using binutils. The resulting executable was
> not working as expected. I experienced all sorts of weird buffer
> overflows. This is the reason we are now moving to VC++ for all object
> files.
>
> Thanks for the info, as I could see myself coming across this situation
> in the near future. I take it, it has not been resolved?
I'm using the attached patch. It doesn't change the behaviour for exe
files and fixes the handling of object files wrt linking with MS
linker.
I *think* it should also work for the gnu linker, because objdump with
the patch applied still reports correct bss and data sizes.
Maybe I can be considered for integration? (Although I can't remember
right now why I've added the '|| !scnhdr_int->s_size' part. :-( )
regards,
chris
--------------------
Index: peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.13
diff -p -u -r1.13 peXXigen.c
--- peXXigen.c 20 Mar 2003 09:02:09 -0000 1.13
+++ peXXigen.c 27 Mar 2003 17:18:42 -0000
@@ -906,12 +906,27 @@ _bfd_XXi_swap_scnhdr_out (abfd, in, out)
sometimes). */
if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0)
{
- ps = scnhdr_int->s_size;
- ss = 0;
+ if (strcmp(abfd->xvec->name, "pe-i386") == 0)
+ { /* object file. */
+ ps = 0;
+ ss = scnhdr_int->s_size;
+ }
+ else
+ { /* executable file. */
+ ps = scnhdr_int->s_size;
+ ss = 0;
+ }
}
else
{
- ps = scnhdr_int->s_paddr;
+ if (strcmp(abfd->xvec->name, "pe-i386") == 0)
+ { /* object file. */
+ ps = 0;
+ }
+ else
+ { /* executable file. */
+ ps = scnhdr_int->s_paddr;
+ }
ss = scnhdr_int->s_size;
}
Index: peicode.h
===================================================================
RCS file: /cvs/src/src/bfd/peicode.h,v
retrieving revision 1.35
diff -p -u -r1.35 peicode.h
--- peicode.h 30 Nov 2002 08:39:40 -0000 1.35
+++ peicode.h 27 Mar 2003 17:18:42 -0000
@@ -264,7 +264,10 @@ coff_swap_scnhdr_in (abfd, ext, in)
if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
&& (scnhdr_int->s_paddr > 0))
{
- scnhdr_int->s_size = scnhdr_int->s_paddr;
+ /* Always set it for non pe-obj files, and don't overwrite it
+ if it's zero for object files. */
+ if (strncmp(abfd->xvec->name, "pe-", 3) != 0 || !scnhdr_int->s_size)
+ scnhdr_int->s_size = scnhdr_int->s_paddr;
/* This code used to set scnhdr_int->s_paddr to 0. However,
coff_set_alignment_hook stores s_paddr in virt_size, which
only works if it correctly holds the virtual size of the
--------------------