PATCH: PE COFF relocation overflow bug
Mark Mitchell
mark@codesourcery.com
Sat Jul 6 02:58:00 GMT 2002
This patch fixes a bug in the PE COFF linker.
When writing out sections with more than 0xffff relocations, we (like
Microsoft's tools), replace the relocation count with 0xffff and
encode the real relocation count by adding a dummy relocation to the
relocation table.
The only problem is that we forget to take into account that extra
relocation when computing file offsets. That causes major problems;
the offset to the symbol table (from the COFF header) is incorrect,
for example.
This shows up with "ld -r" when you have enough relocations; the
.o you get from "ld -r" is corrupted.
OK to check in?
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-07-05 Mark Mitchell <mark@codesourcery.com>
* cofflink.c (_bfd_coff_final_link): On PE COFF systems, take into
account the impact of relocation count overflow when computing
section offsets.
Index: cofflink.c
===================================================================
RCS file: /cvs/src/src/bfd/cofflink.c,v
retrieving revision 1.33
diff -c -p -r1.33 cofflink.c
*** cofflink.c 7 Jun 2002 15:04:47 -0000 1.33
--- cofflink.c 5 Jul 2002 23:11:32 -0000
*************** _bfd_coff_final_link (abfd, info)
*** 757,762 ****
--- 757,766 ----
o->flags |= SEC_RELOC;
o->rel_filepos = rel_filepos;
rel_filepos += o->reloc_count * relsz;
+ /* In PE COFF, if there are at least 0xffff relocations an
+ extra relocation will be written out to encode the count. */
+ if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+ rel_filepos += relsz;
}
if (bfd_coff_long_section_names (abfd)
More information about the Binutils
mailing list