[patch suggestion]: pe-i386 s_size and s_paddr handling
Christian Groessler
cpg@aladdin.de
Tue Jan 1 15:31:00 GMT 2002
Hello,
There is a problem in the generated section header for .bss
sections. s_size is set to 0 and s_paddr is set to the length of the
section. But it should be the other way round.
This gives a problem, when I try to link a gcc generated object file
(containing a bss section) with the MS linker, since the linker reads
a bss length of 0.
The meaning of the s_size and s_paddr fields seems to differ if it's an
object file or executable. binutils don't make this difference, they
handle object files like executables.
Quoting from MS docs:
VirtualSize (s_paddr): Total size of the section when loaded into
memory. If this value is greater than Size of
Raw Data, the section is zero-padded. This
field is valid only for executable images and
should be set to 0 for object files.
SizeOfRawData (s_size): Size of the section (object file) or size of
the initialized data on disk (image
files). For executable image, this must be a
multiple of FileAlignment from the optional
header. If this is less than VirtualSize the
remainder of the section is zero
filled. Because this field is rounded while
the VirtualSize field is not it is possible
for this to be greater than VirtualSize as
well. When a section contains only
uninitialized data, this field should be 0.
The following patch fixes the behaviour to be in line with the MS
tools behaviour.
Changelog:
bfd/
2002-01-01 Christian Groessler <cpg@aladdin.de>
* peXXigen.c (_bfd_XXi_swap_scnhdr_out): Fix handling of
s_size and s_paddr entries in the section header. They have
different meaning depending on whether it's an object file or
executable (image) file.
------------
--- bfd/peXXigen.c Mon Dec 31 01:10:44 2001
+++ bfd/peXXigen.c.new Mon Dec 31 01:10:44 2001
@@ -897,12 +897,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;
}
------------
What do you think?
regards,
chris
More information about the Binutils
mailing list