This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: PEI 16bit relocation problem -- possible fix idea
Date: Tue, 18 Jan 2000 00:04:05 -0600 (CST)
From: Mumit Khan <khan@NanoTech.Wisc.EDU>
I believe there've already been bug reports on the issue that pei-coff
doesn't allow relocations larger than what fits in a 16 bit field
reserved for the relocation count. Turns out that PEI has a workaround
for this particular problem, and quoting the MSDN docs Sec 4.1 "Section
Flags" (http://msdn.microsoft.com/library/specs/pecoff_section4_1.htm):
IMAGE_SCN_LNK_NRELOC_OVFL indicates that the count of relocations for
the section exceeds the 16 bits reserved for it in section header. If
the bit is set and the NumberOfRelocations field in the section header
is 0xffff, the actual relocation count is stored in the 32-bit
VirtualAddress field of the first relocation.
This looks like something reasonably simple to implement given that
RS6k/COFF (XCOFF?) has something similar. However, given my lack of BFD
backend knowledge, I'd really like some input on how to proceed with
this. I see the comment about "grossly abusing" coff_set_alignment_hook
in bfd/coffcode.h, and it does smell like a hack. Is this the way to go?
It's not quite the same as XCOFF, but you probably do have to do it
there. The problem is that in order to set the reloc_count field of
the asection structure correctly, you need to hook in to the code
which sets up the asection. That code uses set_alignment_hook, so
it's a convenient place to hook in. Probably that hook should be
renamed. For PE, it will have to check for the flag; if it is set,
read the first relocation to get the correct count.
Note that PE already uses the set_alignment_hook for other operations,
such as setting the alignment. You just need to add code there.
Then you'll need to patch slurp_reloc_table to skip the first
relocation.
The next trick is to set the flag and create the relocation entry on
output. Setting the flag would be done in coff_write_object_contents,
I suppose. The extra reloc would be written out in coff_write_relocs.
Ian