On 2026-02-18 12:37, Johannes Khoshnazar-Thoma wrote:
Am 26.01.26 um 11:36 schrieb Martin Storsjö:
On Mon, 26 Jan 2026, LIU Hao wrote:

Yes and no. PE COFF object files do not support weak symbols; only weak externals [1]. So by that definition, weak symbols are not supported by GNU toolchains on Windows [2], and may produce unexpected behavior.

In this case you might want to try LLVM [3].

FWIW, LLVM/Clang in mingw mode does implement weak symbols in the same way as the GNU toolchains do - except that there are a few bugs in that area in the GNU toolchains, in my experience.

When implementing it in LLVM, I made a set of testcases for it, to exercise all the relevant corner cases. With GNU toolchains, there are a number of those tests that fail. I haven't filed bugs for those, but if you want to dissect them and file bugs for the individual cases, I can provide you my test project.

For the given testcase by the original poster here, it does link correctly with Clang/LLD.

// Martin

I tested the test program with LLVM and it works there. Is there any possibility to make it work with MinGW-W64 as well? I am willing to help fixing it, if someone points me into the right direction. It would be very valueable to be able to compile the Linux kernel as a Windows Driver [1] with MinGW-w64 without having to patch
the header files (adding __weak where it does not really belong).

Thank you for your attention,

Best regards,

- Johannes

[1] https://jtsoft.at/linux-drivers-for-windows/

I'd be interested in fixing these bugs in gcc too. Can you report them, or link the test project?



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to