Skip to content

Commit 7dd2534

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 7dd2534

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

llvm/include/llvm/DWARFLinker/Utils.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,30 @@ 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+
if (!SysRoot.ends_with(".sdk"))
45+
return {};
4446
StringRef Base = sys::path::parent_path(SysRoot);
4547
if (sys::path::filename(Base) != "SDKs")
46-
return Result;
48+
return {};
4749
Base = sys::path::parent_path(Base);
48-
Result = Base;
49-
Result += "/Toolchains";
50-
return Result;
50+
if (sys::path::filename(Base) != "Developer")
51+
return {};
52+
if (sys::path::filename(sys::path::parent_path(Base)) == "Contents")
53+
return Base;
54+
Base = sys::path::parent_path(Base);
55+
if (!Base.ends_with(".platform"))
56+
return {};
57+
Base = sys::path::parent_path(Base);
58+
if (sys::path::filename(Base) != "Platforms")
59+
return {};
60+
Base = sys::path::parent_path(Base);
61+
if (sys::path::filename(Base) != "Developer")
62+
return {};
63+
return Base;
5164
}
5265

5366
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,24 @@
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(
22+
DEVELOPER_DIR
23+
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk"),
24+
DEVELOPER_DIR);
25+
EXPECT_EQ(guessDeveloperDir(DEVELOPER_DIR "/SDKs/MacOSX.sdk"), DEVELOPER_DIR);
26+
}
27+
28+
} // anonymous namespace

0 commit comments

Comments
 (0)