Skip to content

[dsymutil] Also detect external downloadable toolchains #93872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion llvm/include/llvm/DWARFLinker/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ inline Error finiteLoop(function_ref<Expected<bool>()> Iteration,
/// Make a best effort to guess the
/// Xcode.app/Contents/Developer path from an SDK path.
inline StringRef guessDeveloperDir(StringRef SysRoot) {
SmallString<128> Result;
// Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
auto it = sys::path::rbegin(SysRoot);
auto end = sys::path::rend(SysRoot);
Expand Down Expand Up @@ -74,6 +73,28 @@ inline StringRef guessDeveloperDir(StringRef SysRoot) {
return {};
}

/// Make a best effort to determine whether Path is inside a toolchain.
inline bool isInToolchainDir(StringRef Path) {
// Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-15-a.xctoolchain/usr/lib/swift/macosx/_StringProcessing.swiftmodule/arm64-apple-macos.private.swiftinterface
for (auto it = sys::path::rbegin(Path), end = sys::path::rend(Path);
it != end; ++it) {
if (it->ends_with(".xctoolchain")) {
++it;
if (it == end)
return false;
if (*it != "Toolchains")
return false;
++it;
if (it == end)
return false;
if (*it != "Developer")
return false;
return true;
}
}
return false;
}

inline bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
// Debug info can contain paths from any OS, not necessarily
// an OS we're currently running on. Moreover different compilation units can
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ static void analyzeImportedModule(
StringRef DeveloperDir = guessDeveloperDir(SysRoot);
if (!DeveloperDir.empty() && Path.starts_with(DeveloperDir))
return;
if (isInToolchainDir(Path))
return;
std::optional<const char *> Name =
dwarf::toString(DIE.find(dwarf::DW_AT_name));
if (!Name)
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ void CompileUnit::analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry) {
StringRef DeveloperDir = guessDeveloperDir(SysRoot);
if (!DeveloperDir.empty() && Path.starts_with(DeveloperDir))
return;
if (isInToolchainDir(Path))
return;
if (std::optional<DWARFFormValue> Val = find(DieEntry, dwarf::DW_AT_name)) {
Expected<const char *> Name = Val->getAsCString();
if (!Name) {
Expand Down
6 changes: 6 additions & 0 deletions llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ TEST(DWARFLinker, PathTest) {
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk"),
DEVELOPER_DIR);
EXPECT_EQ(guessDeveloperDir(DEVELOPER_DIR "/SDKs/MacOSX.sdk"), DEVELOPER_DIR);
EXPECT_TRUE(
isInToolchainDir("/Library/Developer/Toolchains/"
"swift-DEVELOPMENT-SNAPSHOT-2024-05-15-a.xctoolchain/"
"usr/lib/swift/macosx/_StringProcessing.swiftmodule/"
"arm64-apple-macos.private.swiftinterface"));
EXPECT_FALSE(isInToolchainDir("/Foo/not-an.xctoolchain/Bar/Baz"));
}

} // anonymous namespace
Loading