Skip to content

Commit c3dc7ee

Browse files
committed
[llvm][ReadTAPI] Add & fix rpath comparison checks
* Check and emit out differences in rpath inputs * Prevent rpaths from being overwritten * Capture file path for tbd-v5 (cherry picked from commit 1a0d699)
1 parent 517567f commit c3dc7ee

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

llvm/lib/TextAPI/InterfaceFile.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ void InterfaceFile::addParentUmbrella(const Target &Target_, StringRef Parent) {
4848
}
4949

5050
void InterfaceFile::addRPath(const Target &InputTarget, StringRef RPath) {
51-
auto Iter = lower_bound(RPaths, InputTarget,
52-
[](const std::pair<Target, std::string> &LHS,
53-
Target RHS) { return LHS.first < RHS; });
51+
using RPathEntryT = const std::pair<Target, std::string>;
52+
RPathEntryT Entry(InputTarget, RPath);
53+
auto Iter =
54+
lower_bound(RPaths, Entry,
55+
[](RPathEntryT &LHS, RPathEntryT &RHS) { return LHS < RHS; });
5456

55-
if ((Iter != RPaths.end()) && !(InputTarget < Iter->first)) {
56-
Iter->second = std::string(RPath);
57+
if ((Iter != RPaths.end()) && (*Iter == Entry))
5758
return;
58-
}
5959

60-
RPaths.emplace(Iter, InputTarget, std::string(RPath));
60+
RPaths.emplace(Iter, Entry);
6161
}
6262

6363
void InterfaceFile::addTarget(const Target &Target) {

llvm/lib/TextAPI/TextStub.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ TextAPIReader::get(MemoryBufferRef InputBuffer) {
11191119
auto FileOrErr = getInterfaceFileFromJSON(InputBuffer.getBuffer());
11201120
if (!FileOrErr)
11211121
return FileOrErr.takeError();
1122+
1123+
(*FileOrErr)->setPath(Ctx.Path);
11221124
return std::move(*FileOrErr);
11231125
}
11241126
yaml::Input YAMLIn(InputBuffer.getBuffer(), &Ctx, DiagHandler, &Ctx);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
; RUN: not llvm-readtapi --compare %t/missing_rpath.tbd %t/rpaths.tbd 2>&1 | FileCheck %s
4+
5+
; CHECK: < {{.*}}missing_rpath.tbd
6+
; CHECK: > {{.*}}rpaths.tbd
7+
8+
; CHECK: Run Path Search Paths
9+
; CHECK-NEXT: x86_64-apple-macos13
10+
; CHECK-NEXT: > /usr/lib/swift
11+
; CHECK-NEXT: > @loader_path/../../../
12+
; CHECK-NEXT: arm64-apple-macos13
13+
; CHECK-NEXT: > /usr/lib/swift
14+
; CHECK-NEXT: > @loader_path/../../../
15+
16+
//--- missing_rpath.tbd
17+
{"main_library":{"exported_symbols":[{"text":{"global":["_foo"]}}],"flags":[{"attributes":["not_app_extension_safe"]}],"install_names":[{"name":"@rpath/libFake.dylib"}],"target_info":[{"min_deployment":"13","target":"x86_64-macos"},{"min_deployment":"13","target":"arm64-macos"}]},"tapi_tbd_version":5}
18+
19+
//--- rpaths.tbd
20+
{"main_library":{"exported_symbols":[{"text":{"global":["_foo"]}}],"rpaths": [{"paths": [ "@loader_path/../../../", "/usr/lib/swift"]}], "flags":[{"attributes":["not_app_extension_safe"]}],"install_names":[{"name":"@rpath/libFake.dylib"}],"target_info":[{"min_deployment":"13","target":"x86_64-macos"},{"min_deployment":"13","target":"arm64-macos"}]},"tapi_tbd_version":5}

llvm/tools/llvm-readtapi/DiffEngine.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ DiffEngine::findDifferences(const InterfaceFile *IFLHS,
374374
IFRHS->reexportedLibraries(),
375375
"Reexported Libraries"));
376376

377+
if (IFLHS->rpaths() != IFRHS->rpaths())
378+
Output.push_back(recordDifferences(IFLHS->rpaths(), IFRHS->rpaths(),
379+
"Run Path Search Paths"));
380+
377381
if (IFLHS->allowableClients() != IFRHS->allowableClients())
378382
Output.push_back(recordDifferences(IFLHS->allowableClients(),
379383
IFRHS->allowableClients(),

0 commit comments

Comments
 (0)