This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C_WEAKEXT Weak Externals in i386-pe COFF


Hi Aaron,

> I'm trying to get GNU ld to link objects produced from
> MSVC, and I beleive I have found a problem with binutils'
> C_WEAKEXT support:
>
> Weak externals, apparently known within binutils as
> C_WEAKEXT, to Win32 as IMAGE_SYM_CLASS_WEAK_EXTERNAL,
> and documented in the Win32 PE COFF spec in section 5.5.3,
> are a loose analog of ELF weak symbols.  Binutils seems
> to treat them the same way as their ELF counterparts, however,
> they are actually substancially different.
>
> Quoting from the spec:
>   "If a definition of sym1 is linked, then an external reference to
>    the symbol is resolved normally. If a definition of sym1 is not
>    linked, then all references to the weak external for sym1 refer
>    to sym2 instead. The external symbol, sym2, must always be
>    linked; typically it is defined in the module containing the weak
>    reference to sym1." 
>
> In other words, where ELF weak symbols default to zero if
> not resolved, COFF weak symbols default to some other
> symbol.
>
> Is there some way to get binutils to correctly resolve
> these kinds of symbols?

At the moment - no.

> Has anyone worked on this, or had any luck getting these kinds of
> things to link?

I do not think so. :-(

> If no to the above, how difficult would it be to add this
> support?  (I am unfamiliar with binutils internals.)

It would probably be tricky.  But it certainly is do-able.  BFD's
internals can seem daunting at first but they are not that bad
really.  Plus you can always ask on this list for help.


The files you are most likely to want to look at and modify are
bfd/coffcode.h and bfd/cofflink.c.  In particular have a look at the
function _bfd_coff_write_global_sym().

Another thing that might help is if you can create a small test case
that can be added to the linker testsuite.  That way anyone who runs
the linker tests (for a WinCE target) will be reminded that this
problem exists and they might even be motivated to fix it.

Cheers
        Nick
        


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]