This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: PE COFF relocation overflow bug
- From: Mark Mitchell <mark at codesourcery dot com>
- To: binutils at sources dot redhat dot com
- Date: Fri, 05 Jul 2002 16:23:25 -0700
- Subject: PATCH: PE COFF relocation overflow bug
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)