[llvm] 1a0d699 - [llvm][ReadTAPI] Add & fix rpath comparison checks
Cyndy Ishida via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 07:45:09 PDT 2023
Author: Cyndy Ishida
Date: 2023-08-30T07:42:52-07:00
New Revision: 1a0d6992aeeaff7a70adfa5079fc9c64ef156b48
URL: https://github.com/llvm/llvm-project/commit/1a0d6992aeeaff7a70adfa5079fc9c64ef156b48
DIFF: https://github.com/llvm/llvm-project/commit/1a0d6992aeeaff7a70adfa5079fc9c64ef156b48.diff
LOG: [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
Added:
llvm/test/tools/llvm-readtapi/compare-rpaths.test
Modified:
llvm/lib/TextAPI/InterfaceFile.cpp
llvm/lib/TextAPI/TextStub.cpp
llvm/tools/llvm-readtapi/DiffEngine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TextAPI/InterfaceFile.cpp b/llvm/lib/TextAPI/InterfaceFile.cpp
index d324e30f32863d..f1c6add67b97b9 100644
--- a/llvm/lib/TextAPI/InterfaceFile.cpp
+++ b/llvm/lib/TextAPI/InterfaceFile.cpp
@@ -48,16 +48,16 @@ void InterfaceFile::addParentUmbrella(const Target &Target_, StringRef Parent) {
}
void InterfaceFile::addRPath(const Target &InputTarget, StringRef RPath) {
- auto Iter = lower_bound(RPaths, InputTarget,
- [](const std::pair<Target, std::string> &LHS,
- Target RHS) { return LHS.first < RHS; });
+ using RPathEntryT = const std::pair<Target, std::string>;
+ RPathEntryT Entry(InputTarget, RPath);
+ auto Iter =
+ lower_bound(RPaths, Entry,
+ [](RPathEntryT &LHS, RPathEntryT &RHS) { return LHS < RHS; });
- if ((Iter != RPaths.end()) && !(InputTarget < Iter->first)) {
- Iter->second = std::string(RPath);
+ if ((Iter != RPaths.end()) && (*Iter == Entry))
return;
- }
- RPaths.emplace(Iter, InputTarget, std::string(RPath));
+ RPaths.emplace(Iter, Entry);
}
void InterfaceFile::addTarget(const Target &Target) {
diff --git a/llvm/lib/TextAPI/TextStub.cpp b/llvm/lib/TextAPI/TextStub.cpp
index e6dc0a4f79aca6..b9b6061101c6b8 100644
--- a/llvm/lib/TextAPI/TextStub.cpp
+++ b/llvm/lib/TextAPI/TextStub.cpp
@@ -1119,6 +1119,8 @@ TextAPIReader::get(MemoryBufferRef InputBuffer) {
auto FileOrErr = getInterfaceFileFromJSON(InputBuffer.getBuffer());
if (!FileOrErr)
return FileOrErr.takeError();
+
+ (*FileOrErr)->setPath(Ctx.Path);
return std::move(*FileOrErr);
}
yaml::Input YAMLIn(InputBuffer.getBuffer(), &Ctx, DiagHandler, &Ctx);
diff --git a/llvm/test/tools/llvm-readtapi/compare-rpaths.test b/llvm/test/tools/llvm-readtapi/compare-rpaths.test
new file mode 100644
index 00000000000000..92134cd97e89e7
--- /dev/null
+++ b/llvm/test/tools/llvm-readtapi/compare-rpaths.test
@@ -0,0 +1,20 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: not llvm-readtapi --compare %t/missing_rpath.tbd %t/rpaths.tbd 2>&1 | FileCheck %s
+
+; CHECK: < {{.*}}missing_rpath.tbd
+; CHECK: > {{.*}}rpaths.tbd
+
+; CHECK: Run Path Search Paths
+; CHECK-NEXT: x86_64-apple-macos13
+; CHECK-NEXT: > /usr/lib/swift
+; CHECK-NEXT: > @loader_path/../../../
+; CHECK-NEXT: arm64-apple-macos13
+; CHECK-NEXT: > /usr/lib/swift
+; CHECK-NEXT: > @loader_path/../../../
+
+//--- missing_rpath.tbd
+{"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}
+
+//--- rpaths.tbd
+{"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}
diff --git a/llvm/tools/llvm-readtapi/DiffEngine.cpp b/llvm/tools/llvm-readtapi/DiffEngine.cpp
index c10e74725a92d7..11d0eba563c32f 100644
--- a/llvm/tools/llvm-readtapi/DiffEngine.cpp
+++ b/llvm/tools/llvm-readtapi/DiffEngine.cpp
@@ -375,6 +375,10 @@ DiffEngine::findDifferences(const InterfaceFile *IFLHS,
IFRHS->reexportedLibraries(),
"Reexported Libraries"));
+ if (IFLHS->rpaths() != IFRHS->rpaths())
+ Output.push_back(recordDifferences(IFLHS->rpaths(), IFRHS->rpaths(),
+ "Run Path Search Paths"));
+
if (IFLHS->allowableClients() != IFRHS->allowableClients())
Output.push_back(recordDifferences(IFLHS->allowableClients(),
IFRHS->allowableClients(),
More information about the llvm-commits
mailing list