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: Nick Clifton <nickc at redhat dot com>
- To: chris at groessler dot org
- Cc: richard at trust-factory dot com, binutils at sources dot redhat dot com, chris at groessler dot org, dj at delorie dot com
- Date: Thu, 3 Apr 2003 12:12:06 +0100
- Subject: Re: Strip 2.13 corrupts exe file
- References: <200303271735.SAA13804@Caligula.cnet.aladdin.de>
Hi Chris,
: 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. :-( )
I have applied a slight variation of your patch. The changes I made
were:
1. Extract the test to distinguish between a PE executable and a PE
object file and put it into a macro.
2. Remove the x86 specific nature of the change to
..._swap_scnhdr_out, and make it apply to all PE ports.
3. Create a ChangeLog entry.
Here is the patch that I have applied.
Cheers
Nick
2003-04-03 Nick Clifton <nickc at redhat dot com>
* peXXigen.c (_bfd_XXi_swap_scnhdr_out): Compute ps and ss
differently for object files and executables.
* peicode.h (coff_swap_scnhdr_in): Only set the s_size field
for object files or for executables who have not already
initialised the field.
* libpei.h (bfd_pe_executable_p): New macro. Return true if
the PE format bfd is an executable.
Index: bfd/peXXigen.c
===================================================================
RCS file: /cvs/src/src/bfd/peXXigen.c,v
retrieving revision 1.13
diff -c -3 -p -w -r1.13 peXXigen.c
*** bfd/peXXigen.c 20 Mar 2003 09:02:09 -0000 1.13
--- bfd/peXXigen.c 3 Apr 2003 11:08:29 -0000
*************** _bfd_XXi_swap_scnhdr_out (abfd, in, out)
*** 906,917 ****
--- 906,929 ----
sometimes). */
if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0)
{
+ if (bfd_pe_executable_p (abfd))
+ {
ps = scnhdr_int->s_size;
ss = 0;
}
else
{
+ ps = 0;
+ ss = scnhdr_int->s_size;
+ }
+ }
+ else
+ {
+ if (bfd_pe_executable_p (abfd))
ps = scnhdr_int->s_paddr;
+ else
+ ps = 0;
+
ss = scnhdr_int->s_size;
}
Index: bfd/peicode.h
===================================================================
RCS file: /cvs/src/src/bfd/peicode.h,v
retrieving revision 1.35
diff -c -3 -p -w -r1.35 peicode.h
*** bfd/peicode.h 30 Nov 2002 08:39:40 -0000 1.35
--- bfd/peicode.h 3 Apr 2003 11:08:30 -0000
*************** coff_swap_scnhdr_in (abfd, ext, in)
*** 264,270 ****
--- 261,271 ----
if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
&& (scnhdr_int->s_paddr > 0))
{
+ /* Always set it for non pe-obj files, and don't overwrite it
+ if it's zero for object files. */
+ if (! bfd_pe_executable_p (abfd) || !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
Index: bfd/libpei.h
===================================================================
RCS file: /cvs/src/src/bfd/libpei.h,v
retrieving revision 1.9
diff -c -3 -p -w -r1.9 libpei.h
*** bfd/libpei.h 30 Nov 2002 08:39:40 -0000 1.9
--- bfd/libpei.h 3 Apr 2003 11:08:30 -0000
*************** unsigned int _bfd_XX_only_swap_filehdr_o
*** 333,335 ****
--- 330,335 ----
unsigned int _bfd_XXi_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
bfd_boolean _bfd_XX_bfd_copy_private_section_data
PARAMS ((bfd *, asection *, bfd *, asection *));
+
+ /* Macro: Returns true if the bfd is a PE executable as opposed to a PE object file. */
+ #define bfd_pe_executable_p(abfd) (strncmp ((abfd)->xvec->name, "pei-", 4) == 0)