[llvm] 3b73139 - [TextAPI] Make min-os deployment version optional in tbd-v5.
Cyndy Ishida via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 11:27:26 PDT 2023
Author: Cyndy Ishida
Date: 2023-07-28T11:21:11-07:00
New Revision: 3b73139150be1f62e1f79c54a7d4bb46940ad50f
URL: https://github.com/llvm/llvm-project/commit/3b73139150be1f62e1f79c54a7d4bb46940ad50f
DIFF: https://github.com/llvm/llvm-project/commit/3b73139150be1f62e1f79c54a7d4bb46940ad50f.diff
LOG: [TextAPI] Make min-os deployment version optional in tbd-v5.
The minOS version is recorded in tbd-v5 so the linker can report
diagnostics when a library and client are misconfigured.
Dylibs should always have a minOS recorded, but in was not recorded in
previous TBD versions. To accommodate the format transition, treat
unrecorded minOS versions as 0.
Reviewed By: zixuw
Differential Revision: https://reviews.llvm.org/D156487
Added:
Modified:
llvm/lib/TextAPI/TextStubV5.cpp
llvm/unittests/TextAPI/TextStubV5Tests.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TextAPI/TextStubV5.cpp b/llvm/lib/TextAPI/TextStubV5.cpp
index 5b3d69b8d94abb..b74250cca6cb2a 100644
--- a/llvm/lib/TextAPI/TextStubV5.cpp
+++ b/llvm/lib/TextAPI/TextStubV5.cpp
@@ -27,7 +27,7 @@ All library level keys, accept target values and are defaulted if not specified.
"target_info": [ # Required: target information
{
"target": "x86_64-macos",
- "min_deployment": "10.14" # Required: minimum OS deployment version
+ "min_deployment": "10.14" # Optional: minOS defaults to 0
},
{
"target": "arm64-macos",
@@ -283,17 +283,16 @@ Expected<TargetList> getTargetsSection(const Object *Section) {
getRequiredValue<StringRef>(TBDKey::Target, Obj, &Object::getString);
if (!TargetStr)
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Target));
- auto VersionStr = getRequiredValue<StringRef>(TBDKey::Deployment, Obj,
- &Object::getString);
- if (!VersionStr)
- return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Deployment));
- VersionTuple Version;
- if (Version.tryParse(*VersionStr))
- return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Deployment));
auto TargetOrErr = Target::create(*TargetStr);
if (!TargetOrErr)
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Target));
+
+ auto VersionStr = Obj->getString(Keys[TBDKey::Deployment]);
+ VersionTuple Version;
+ if (VersionStr && Version.tryParse(*VersionStr))
+ return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Deployment));
TargetOrErr->MinDeployment = Version;
+
// Convert to LLVM::Triple to accurately compute minOS + platform + arch
// pairing.
IFTargets.push_back(
diff --git a/llvm/unittests/TextAPI/TextStubV5Tests.cpp b/llvm/unittests/TextAPI/TextStubV5Tests.cpp
index 1ccbfe2b1a27f6..d628ee8f43cbd3 100644
--- a/llvm/unittests/TextAPI/TextStubV5Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV5Tests.cpp
@@ -1104,6 +1104,53 @@ TEST(TBDv5, InvalidSymbols) {
EXPECT_EQ("invalid exported_symbols section\n", ErrorMessage);
}
+TEST(TBDv5, DefaultMinOS) {
+ static const char TBDv5File[] = R"({
+"tapi_tbd_version": 5,
+"main_library": {
+ "target_info": [
+ {
+ "target": "arm64-ios-simulator"
+ }
+ ],
+ "install_names":[
+ { "name":"/S/L/F/Foo.framework/Foo" }
+ ]
+}})";
+
+ Expected<TBDFile> Result =
+ TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
+ EXPECT_TRUE(!!Result);
+ TBDFile File = std::move(Result.get());
+ EXPECT_EQ(FileType::TBD_V5, File->getFileType());
+ EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"), File->getInstallName());
+ EXPECT_TRUE(File->targets().begin() != File->targets().end());
+ EXPECT_EQ(*File->targets().begin(),
+ Target(AK_arm64, PLATFORM_IOSSIMULATOR, VersionTuple(0, 0)));
+}
+
+TEST(TBDv5, InvalidMinOS) {
+ static const char TBDv5File[] = R"({
+"tapi_tbd_version": 5,
+"main_library": {
+ "target_info": [
+ {
+ "target": "arm64-ios-simulator",
+ "min_deployment": "swift-abi"
+ }
+ ],
+ "install_names":[
+ { "name":"/S/L/F/Foo.framework/Foo" }
+ ]
+}})";
+
+ Expected<TBDFile> Result =
+ TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
+ EXPECT_FALSE(!!Result);
+ std::string ErrorMessage = toString(Result.takeError());
+ EXPECT_EQ("invalid min_deployment section\n", ErrorMessage);
+}
+
TEST(TBDv5, MergeIF) {
static const char TBDv5FileA[] = R"({
"tapi_tbd_version": 5,
More information about the llvm-commits
mailing list