[llvm] f8cc183 - Fix the dsymutil heuristic for excluding system interfaces. (#93745)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 30 12:23:24 PDT 2024
Author: Adrian Prantl
Date: 2024-05-30T12:23:20-07:00
New Revision: f8cc183ea244be6b8ea5e9da7733923e39c9fc38
URL: https://github.com/llvm/llvm-project/commit/f8cc183ea244be6b8ea5e9da7733923e39c9fc38
DIFF: https://github.com/llvm/llvm-project/commit/f8cc183ea244be6b8ea5e9da7733923e39c9fc38.diff
LOG: Fix the dsymutil heuristic for excluding system interfaces. (#93745)
The function was meant to find the Developer/ dir, but it found a
Developer directory nested deep inside the top-level Developer dir.
The new implementation rejects everything in Xcode.app/Developer in
broad strokes.
rdar://128571037
Added:
Modified:
llvm/include/llvm/DWARFLinker/Utils.h
llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/DWARFLinker/Utils.h b/llvm/include/llvm/DWARFLinker/Utils.h
index 23e59c967011a..8bc22a0eadf16 100644
--- a/llvm/include/llvm/DWARFLinker/Utils.h
+++ b/llvm/include/llvm/DWARFLinker/Utils.h
@@ -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) {
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
index 3149d9b1d6624..84bbdfb5c3947 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
@@ -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));
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
index 8c52040fdbc92..b50ea9ab49c1b 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp
@@ -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();
diff --git a/llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp b/llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp
index 0eb83d4b4fc9b..6439bf2cbc5f8 100644
--- a/llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp
+++ b/llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp
@@ -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
More information about the llvm-commits
mailing list