diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/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 /bin/../lib/libc++.dylib is a valid path + + llvm::SmallString<128> LibCXXDylibDirPath = + llvm::StringRef(D.getInstalledDir()); // /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();