[clang] [clang][Darwin] Prefer the toolchain-provided libc++.dylib if there is one (PR #170303)

Ian Anderson via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 3 13:06:06 PST 2025


================
@@ -2846,11 +2846,49 @@ void AppleMachO::AddCXXStdlibLibArgs(const ArgList &Args,
   CXXStdlibType Type = GetCXXStdlibType(Args);
 
   switch (Type) {
-  case ToolChain::CST_Libcxx:
-    CmdArgs.push_back("-lc++");
+  case ToolChain::CST_Libcxx: {
+    // On Darwin, we prioritize a libc++ located in the toolchain to a libc++
+    // located in the sysroot. Unlike the driver for most other platforms, on
+    // Darwin we do that by explicitly passing the library path to the linker
+    // to avoid having to add the toolchain's `lib/` directory to the linker
+    // search path, which would make other libraries findable as well.
+    //
+    // Prefering the toolchain library over the sysroot library matches the
+    // behavior we have for headers, where we prefer headers in the toolchain
+    // over headers in the sysroot if there are any. Note that it's important
----------------
ian-twilightcoder wrote:

Is this strictly true? I don't think we ever add <toolchain>/usr/include/c++/v1 or <toolchain>/usr/lib/clang/nn/include/c++/v1

https://github.com/llvm/llvm-project/pull/170303


More information about the cfe-commits mailing list