Skip to content

Commit de49554

Browse files
committed
Fix the dsymutil heuristic for excluding system interfaces.
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
1 parent 66b9785 commit de49554

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

llvm/include/llvm/DWARFLinker/Utils.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,41 @@ inline Error finiteLoop(function_ref<Expected<bool>()> Iteration,
3737
}
3838

3939
/// Make a best effort to guess the
40-
/// Xcode.app/Contents/Developer/Toolchains/ path from an SDK path.
41-
inline SmallString<128> guessToolchainBaseDir(StringRef SysRoot) {
40+
/// Xcode.app/Contents/Developer path from an SDK path.
41+
inline StringRef guessDeveloperDir(StringRef SysRoot) {
4242
SmallString<128> Result;
4343
// Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
44-
StringRef Base = sys::path::parent_path(SysRoot);
45-
if (sys::path::filename(Base) != "SDKs")
46-
return Result;
47-
Base = sys::path::parent_path(Base);
48-
Result = Base;
49-
Result += "/Toolchains";
50-
return Result;
44+
auto it = sys::path::rbegin(SysRoot);
45+
auto end = sys::path::rend(SysRoot);
46+
if (it == end || !it->ends_with(".sdk"))
47+
return {};
48+
++it;
49+
// Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
50+
if (it == end || *it != "SDKs")
51+
return {};
52+
auto developerEnd = it;
53+
++it;
54+
while (it != end) {
55+
// Contents/Developer/Platforms/MacOSX.platform/Developer
56+
if (*it != "Developer")
57+
return {};
58+
++it;
59+
if (it == end)
60+
return {};
61+
if (*it == "Contents")
62+
return StringRef(SysRoot.data(),
63+
developerEnd - sys::path::rend(SysRoot) - 1);
64+
// Contents/Developer/Platforms/MacOSX.platform
65+
if (!it->ends_with(".platform"))
66+
return {};
67+
++it;
68+
// Contents/Developer/Platforms
69+
if (it == end || *it != "Platforms")
70+
return {};
71+
developerEnd = it;
72+
++it;
73+
}
74+
return {};
5175
}
5276

5377
inline bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {

llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ static void analyzeImportedModule(
201201
return;
202202
// Don't track interfaces that are part of the toolchain.
203203
// For example: Swift, _Concurrency, ...
204-
SmallString<128> Toolchain = guessToolchainBaseDir(SysRoot);
205-
if (!Toolchain.empty() && Path.starts_with(Toolchain))
204+
StringRef DeveloperDir = guessDeveloperDir(SysRoot);
205+
if (!DeveloperDir.empty() && Path.starts_with(DeveloperDir))
206206
return;
207207
std::optional<const char *> Name =
208208
dwarf::toString(DIE.find(dwarf::DW_AT_name));

llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ void CompileUnit::analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry) {
270270
return;
271271
// Don't track interfaces that are part of the toolchain.
272272
// For example: Swift, _Concurrency, ...
273-
SmallString<128> Toolchain = guessToolchainBaseDir(SysRoot);
274-
if (!Toolchain.empty() && Path.starts_with(Toolchain))
273+
StringRef DeveloperDir = guessDeveloperDir(SysRoot);
274+
if (!DeveloperDir.empty() && Path.starts_with(DeveloperDir))
275275
return;
276276
if (std::optional<DWARFFormValue> Val = find(DieEntry, dwarf::DW_AT_name)) {
277277
Expected<const char *> Name = Val->getAsCString();

llvm/unittests/DWARFLinkerParallel/DWARFLinkerTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,25 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/DWARFLinker/Utils.h"
10+
#include "gtest/gtest.h"
11+
12+
using namespace llvm;
13+
using namespace dwarf_linker;
14+
15+
#define DEVELOPER_DIR "/Applications/Xcode.app/Contents/Developer"
16+
17+
namespace {
18+
19+
TEST(DWARFLinker, PathTest) {
20+
EXPECT_EQ(guessDeveloperDir("/Foo"), "");
21+
EXPECT_EQ(guessDeveloperDir("Foo.sdk"), "");
22+
EXPECT_EQ(guessDeveloperDir(
23+
DEVELOPER_DIR
24+
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk"),
25+
DEVELOPER_DIR);
26+
EXPECT_EQ(guessDeveloperDir(DEVELOPER_DIR "/SDKs/MacOSX.sdk"), DEVELOPER_DIR);
27+
}
28+
29+
} // anonymous namespace

0 commit comments

Comments
 (0)