[PATCH/RFC] Fix LD test FAIL: weak symbols on Cygwin

Aaron W. LaFramboise aaron98wiridge9@aaronwl.com
Wed Mar 18 23:51:00 GMT 2009

Kai Tietz wrote:

> As far as I see the weak support for pe(p)-coff targets isn't complete. 
> The comdat stuff is half implemented and bfd uses internally just 
> C_NT_WEAK, but it should use C_WEAKEXT in most cases instead.
> I think there is much work left to support weak in a better way.

What I implemented specifically were the PECOFF weak symbols specified 
in the standard (C_NT_WEAK).  I implemented them specifically because I 
needed them for link interoperability with MSVC code, which generates 
them to solve C++ destructor resolution.

A lot of people feel that PECOFF should be extended with an ELF-like 
weak symbol, which presumably would be called C_WEAKEXT.  The C_NT_WEAK 
symbols presently implemented by .weak in gas have some special features 
that make them behave more alike to to ELF weak symbols than implemented 
in Microsoft's tools, without breaking standard conformance.  (The 
effect of this is that weak symbols generated by gas will work just fine 
with MS LINK.)

The only important thing that ELF symbols can do that PECOFF symbols 
simply cannot do is satisfy external references.  It's my opinion that 
this is not actually a very important feature, but because ELF can do 
it, it comes up a lot on Linux-based code as a way of making two steps 
into one.  I believe Danny Smith may have extended binutils ld to make 
this sort of thing work, as an extension to PECOFF, although I don't 
really know the status of this.

I have nothing against someone implementing an extension to PECOFF that 
has ELF-style weak symbols (C_WEAKEXT); but that really has nothing to 
do with the existing weak symbol support.  In any case, I think it's 
important we correctly implement the ones specified by the standard.

Also, as far as I know, this isn't related to COMDAT sections, although 
they're a similar mechanism.  I agree with you that completely 
implementing COMDAT as specified in PECOFF would be very valuable.  To 
the extent that C_NT_WEAK symbols and COMDAT sections intersect, 
everything should work now, although the testsuite does not test this.

More information about the Binutils mailing list