diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -492,7 +492,39 @@ getArchitectureName(config->target.Arch)); return; } - // TODO: check platform too + + if (const build_version_command *cmd = findCommand(hdr, LC_BUILD_VERSION)) { + auto checkValidMinos = [](const build_version_command *cmd, + const llvm::VersionTuple &ConfigVersion) { + unsigned major = cmd->minos >> 16; + unsigned minor = (cmd->minos >> 8) & 0xffu; + unsigned subMinor = cmd->minos & 0xffu; + if (major < ConfigVersion.getMajor() || + major == ConfigVersion.getMajor() && + minor < ConfigVersion.getMinor() || + minor == ConfigVersion.getMinor() && + subMinor < ConfigVersion.getSubminor()) { + // Prepare the human-readable string for error message. + std::string Rep; + llvm::raw_string_ostream Out(Rep); + Out << major << "." << minor << "." << subMinor; + return Rep; + } + return ""; + }; + if (static_cast(config->platform.kind) != cmd->platform) { + error(toString(this) + " has platform " + Twine(cmd->platform) + + Twine(" which is different from target platform ") + + Twine(config->platform.kind)); + return; + } else if (const std::string Rep = checkValidMinos(cmd, config->minimum); + !Rep.empty()) { + error(toString(this) + " has version " + Rep + + "which is incompatible with target version of " + + config->minimum.getAsString()); + return; + } + } if (const load_command *cmd = findCommand(hdr, LC_LINKER_OPTION)) { auto *c = reinterpret_cast(cmd);