[PATCH] D79076: [clang] [MinGW] Add the compiler rt libdirs to the search path

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 02:39:08 PDT 2020


mstorsjo created this revision.
mstorsjo added reviewers: rnk, hans.
Herald added a project: clang.

This matches what is done for MSVC in b8000c0ce84541c5b5535419234fb65ce77d6756 <https://reviews.llvm.org/rGb8000c0ce84541c5b5535419234fb65ce77d6756>. Since that commit, compiler rt sanitizer libraries aren't linked to with absolute path on windows, but using their basenames, requiring the libdirs to be passed to the linker.

This fixes undefined behaviour sanitizer on MinGW after b8000c0ce84541c5b5535419234fb65ce77d6756 <https://reviews.llvm.org/rGb8000c0ce84541c5b5535419234fb65ce77d6756>.

Not sure what would be a good test for this, as the lib/clang/<version>/lib/windows directory doesn't exist, it won't show up in tests...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79076

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp


Index: clang/lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include <system_error>
 
 using namespace clang::diag;
@@ -198,6 +199,17 @@
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   TC.AddFilePathLibArgs(Args, CmdArgs);
+
+  // Add the compiler-rt library directories if they exist to help
+  // the linker find the various sanitizer, builtin, and profiling runtimes.
+  for (const auto &LibPath : TC.getLibraryPaths()) {
+    if (TC.getVFS().exists(LibPath))
+      CmdArgs.push_back(Args.MakeArgString("-L" + LibPath));
+  }
+  auto CRTPath = TC.getCompilerRTPath();
+  if (TC.getVFS().exists(CRTPath))
+    CmdArgs.push_back(Args.MakeArgString("-L" + CRTPath));
+
   AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
 
   // TODO: Add profile stuff here


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79076.260867.patch
Type: text/x-patch
Size: 1065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200429/9a151eba/attachment.bin>


More information about the cfe-commits mailing list