Skip to content

Commit c805b71

Browse files
authored
Merge pull request #9703 from cyndyishida/cishida/6.1/cherrypicks
tapi & clang cherrypicks
2 parents 2dcf631 + 762dc7d commit c805b71

File tree

12 files changed

+234
-24
lines changed

12 files changed

+234
-24
lines changed

clang/lib/InstallAPI/DirectoryScanner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ Error DirectoryScanner::scanHeaders(StringRef Path, Library &Lib,
130130
if (ParentPath.empty())
131131
ParentPath = Path;
132132
for (const StringRef Dir : SubDirectories)
133-
return scanHeaders(Dir, Lib, Type, BasePath, ParentPath);
133+
if (Error Err = scanHeaders(Dir, Lib, Type, BasePath, ParentPath))
134+
return Err;
134135

135136
return Error::success();
136137
}
@@ -276,7 +277,8 @@ llvm::Error DirectoryScanner::scanForFrameworks(StringRef Directory) {
276277
// Expect a certain directory structure and naming convention to find
277278
// frameworks.
278279
static const char *SubDirectories[] = {"System/Library/Frameworks/",
279-
"System/Library/PrivateFrameworks/"};
280+
"System/Library/PrivateFrameworks/",
281+
"System/Library/SubFrameworks"};
280282

281283
// Check if the directory is already a framework.
282284
if (isFramework(Directory)) {

clang/lib/Lex/InitHeaderSearch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(
346346
AddPath("/System/DriverKit/System/Library/Frameworks", System, true);
347347
} else {
348348
AddPath("/System/Library/Frameworks", System, true);
349+
AddPath("/System/Library/SubFrameworks", System, true);
349350
AddPath("/Library/Frameworks", System, true);
350351
}
351352
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// UNSUPPORTED: system-windows
2+
// Windows is unsupported because we use the Unix path separator `\`.
3+
4+
// Add default directories before running clang to check default
5+
// search paths.
6+
// RUN: rm -rf %t && mkdir -p %t
7+
// RUN: cp -R %S/Inputs/MacOSX15.1.sdk %t/
8+
// RUN: mkdir -p %t/MacOSX15.1.sdk/System/Library/Frameworks
9+
// RUN: mkdir -p %t/MacOSX15.1.sdk/System/Library/SubFrameworks
10+
// RUN: mkdir -p %t/MacOSX15.1.sdk/usr/include
11+
12+
// RUN: %clang %s -target arm64-apple-darwin13.0 -isysroot %t/MacOSX15.1.sdk -E -v 2>&1 | FileCheck %s
13+
14+
// CHECK: -isysroot [[PATH:[^ ]*/MacOSX15.1.sdk]]
15+
// CHECK: #include <...> search starts here:
16+
// CHECK: [[PATH]]/usr/include
17+
// CHECK: [[PATH]]/System/Library/Frameworks (framework directory)
18+
// CHECK: [[PATH]]/System/Library/SubFrameworks (framework directory)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
; RUN: mkdir -p %t/DstRoot/
4+
; RUN: cp -r %S/Inputs/LibFoo/* %t/DstRoot/
5+
6+
; RUN: clang-installapi \
7+
; RUN: -target arm64-apple-macos12 -install_name @rpath/libfoo.dylib \
8+
; RUN: -current_version 1 -compatibility_version 1 \
9+
; RUN: -I%t/DstRoot/usr/include -dynamiclib \
10+
; RUN: -exclude-public-header %t/DstRoot/usr/include/public.h \
11+
; RUN: %t/DstRoot -o %t/output.tbd 2>&1 | FileCheck %s --allow-empty \
12+
; RUN: --implicit-check-not=error --implicit-check-not=warning
13+
; RUN: llvm-readtapi --compare %t/output.tbd %t/expected.tbd
14+
15+
16+
;--- DstRoot/usr/include/extra/extra.h
17+
int extra(void);
18+
19+
;--- DstRoot/usr/include/extra/additional/additional.h
20+
int additional(void);
21+
22+
;--- DstRoot/usr/include/more/more.h
23+
int more(void);
24+
25+
;--- DstRoot/usr/include/another/another.h
26+
int another(void);
27+
28+
;--- expected.tbd
29+
{
30+
"main_library": {
31+
"exported_symbols": [
32+
{
33+
"text": {
34+
"global": [
35+
"_foo", "_additional", "_more",
36+
"_another", "_extra"
37+
]
38+
}
39+
}
40+
],
41+
"flags": [
42+
{
43+
"attributes": [
44+
"not_app_extension_safe"
45+
]
46+
}
47+
],
48+
"install_names": [
49+
{
50+
"name": "@rpath/libfoo.dylib"
51+
}
52+
],
53+
"target_info": [
54+
{
55+
"min_deployment": "12",
56+
"target": "arm64-macos"
57+
}
58+
]
59+
},
60+
"tapi_tbd_version": 5
61+
}

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ function(darwin_test_archs os valid_archs)
136136

137137
# The simple program will build for x86_64h on the simulator because it is
138138
# compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
139-
# a valid or useful architecture for the iOS simulator we should drop it.
139+
# a valid or useful architecture for the simulators. We should drop it.
140140
if(${os} MATCHES "^(iossim|tvossim|watchossim)$")
141141
list(REMOVE_ITEM archs "x86_64h")
142-
endif()
143-
144-
if(${os} MATCHES "iossim")
145-
message(STATUS "Disabling i386 slice for iossim")
146-
list(REMOVE_ITEM archs "i386")
142+
if ("i386" IN_LIST archs)
143+
list(REMOVE_ITEM archs "i386")
144+
message(STATUS "Disabling i386 slice for simulator")
145+
endif()
147146
endif()
148147

149148
if(${os} MATCHES "^ios$")

llvm/lib/TextAPI/InterfaceFile.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void InterfaceFile::addDocument(std::shared_ptr<InterfaceFile> &&Document) {
8787
const std::shared_ptr<InterfaceFile> &RHS) {
8888
return LHS->InstallName < RHS->InstallName;
8989
});
90+
assert((Pos == Documents.end() ||
91+
(*Pos)->InstallName != Document->InstallName) &&
92+
"Unexpected duplicate document added");
9093
Document->Parent = this;
9194
Documents.insert(Pos, Document);
9295
}
@@ -169,6 +172,7 @@ InterfaceFile::merge(const InterfaceFile *O) const {
169172

170173
IF->setTwoLevelNamespace(isTwoLevelNamespace());
171174
IF->setApplicationExtensionSafe(isApplicationExtensionSafe());
175+
IF->setOSLibNotForSharedCache(isOSLibNotForSharedCache());
172176

173177
for (const auto &It : umbrellas()) {
174178
if (!It.second.empty())
@@ -235,6 +239,8 @@ InterfaceFile::remove(Architecture Arch) const {
235239
return make_error<TextAPIError>(TextAPIErrorCode::NoSuchArchitecture);
236240
}
237241

242+
// FIXME: Figure out how to keep these attributes in sync when new ones are
243+
// added.
238244
std::unique_ptr<InterfaceFile> IF(new InterfaceFile());
239245
IF->setFileType(getFileType());
240246
IF->setPath(getPath());
@@ -245,6 +251,7 @@ InterfaceFile::remove(Architecture Arch) const {
245251
IF->setSwiftABIVersion(getSwiftABIVersion());
246252
IF->setTwoLevelNamespace(isTwoLevelNamespace());
247253
IF->setApplicationExtensionSafe(isApplicationExtensionSafe());
254+
IF->setOSLibNotForSharedCache(isOSLibNotForSharedCache());
248255
for (const auto &It : umbrellas())
249256
if (It.first.Arch != Arch)
250257
IF->addParentUmbrella(It.first, It.second);
@@ -313,6 +320,7 @@ InterfaceFile::extract(Architecture Arch) const {
313320
IF->setSwiftABIVersion(getSwiftABIVersion());
314321
IF->setTwoLevelNamespace(isTwoLevelNamespace());
315322
IF->setApplicationExtensionSafe(isApplicationExtensionSafe());
323+
IF->setOSLibNotForSharedCache(isOSLibNotForSharedCache());
316324
for (const auto &It : umbrellas())
317325
if (It.first.Arch == Arch)
318326
IF->addParentUmbrella(It.first, It.second);

llvm/lib/TextAPI/Utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ bool llvm::MachO::isPrivateLibrary(StringRef Path, bool IsSymLink) {
120120
if (Path.starts_with("/System/Library/PrivateFrameworks"))
121121
return true;
122122

123+
if (Path.starts_with("/System/Library/SubFrameworks"))
124+
return true;
125+
123126
// Everything in /usr/lib/swift (including sub-directories) are considered
124127
// public.
125128
if (Path.consume_front("/usr/lib/swift/"))
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
4+
; RUN: llvm-readtapi --compare %t/all_archs.tbd %t/missing_archs.tbd --ignore-arch armv7 --ignore-arch armv7s 2>&1 | FileCheck %s --allow-empty --implicit-check-not warning: --implicit-check-not error:
5+
; RUN: not llvm-readtapi --compare %t/all_archs.tbd %t/missing_archs.tbd --ignore-arch armv7s 2>&1 | FileCheck %s --check-prefix ARMV7
6+
7+
all_archs.tbd
8+
; ARMV7: < {{.*}}all_archs.tbd
9+
; ARMV7: > {{.*}}missing_archs.tbd
10+
11+
; ARMV7: Reexported Libraries
12+
; ARMV7-NEXT: armv7-apple-ios
13+
; ARMV7: Symbols
14+
; ARMV7-NEXT: armv7-apple-ios
15+
; ARMV7: Inlined Reexported Frameworks/Libraries
16+
; ARMV7-NEXT: /System/Library/Frameworks/FooCore.framework/FooCore
17+
; ARMV7: Symbols
18+
; ARMV7-NEXT: armv7-apple-ios
19+
20+
;--- all_archs.tbd
21+
--- !tapi-tbd
22+
tbd-version: 4
23+
targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
24+
install-name: '/System/Library/Frameworks/Foo.framework/Foo'
25+
current-version: 1986.34.9
26+
reexported-libraries:
27+
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
28+
libraries: [ '/System/Library/Frameworks/FooCore.framework/FooCore' ]
29+
exports:
30+
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
31+
symbols: [ _AllRequestsKeyPathFragment, _AnalyticsLoggingSubsystem, _AnyRequestKeyPathFragment,
32+
_bar_getBarPointSize_ints, _bar_newBarMessage, _bar_serialize ]
33+
- targets: [ arm64-ios, arm64e-ios ]
34+
symbols: [ __ZN3lingo11MapEdgeRoad6lengthEv,
35+
__ZTVN3lingo11MapEdgeRoadE, __ZTVN3lingo7MapNodeE, __ZTVN5bar19GeometryPathElementE ]
36+
--- !tapi-tbd
37+
tbd-version: 4
38+
targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
39+
install-name: '/System/Library/Frameworks/FooCore.framework/FooCore'
40+
current-version: 1986.34.9
41+
exports:
42+
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
43+
symbols: [ _sym, _workgroupsym, _taskgroup_sim, meta_sim ]
44+
...
45+
46+
;--- missing_archs.tbd
47+
--- !tapi-tbd
48+
tbd-version: 4
49+
targets: [ arm64-ios, arm64e-ios ]
50+
install-name: '/System/Library/Frameworks/Foo.framework/Foo'
51+
current-version: 1986.34.9
52+
reexported-libraries:
53+
- targets: [ arm64-ios, arm64e-ios ]
54+
libraries: [ '/System/Library/Frameworks/FooCore.framework/FooCore' ]
55+
exports:
56+
- targets: [ arm64-ios, arm64e-ios ]
57+
symbols: [ _AllRequestsKeyPathFragment, _AnalyticsLoggingSubsystem, _AnyRequestKeyPathFragment,
58+
_bar_getBarPointSize_ints, _bar_newBarMessage, _bar_serialize, __ZN3lingo11MapEdgeRoad6lengthEv,
59+
__ZTVN3lingo11MapEdgeRoadE, __ZTVN3lingo7MapNodeE, __ZTVN5bar19GeometryPathElementE ]
60+
--- !tapi-tbd
61+
tbd-version: 4
62+
targets: [ arm64-ios, arm64e-ios ]
63+
install-name: '/System/Library/Frameworks/FooCore.framework/FooCore'
64+
current-version: 1986.34.9
65+
exports:
66+
- targets: [ arm64-ios, arm64e-ios ]
67+
symbols: [ _sym, _workgroupsym, _taskgroup_sim, meta_sim ]
68+
...

llvm/test/tools/llvm-readtapi/stubify-delete.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
# Setup a mix of public and private libraries that resemble apple sdk.
33
; RUN: mkdir -p %t/sysroot/usr/local/lib/ %t/sysroot/usr/lib/
44
; RUN: mkdir -p %t/sysroot/System/Library/Frameworks/System.framework %t/sysroot/System/Library/PrivateFrameworks/Fat.framework
5+
; RUN: mkdir -p %t/sysroot/System/Library/SubFrameworks/Fat.framework/Headers
56
; RUN: yaml2obj %S/Inputs/libSystem.1.yaml -o %t/sysroot/System/Library/Frameworks/System.framework/System
67
; RUN: yaml2obj %S/Inputs/objc.yaml -o %t/sysroot/usr/lib/libobjc.dylib
78
; RUN: cp %t/sysroot/usr/lib/libobjc.dylib %t/sysroot/usr/local/lib/libobjc-unstable.dylib
89
; RUN: yaml2obj %S/Inputs/universal.yaml -o %t/sysroot/System/Library/PrivateFrameworks/Fat.framework/Fat
10+
; RUN: cp %t/sysroot/System/Library/PrivateFrameworks/Fat.framework/Fat %t/sysroot/System/Library/SubFrameworks/Fat.framework/Fat
11+
; RUN: touch %t/sysroot/System/Library/SubFrameworks/Fat.framework/Headers/Fat.h
912
; RUN: llvm-readtapi -stubify %t/sysroot --delete-input --delete-private-libraries 2>&1 | FileCheck %s --allow-empty --implicit-check-not warning: --implicit-check-not error:
1013
# Validate expected files are removed.
1114
; RUN: not test -f %t/sysroot/System/Library/PrivateFrameworks
1215
; RUN: not test -f %t/sysroot/usr/local
1316
; RUN: not test -f %t/sysroot/usr/lib/libobjc.dylib
1417
; RUN: not test -f %t/sysroot/System/Library/Frameworks/System.framework/System
18+
; RUN: not test -f %t/sysroot/System/Library/SubFrameworks/Fat.framework/Fat
1519
; RUN: test -f %t/sysroot/System/Library/Frameworks/System.framework/System.tbd
1620
; RUN: test -f %t/sysroot/usr/lib/libobjc.tbd
17-
18-
21+
; RUN: test -f %t/sysroot/System/Library/SubFrameworks/Fat.framework/Headers/Fat.h

llvm/tools/llvm-readtapi/TapiOpts.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ def delete_input : FF<"delete-input", "delete and replace input file on success"
3535
def delete_private_libraries : FF<"delete-private-libraries", "delete private system dynamic libraries and frameworks">;
3636
def t: FF<"t", "logs each library loaded, useful for debugging problems with search paths where the wrong library is loaded">;
3737

38+
39+
//
40+
// Compare options
41+
//
42+
defm ignore_arch : JS<"ignore-arch", "<architecture> slice to ignore for comparison", "<architecture>">;

llvm/tools/llvm-readtapi/llvm-readtapi.cpp

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ struct StubOptions {
7171
bool TraceLibs = false;
7272
};
7373

74+
struct CompareOptions {
75+
ArchitectureSet ArchsToIgnore;
76+
};
77+
7478
struct Context {
7579
std::vector<std::string> Inputs;
7680
StubOptions StubOpt;
81+
CompareOptions CmpOpt;
7782
std::unique_ptr<llvm::raw_fd_stream> OutStream;
7883
FileType WriteFT = FileType::TBD_V5;
7984
bool Compact = false;
@@ -160,6 +165,28 @@ static bool handleCompareAction(const Context &Ctx) {
160165
auto LeftIF = getInterfaceFile(Ctx.Inputs.front());
161166
auto RightIF = getInterfaceFile(Ctx.Inputs.at(1));
162167

168+
// Remove all architectures to ignore before running comparison.
169+
auto removeArchFromIF = [](auto &IF, const ArchitectureSet &ArchSet,
170+
const Architecture ArchToRemove) {
171+
if (!ArchSet.has(ArchToRemove))
172+
return;
173+
if (ArchSet.count() == 1)
174+
return;
175+
auto OutIF = IF->remove(ArchToRemove);
176+
if (!OutIF)
177+
ExitOnErr(OutIF.takeError());
178+
IF = std::move(*OutIF);
179+
};
180+
181+
if (!Ctx.CmpOpt.ArchsToIgnore.empty()) {
182+
const ArchitectureSet LeftArchs = LeftIF->getArchitectures();
183+
const ArchitectureSet RightArchs = RightIF->getArchitectures();
184+
for (const auto Arch : Ctx.CmpOpt.ArchsToIgnore) {
185+
removeArchFromIF(LeftIF, LeftArchs, Arch);
186+
removeArchFromIF(RightIF, RightArchs, Arch);
187+
}
188+
}
189+
163190
raw_ostream &OS = Ctx.OutStream ? *Ctx.OutStream : outs();
164191
return DiffEngine(LeftIF.get(), RightIF.get()).compareFiles(OS);
165192
}
@@ -228,16 +255,21 @@ static void stubifyDirectory(const StringRef InputPath, Context &Ctx) {
228255
if (EC)
229256
reportError(IT->path() + ": " + EC.message());
230257

231-
// Skip header directories (include/Headers/PrivateHeaders) and module
232-
// files.
258+
// Skip header directories (include/Headers/PrivateHeaders).
233259
StringRef Path = IT->path();
234-
if (Path.ends_with("/include") || Path.ends_with("/Headers") ||
235-
Path.ends_with("/PrivateHeaders") || Path.ends_with("/Modules") ||
236-
Path.ends_with(".map") || Path.ends_with(".modulemap")) {
237-
IT.no_push();
238-
continue;
260+
if (sys::fs::is_directory(Path)) {
261+
const StringRef Stem = sys::path::stem(Path);
262+
if ((Stem == "include") || (Stem == "Headers") ||
263+
(Stem == "PrivateHeaders") || (Stem == "Modules")) {
264+
IT.no_push();
265+
continue;
266+
}
239267
}
240268

269+
// Skip module files too.
270+
if (Path.ends_with(".map") || Path.ends_with(".modulemap"))
271+
continue;
272+
241273
// Check if the entry is a symlink. We don't follow symlinks but we record
242274
// their content.
243275
bool IsSymLink;
@@ -497,12 +529,20 @@ int main(int Argc, char **Argv) {
497529
reportError("unsupported filetype '" + FT + "'");
498530
}
499531

500-
if (opt::Arg *A = Args.getLastArg(OPT_arch_EQ)) {
501-
StringRef Arch = A->getValue();
502-
Ctx.Arch = getArchitectureFromName(Arch);
503-
if (Ctx.Arch == AK_unknown)
504-
reportError("unsupported architecture '" + Arch);
505-
}
532+
auto SanitizeArch = [&](opt::Arg *A) {
533+
StringRef ArchStr = A->getValue();
534+
auto Arch = getArchitectureFromName(ArchStr);
535+
if (Arch == AK_unknown)
536+
reportError("unsupported architecture '" + ArchStr);
537+
return Arch;
538+
};
539+
540+
if (opt::Arg *A = Args.getLastArg(OPT_arch_EQ))
541+
Ctx.Arch = SanitizeArch(A);
542+
543+
for (opt::Arg *A : Args.filtered(OPT_ignore_arch_EQ))
544+
Ctx.CmpOpt.ArchsToIgnore.set(SanitizeArch(A));
545+
506546
// Handle top level and exclusive operation.
507547
SmallVector<opt::Arg *, 1> ActionArgs(Args.filtered(OPT_action_group));
508548

0 commit comments

Comments
 (0)