Author: Martin Storsjö Date: 2020-06-17T09:37:07+03:00 New Revision: beeed368b60252178f66ab117d8a96ecdc35f60e
URL: https://github.com/llvm/llvm-project/commit/beeed368b60252178f66ab117d8a96ecdc35f60e DIFF: https://github.com/llvm/llvm-project/commit/beeed368b60252178f66ab117d8a96ecdc35f60e.diff LOG: [clang] [MinGW] Link kernel32 once after the last instance of msvcrt The msvcrt library isn't a pure import library; it does contain regular object files with wrappers/fallbacks, and these can require linking against kernel32. This only makes a difference when linking with ld.bfd, as lld always searches all static libraries. This matches a similar change made recently in gcc in https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=850533ab160ef40eccfd039e1e3b138cf26e76b8, although clang adds --start-group --end-group around these libraries if -static is specified, which gcc doesn't. But try to match gcc's linking order in any case, for consistency. Differential Revision: https://reviews.llvm.org/D80880 Added: Modified: clang/lib/Driver/ToolChains/MinGW.cpp clang/test/Driver/mingw-msvcrt.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index ce01c8816263..3c2ba40323d9 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -304,10 +304,13 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lkernel32"); } - if (Args.hasArg(options::OPT_static)) + if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("--end-group"); - else + } else { AddLibGCC(Args, CmdArgs); + if (!HasWindowsApp) + CmdArgs.push_back("-lkernel32"); + } } if (!Args.hasArg(options::OPT_nostartfiles)) { diff --git a/clang/test/Driver/mingw-msvcrt.c b/clang/test/Driver/mingw-msvcrt.c index 89a8d2a94c28..bb4813ca33a5 100644 --- a/clang/test/Driver/mingw-msvcrt.c +++ b/clang/test/Driver/mingw-msvcrt.c @@ -4,6 +4,7 @@ // RUN: %clang -v -target i686-pc-windows-gnu -lucrt -### %s 2>&1 | FileCheck -check-prefix=CHECK_UCRT %s // CHECK_DEFAULT: "-lmingwex" "-lmsvcrt" "-ladvapi32" +// CHECK_DEFAULT-SAME: "-lmsvcrt" "-lkernel32" "{{.*}}crtend.o" // CHECK_MSVCR120: "-lmsvcr120" // CHECK_MSVCR120-SAME: "-lmingwex" "-ladvapi32" // CHECK_UCRTBASE: "-lucrtbase" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits