Skip to content

Commit 86c31e4

Browse files
committed
[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 (cherry picked from commit 3b73139)
1 parent 979f2de commit 86c31e4

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

llvm/lib/TextAPI/TextStubV5.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ All library level keys, accept target values and are defaulted if not specified.
2727
"target_info": [ # Required: target information
2828
{
2929
"target": "x86_64-macos",
30-
"min_deployment": "10.14" # Required: minimum OS deployment version
30+
"min_deployment": "10.14" # Optional: minOS defaults to 0
3131
},
3232
{
3333
"target": "arm64-macos",
@@ -282,17 +282,16 @@ Expected<TargetList> getTargetsSection(const Object *Section) {
282282
getRequiredValue<StringRef>(TBDKey::Target, Obj, &Object::getString);
283283
if (!TargetStr)
284284
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Target));
285-
auto VersionStr = getRequiredValue<StringRef>(TBDKey::Deployment, Obj,
286-
&Object::getString);
287-
if (!VersionStr)
288-
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Deployment));
289-
VersionTuple Version;
290-
if (Version.tryParse(*VersionStr))
291-
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Deployment));
292285
auto TargetOrErr = Target::create(*TargetStr);
293286
if (!TargetOrErr)
294287
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Target));
288+
289+
auto VersionStr = Obj->getString(Keys[TBDKey::Deployment]);
290+
VersionTuple Version;
291+
if (VersionStr && Version.tryParse(*VersionStr))
292+
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Deployment));
295293
TargetOrErr->MinDeployment = Version;
294+
296295
// Convert to LLVM::Triple to accurately compute minOS + platform + arch
297296
// pairing.
298297
IFTargets.push_back(

llvm/unittests/TextAPI/TextStubV5Tests.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,53 @@ TEST(TBDv5, InvalidSymbols) {
11041104
EXPECT_EQ("invalid exported_symbols section\n", ErrorMessage);
11051105
}
11061106

1107+
TEST(TBDv5, DefaultMinOS) {
1108+
static const char TBDv5File[] = R"({
1109+
"tapi_tbd_version": 5,
1110+
"main_library": {
1111+
"target_info": [
1112+
{
1113+
"target": "arm64-ios-simulator"
1114+
}
1115+
],
1116+
"install_names":[
1117+
{ "name":"/S/L/F/Foo.framework/Foo" }
1118+
]
1119+
}})";
1120+
1121+
Expected<TBDFile> Result =
1122+
TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
1123+
EXPECT_TRUE(!!Result);
1124+
TBDFile File = std::move(Result.get());
1125+
EXPECT_EQ(FileType::TBD_V5, File->getFileType());
1126+
EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"), File->getInstallName());
1127+
EXPECT_TRUE(File->targets().begin() != File->targets().end());
1128+
EXPECT_EQ(*File->targets().begin(),
1129+
Target(AK_arm64, PLATFORM_IOSSIMULATOR, VersionTuple(0, 0)));
1130+
}
1131+
1132+
TEST(TBDv5, InvalidMinOS) {
1133+
static const char TBDv5File[] = R"({
1134+
"tapi_tbd_version": 5,
1135+
"main_library": {
1136+
"target_info": [
1137+
{
1138+
"target": "arm64-ios-simulator",
1139+
"min_deployment": "swift-abi"
1140+
}
1141+
],
1142+
"install_names":[
1143+
{ "name":"/S/L/F/Foo.framework/Foo" }
1144+
]
1145+
}})";
1146+
1147+
Expected<TBDFile> Result =
1148+
TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
1149+
EXPECT_FALSE(!!Result);
1150+
std::string ErrorMessage = toString(Result.takeError());
1151+
EXPECT_EQ("invalid min_deployment section\n", ErrorMessage);
1152+
}
1153+
11071154
TEST(TBDv5, MergeIF) {
11081155
static const char TBDv5FileA[] = R"({
11091156
"tapi_tbd_version": 5,

0 commit comments

Comments
 (0)