Hi, I'd like to ask what is the correct and suggested order of linking mingw-w64 related libs. We currently faced some linking order problems, see [1].
Currently: GCC uses "-lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32", which is genrated from "%G %L %G", with %G = "-lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32" and %L = "-lpthread -ladvapi32 -lshell32 -luser32 -lkernel32". This is safe, but may be a little redundant. Clang uses "-lssp_nonshared -lssp -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32". -lssp_nonshared, -lssp, and -lmoldname is redundant, I've already opened PR to ask for removing them, see [2], [3] and [4]. Rust uses "-lmsvcrt -lmingwex -lmingw32 -lgcc -lmsvcrt -lmingwex -luser32 -lkernel32". This worked before, but failed when we tried to enable `-fstack-protector-strong` to compile mingw-w64-crt itself. I think the best choice is to use "-Wl,--start-group" and "-Wl,--end-group", but I'm not sure whether it fits for different compilers, and whether it will causes compatiablity issues regarding different ld. Plus, which libraries should be put inside a group is also a problem. If in some case we can't use archive group, then what would be the best linking order? It would also be better if this could be documented somewhere, so downstream compiler maintainers can just use this. [1]: https://github.com/msys2/MINGW-packages/pull/31309#issuecomment-5489549886 [2]: https://github.com/llvm/llvm-project/pull/219932 [3]: https://github.com/llvm/llvm-project/pull/219936 [4]: https://github.com/llvm/llvm-project/pull/219949 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
