[PATCH] D97979: [lld-macho] Check platform and version when constructor ObjFile
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 4 13:59:18 PST 2021
oontvoo created this revision.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97979
Files:
lld/MachO/InputFiles.cpp
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ 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<uint32_t>(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<const linker_option_command *>(cmd);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97979.328302.patch
Type: text/x-patch
Size: 1856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210304/b4eac6f0/attachment.bin>
More information about the llvm-commits
mailing list