diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -42,7 +42,6 @@ struct PlatformInfo { llvm::MachO::Target target; - llvm::VersionTuple minimum; llvm::VersionTuple sdk; }; diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -683,7 +683,8 @@ } // Has the side-effect of setting Config::platformInfo. -static PlatformType parsePlatformVersions(const ArgList &args) { +static std::pair> +parsePlatformVersions(const ArgList &args) { std::map platformVersions; const PlatformVersion *lastVersionInfo = nullptr; for (const Arg *arg : args.filtered(OPT_platform_version)) { @@ -699,11 +700,11 @@ if (platformVersions.empty()) { error("must specify -platform_version"); - return PLATFORM_UNKNOWN; + return {}; } if (platformVersions.size() > 2) { error("must specify -platform_version at most twice"); - return PLATFORM_UNKNOWN; + return {}; } if (platformVersions.size() == 2) { bool isZipperedCatalyst = platformVersions.count(PLATFORM_MACOS) && @@ -716,20 +717,20 @@ config->outputType != MH_BUNDLE) { error("writing zippered outputs only valid for -dylib and -bundle"); } else { - config->platformInfo.minimum = platformVersions[PLATFORM_MACOS].minimum; - config->platformInfo.sdk = platformVersions[PLATFORM_MACOS].sdk; - config->secondaryPlatformInfo = PlatformInfo{}; - config->secondaryPlatformInfo->minimum = - platformVersions[PLATFORM_MACCATALYST].minimum; - config->secondaryPlatformInfo->sdk = - platformVersions[PLATFORM_MACCATALYST].sdk; + return {{PLATFORM_MACOS, platformVersions[PLATFORM_MACOS].minimum, + platformVersions[PLATFORM_MACOS].sdk}, + std::optional( + {PLATFORM_MACCATALYST, + platformVersions[PLATFORM_MACCATALYST].minimum, + platformVersions[PLATFORM_MACCATALYST].sdk})}; } - return PLATFORM_MACOS; + + return {{PLATFORM_MACOS, platformVersions[PLATFORM_MACOS].minimum, + platformVersions[PLATFORM_MACOS].sdk}, + std::nullopt}; } - config->platformInfo.minimum = lastVersionInfo->minimum; - config->platformInfo.sdk = lastVersionInfo->sdk; - return lastVersionInfo->platform; + return {*lastVersionInfo, std::nullopt}; } // Has the side-effect of setting Config::target. @@ -740,12 +741,16 @@ return nullptr; } - PlatformType platform = parsePlatformVersions(args); - config->platformInfo.target = - MachO::Target(getArchitectureFromName(archName), platform); - if (config->secondaryPlatformInfo) { - config->secondaryPlatformInfo->target = - MachO::Target(getArchitectureFromName(archName), PLATFORM_MACCATALYST); + auto versions = parsePlatformVersions(args); + config->platformInfo = {MachO::Target(getArchitectureFromName(archName), + versions.first.platform, + versions.first.minimum), + versions.first.sdk}; + if (versions.second) { + config->secondaryPlatformInfo = { + MachO::Target(getArchitectureFromName(archName), PLATFORM_MACCATALYST, + versions.second->minimum), + versions.second->sdk}; } auto [cpuType, cpuSubtype] = getCPUTypeFromArchitecture(config->arch()); @@ -987,7 +992,7 @@ auto it = llvm::find_if(minVersion, [&](const auto &p) { return p.first == platform; }); if (it != minVersion.end()) - if (config->platformInfo.minimum < it->second) + if (config->platformInfo.target.MinDeployment < it->second) return false; switch (config->outputType) { @@ -1025,13 +1030,14 @@ PlatformType platform = removeSimulator(config->platformInfo.target.Platform); auto it = llvm::find_if(minVersion, [&](const auto &p) { return p.first == platform; }); - if (it != minVersion.end() && it->second > config->platformInfo.minimum) { + if (it != minVersion.end() && + it->second > config->platformInfo.target.MinDeployment) { if (!isRequested) return false; warn("-fixup_chains requires " + getPlatformName(config->platform()) + " " + it->second.getAsString() + ", which is newer than target minimum of " + - config->platformInfo.minimum.getAsString()); + config->platformInfo.target.MinDeployment.getAsString()); } if (!is_contained({AK_x86_64, AK_x86_64h, AK_arm64}, config->arch())) { diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -124,7 +124,7 @@ for (auto *cmd : findCommands(hdr, LC_BUILD_VERSION)) { PlatformInfo info; info.target.Platform = static_cast(cmd->platform); - info.minimum = decodeVersion(cmd->minos); + info.target.MinDeployment = decodeVersion(cmd->minos); platformInfos.emplace_back(std::move(info)); } for (auto *cmd : findCommands( @@ -145,7 +145,7 @@ info.target.Platform = PLATFORM_WATCHOS; break; } - info.minimum = decodeVersion(cmd->version); + info.target.MinDeployment = decodeVersion(cmd->version); platformInfos.emplace_back(std::move(info)); } @@ -176,10 +176,11 @@ return false; } - if (it->minimum > config->platformInfo.minimum) - warn(toString(input) + " has version " + it->minimum.getAsString() + + if (it->target.MinDeployment > config->platformInfo.target.MinDeployment) + warn(toString(input) + " has version " + + it->target.MinDeployment.getAsString() + ", which is newer than target minimum of " + - config->platformInfo.minimum.getAsString()); + config->platformInfo.target.MinDeployment.getAsString()); return true; } @@ -2017,8 +2018,8 @@ originalName + "' ignored"); return; } - if (config->platformInfo.minimum < start || - config->platformInfo.minimum >= end) + if (config->platformInfo.target.MinDeployment < start || + config->platformInfo.target.MinDeployment >= end) return; // Initialized to compatibilityVersion for the symbolName branch below. @@ -2069,7 +2070,7 @@ if (!condition.consume_front("os") || version.tryParse(condition)) warn(toString(this) + ": failed to parse os version, symbol '" + originalName + "' ignored"); - else if (version == config->platformInfo.minimum) + else if (version == config->platformInfo.target.MinDeployment) this->installName = saver().save(installName); } @@ -2087,7 +2088,7 @@ "` ignored."); return; } - shouldHide = versionTup == config->platformInfo.minimum; + shouldHide = versionTup == config->platformInfo.target.MinDeployment; } else { symbolName = name; } diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -105,7 +105,7 @@ if (config->outputType == MH_EXECUTE && !config->staticLink && target->cpuSubtype == CPU_SUBTYPE_X86_64_ALL && config->platform() == PLATFORM_MACOS && - config->platformInfo.minimum >= VersionTuple(10, 5)) + config->platformInfo.target.MinDeployment >= VersionTuple(10, 5)) subtype |= CPU_SUBTYPE_LIB64; return subtype; diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -465,7 +465,7 @@ break; } c->cmdsize = getSize(); - c->version = encodeVersion(platformInfo.minimum); + c->version = encodeVersion(platformInfo.target.MinDeployment); c->sdk = encodeVersion(platformInfo.sdk); } @@ -490,7 +490,7 @@ c->cmdsize = getSize(); c->platform = static_cast(platformInfo.target.Platform); - c->minos = encodeVersion(platformInfo.minimum); + c->minos = encodeVersion(platformInfo.target.MinDeployment); c->sdk = encodeVersion(platformInfo.sdk); c->ntools = ntools; @@ -764,7 +764,9 @@ auto it = llvm::find_if(minVersion, [&](const auto &p) { return p.first == platformInfo.target.Platform; }); - return it == minVersion.end() ? true : platformInfo.minimum >= it->second; + return it == minVersion.end() + ? true + : platformInfo.target.MinDeployment >= it->second; } template void Writer::createLoadCommands() { diff --git a/lld/test/MachO/invalid/incompatible-target-tapi.test b/lld/test/MachO/invalid/incompatible-target-tapi.test --- a/lld/test/MachO/invalid/incompatible-target-tapi.test +++ b/lld/test/MachO/invalid/incompatible-target-tapi.test @@ -6,5 +6,5 @@ RUN: -o /dev/null 2>&1 | FileCheck %s --check-prefix=ARCH RUN: not %no-arg-lld -dylib -arch arm64 -platform_version ios-simulator 14.0 15.0 %t/arm64-test.o \ RUN: %S/Inputs/libincompatible.tbd -o /dev/null 2>&1 | FileCheck %s --check-prefix=PLATFORM -ARCH: error: {{.*}}libincompatible.tbd(/usr/lib/libincompatible.dylib) is incompatible with x86_64 (macOS) -PLATFORM: error: {{.*}}libincompatible.tbd(/usr/lib/libincompatible.dylib) is incompatible with arm64 (iOS Simulator) +ARCH: error: {{.*}}libincompatible.tbd(/usr/lib/libincompatible.dylib) is incompatible with x86_64 (macOS11.0) +PLATFORM: error: {{.*}}libincompatible.tbd(/usr/lib/libincompatible.dylib) is incompatible with arm64 (iOS Simulator14.0) diff --git a/lld/test/MachO/tapi-link.s b/lld/test/MachO/tapi-link.s --- a/lld/test/MachO/tapi-link.s +++ b/lld/test/MachO/tapi-link.s @@ -15,9 +15,9 @@ # RUN: env LD_DYLIB_CPU_SUBTYPES_MUST_MATCH=1 not %lld -arch x86_64h -o /dev/null -lSystem -lc++ -framework \ # RUN: CoreFoundation %t/libNested.tbd %t/libTlvWeak.tbd %t/test.o 2>&1 | FileCheck %s -check-prefix=INCOMPATIBLE -# INCOMPATIBLE: error: {{.*}}libSystem.tbd(/usr/lib/libSystem.dylib) is incompatible with x86_64h (macOS) -# INCOMPATIBLE-NEXT: error: {{.*}}libc++.tbd(/usr/lib/libc++.dylib) is incompatible with x86_64h (macOS) -# INCOMPATIBLE-NEXT: error: {{.*}}CoreFoundation.tbd(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation) is incompatible with x86_64h (macOS) +# INCOMPATIBLE: error: {{.*}}libSystem.tbd(/usr/lib/libSystem.dylib) is incompatible with x86_64h (macOS11.0) +# INCOMPATIBLE-NEXT: error: {{.*}}libc++.tbd(/usr/lib/libc++.dylib) is incompatible with x86_64h (macOS11.0) +# INCOMPATIBLE-NEXT: error: {{.*}}CoreFoundation.tbd(/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation) is incompatible with x86_64h (macOS11.0) ## libReexportSystem.tbd tests that we can reference symbols from a 2nd-level ## tapi document, re-exported by a top-level tapi document, which itself is diff --git a/lld/test/MachO/zippered.yaml b/lld/test/MachO/zippered.yaml --- a/lld/test/MachO/zippered.yaml +++ b/lld/test/MachO/zippered.yaml @@ -12,7 +12,7 @@ # RUN: %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version mac-catalyst 13.15.0 14.0 %t/test_maccatalyst.o -o /dev/null -framework MacOnly-Indirect # RUN: not %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version mac-catalyst 13.15.0 14.0 %t/test_maccatalyst.o -o /dev/null -framework MacOnly 2>&1 | FileCheck --check-prefix=INCOMPATIBLE %s -# INCOMPATIBLE: System/Library/Frameworks{{[\\/]}}MacOnly.framework{{[\\/]}}MacOnly.tbd(MacOnly.dylib) is incompatible with x86_64 (macCatalyst) +# INCOMPATIBLE: System/Library/Frameworks{{[\\/]}}MacOnly.framework{{[\\/]}}MacOnly.tbd(MacOnly.dylib) is incompatible with x86_64 (macCatalyst13.15.0) # RUN: not %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version ios 13.15.0 14.0 %t/test.dylib %t/test_ios.o -o /dev/null 2>&1 | FileCheck %s # CHECK: test.dylib has platform macOS/macCatalyst, which is different from target platform iOS