Possible bug in binutils for MinGW-w64 related to linking weak symbols
Martin Storsjö
martin@martin.st
Thu Mar 19 14:37:18 GMT 2026
On Thu, 19 Mar 2026, Martin Storsjö wrote:
> When you use a declaration of a weak symbol (which means that the symbol
> either may be defined, or may be undefined, when it essentially is a null
> pointer), then the symbol "bar" points at an absolute symbol with the address
> zero. The idea here is that if nothing else overrides the symbol, then it
> uses the fallback value of absolute zero (and in that case, the user should
> check if it is null before referencing it).
Sorry, I misremembered one detail here. The default symbol it points at
isn't an absolute zero symbol, it's an undefined symbol. That makes it
easier to disambiguate between a weak external pointing at an actual
definition (which should be preferred), and a weak external pointing at an
undefined symbol (which is just a dummy).
FWIW, from when I implemented this in LLVM, I made a set of unit tests for
linking of weak symbols - see https://martin.st/temp/weak-testcases.zip.
// Martin
More information about the Binutils
mailing list