Skip to content

Fix the dsymutil heuristic for excluding system interfaces. #93745

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
42 changes: 33 additions & 9 deletions llvm/include/llvm/DWARFLinker/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,41 @@ inline Error finiteLoop(function_ref<Expected<bool>()> Iteration,
}

/// Make a best effort to guess the
/// Xcode.app/Contents/Developer/Toolchains/ path from an SDK path.
inline SmallString<128> guessToolchainBaseDir(StringRef SysRoot) {
/// 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
StringRef Base = sys::path::parent_path(SysRoot);
if (sys::path::filename(Base) != "SDKs")
return Result;
Base = sys::path::parent_path(Base);
Result = Base;
Result += "/Toolchains";
return Result;
auto it = sys::path::rbegin(SysRoot);
auto end = sys::path::rend(SysRoot);
if (it == end || !it->ends_with(".sdk"))
return {};
++it;
// Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
if (it == end || *it != "SDKs")
return {};
auto developerEnd = it;
++it;
while (it != end) {
// Contents/Developer/Platforms/MacOSX.platform/Developer
if (*it != "Developer")
return {};
++it;
if (it == end)
return {};
if (*it == "Contents")
return StringRef(SysRoot.data(),
developerEnd - sys::path::rend(SysRoot) - 1);
// Contents/Developer/Platforms/MacOSX.platform
if (!it->ends_with(".platform"))
return {};
++it;
// Contents/Developer/Platforms
if (it == end || *it != "Platforms")
return {};
developerEnd = it;
++it;
}
return {};
}

inline bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ static void analyzeImportedModule(
return;
// Don't track interfaces that are part of the toolchain.
// For example: Swift, _Concurrency, ...
SmallString<128> Toolchain = guessToolchainBaseDir(SysRoot);
if (!Toolchain.empty() && Path.starts_with(Toolchain))
StringRef DeveloperDir = guessDeveloperDir(SysRoot);
if (!DeveloperDir.empty() && Path.starts_with(DeveloperDir))
return;
std::optional<const char *> Name =
dwarf::toString(DIE.find(dwarf::DW_AT_name));
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ void CompileUnit::analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry) {
return;
// Don't track interfaces that are part of the toolchain.
// For example: Swift, _Concurrency, ...
SmallString<128> Toolchain = guessToolchainBaseDir(SysRoot);
if (!Toolchain.empty() && Path.starts_with(Toolchain))
StringRef DeveloperDir = guessDeveloperDir(SysRoot);
if (!DeveloperDir.empty() && Path.starts_with(DeveloperDir))
return;
if (std::optional<DWARFFormValue> Val = find(DieEntry, dwarf::DW_AT_name)) {
Expected<const char *> Name = Val->getAsCString();
Expand Down
22 changes: 22 additions & 0 deletions llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,25 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "llvm/DWARFLinker/Utils.h"
#include "gtest/gtest.h"

using namespace llvm;
using namespace dwarf_linker;

#define DEVELOPER_DIR "/Applications/Xcode.app/Contents/Developer"

namespace {

TEST(DWARFLinker, PathTest) {
EXPECT_EQ(guessDeveloperDir("/Foo"), "");
EXPECT_EQ(guessDeveloperDir("Foo.sdk"), "");
EXPECT_EQ(guessDeveloperDir(
DEVELOPER_DIR
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk"),
DEVELOPER_DIR);
EXPECT_EQ(guessDeveloperDir(DEVELOPER_DIR "/SDKs/MacOSX.sdk"), DEVELOPER_DIR);
}

} // anonymous namespace
Loading