[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

Fahad Nayyar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 13 13:06:29 PDT 2023


fahadnayyar created this revision.
Herald added a project: All.
fahadnayyar requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

When libc++ is bootstrapped with clang using the cmake options
-DLLVM_ENABLE_PROJECTS="clang;llvm;lldb" and 
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" then the resulting clang uses 
the just-built libcxx headers from <build-directory>/bin/../include/c++/v1 
. So the clang in this case should also use the just-built libc++.dylib 
from <build-directory>/bin/../lib instead of using the system's libc++ 
libraries.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148266

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


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -410,6 +410,21 @@
   Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
   Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
 
+  // Including the path to the just-built libc++.dylib if libc++ is bootstrapped
+  // and <install>/bin/../lib/libc++.dylib is a valid path
+
+  llvm::SmallString<128> LibCXXDylibDirPath =
+      llvm::StringRef(D.getInstalledDir()); // <install>/bin
+  llvm::sys::path::append(LibCXXDylibDirPath, "..", "lib");
+
+  llvm::SmallString<128> LibCXXDylibPath = LibCXXDylibDirPath;
+  llvm::sys::path::append(LibCXXDylibPath, "..", "lib", "libc++.dylib");
+
+  if (D.getVFS().exists(LibCXXDylibPath)) {
+    CmdArgs.push_back("-L");
+    CmdArgs.push_back(C.getArgs().MakeArgString(LibCXXDylibDirPath));
+  }
+
   // Give --sysroot= preference, over the Apple specific behavior to also use
   // --isysroot as the syslibroot.
   StringRef sysroot = C.getSysRoot();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148266.513331.patch
Type: text/x-patch
Size: 1099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230413/4cb4b0fd/attachment-0001.bin>


More information about the cfe-commits mailing list