Possible bug in binutils for MinGW-w64 related to linking weak symbols

Martin Storsjö martin@martin.st
Fri Mar 20 06:54:08 GMT 2026


On Thu, 19 Mar 2026, Fangrui Song wrote:

> There is a distinction between weak definition and weak reference.

Indeed; using a weak reference to access a potentially weak definition (as 
suggested above, by requiring the attribute to be used consistently on all 
declarations) seems both surprising and redundant. Plus that it is extra 
brittle due to relying on the linking order of the two object files, 
currently.

If using a weak reference, the referencer should be ready to handle the 
case that there was no actual symbol present (the symbol resolving to 
absolute null), while the weak definition is for handling possibly two 
definitions of the same, with one giving way for the other.

> The linker should allow a regular reference from foobar.o to resolve
> to a weak definition (simulated with IMAGE_SYM_CLASS_WEAK_EXTERNAL
> IMAGE_SYM_UNDEFINED symbol with an IMAGE_SYM_CLASS_EXTERNAL
> IMAGE_SYM_ABSOLUTE auxiliary symbol
> https://maskray.me/blog/2021-04-25-weak-symbol#pecoff).

You've mixed up the quotes here.

An IMAGE_SYM_CLASS_WEAK_EXTERNAL IMAGE_SYM_UNDEFINED symbol with an 
IMAGE_SYM_CLASS_EXTERNAL IMAGE_SYM_ABSOLUTE auxiliary symbol is used for 
weak references (with the absolute symbol used as the fallback null 
pointer, in case nothing else was found).

An IMAGE_SYM_CLASS_WEAK_EXTERNAL IMAGE_SYM_UNDEFINED symbol with a defined 
IMAGE_SYM_CLASS_EXTERNAL symbol (for the actual function or data symbol) 
is used for weak definitions.

// Martin



More information about the Binutils mailing list