[PATCH] D80880: [clang] [MinGW] Link kernel32 once after the last instance of msvcrt

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 1 06:23:35 PDT 2020


mstorsjo added a comment.

In D80880#2066130 <https://reviews.llvm.org/D80880#2066130>, @mati865 wrote:

> I don't know why `AddLibGCC` has to be called twice but that doesn't really matter for this diff.


>From the clang perspective, I guess it's to match GCC. Originally, I guess the reason is that there's some nontrivial dependencies among all the default linked libraries - for G++ with `-pthread`, this is what gcc links: `-lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt`.

As there's functions in libmingwex which maybe used by libpthread - and we also occasionally move functions from libmingwex to libmsvcrt (for functions that aren't needed when on ucrt), and such functions may require both libgcc and libkernel32, it's all pretty fragile - a more robust solution would be to just add `--start-group` and `--end-group` around it (which would end up matching what lld always does anyway), but I'm not sure how receptive GCC would be to that. (Clang does add `--start-group` though, but only when linking with `-static`.)

As the issue in https://github.com/msys2/MINGW-packages/pull/6539 seems to end up resolved by using the "simpler" (linking wise) stdio functions in libwinpthread, lh_mouse also concluded that this added `-lkernel32` isn't really necessary in the end in that case, so if it ends up backed out from GCC I might skip pushing this one here as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80880/new/

https://reviews.llvm.org/D80880





More information about the cfe-commits mailing list