aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorSteven Wu <stevenwu@apple.com>2022-07-20 16:45:09 -0700
committerSteven Wu <stevenwu@apple.com>2022-07-20 16:45:52 -0700
commitd0728260577d66b4b4d922adf0a40de86f09ccf5 (patch)
treedfa3e3616216b65e16726979df30138289505bc2 /clang/lib
parent4fbd1d6c872e8228f23a6e13914222af40ca6461 (diff)
downloadllvm-d0728260577d66b4b4d922adf0a40de86f09ccf5.zip
llvm-d0728260577d66b4b4d922adf0a40de86f09ccf5.tar.gz
llvm-d0728260577d66b4b4d922adf0a40de86f09ccf5.tar.bz2
[Darwin toolchain] Tune the logic for finding arclite.
The heuristic used to determine where the arclite libraries are to be found was based on the path of the `clang` executable. However, in some scenarios the `clang` executable is within a toolchain that does not have arclite. When this happens, derive the arclite paths from the sysroot option. This allows Clang to correctly derive the arclite directory in, e.g., Swift CI, using similar logic to what the Swift driver has been doing for several years. Patched by Doug Gregor. Reviewed By: keith Differential Revision: https://reviews.llvm.org/D130205
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/ToolChains/Darwin.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 71b0c5b..bada811 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1141,25 +1141,38 @@ void DarwinClang::AddLinkARCArgs(const ArgList &Args,
SmallString<128> P(getDriver().ClangExecutable);
llvm::sys::path::remove_filename(P); // 'clang'
llvm::sys::path::remove_filename(P); // 'bin'
+ llvm::sys::path::append(P, "lib", "arc");
// 'libarclite' usually lives in the same toolchain as 'clang'. However, the
// Swift open source toolchains for macOS distribute Clang without libarclite.
// In that case, to allow the linker to find 'libarclite', we point to the
// 'libarclite' in the XcodeDefault toolchain instead.
- if (getXcodeDeveloperPath(P).empty()) {
- if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
+ if (!getVFS().exists(P)) {
+ auto updatePath = [&](const Arg *A) {
// Try to infer the path to 'libarclite' in the toolchain from the
// specified SDK path.
StringRef XcodePathForSDK = getXcodeDeveloperPath(A->getValue());
- if (!XcodePathForSDK.empty()) {
- P = XcodePathForSDK;
- llvm::sys::path::append(P, "Toolchains/XcodeDefault.xctoolchain/usr");
- }
+ if (XcodePathForSDK.empty())
+ return false;
+
+ P = XcodePathForSDK;
+ llvm::sys::path::append(P, "Toolchains/XcodeDefault.xctoolchain/usr",
+ "lib", "arc");
+ return getVFS().exists(P);
+ };
+
+ bool updated = false;
+ if (const Arg *A = Args.getLastArg(options::OPT_isysroot))
+ updated = updatePath(A);
+
+ if (!updated) {
+ if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
+ updatePath(A);
}
}
CmdArgs.push_back("-force_load");
- llvm::sys::path::append(P, "lib", "arc", "libarclite_");
+ llvm::sys::path::append(P, "libarclite_");
// Mash in the platform.
if (isTargetWatchOSSimulator())
P += "watchsimulator";