mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-21 03:05:26 -04:00
[macho] save the SDK version stored in module metadata into the version min and
build version load commands in the object file This commit introduces a new metadata node called "SDK Version". It will be set by the frontend to mark the platform SDK (macOS/iOS/etc) version which was used during that particular compilation. This node is used when machine code is emitted, by either saving the SDK version into the appropriate macho load command (version min/build version), or by emitting the assembly for these load commands with the SDK version specified as well. The assembly for both load commands is extended by allowing it to contain the sdk_version X, Y [, Z] trailing directive to represent the SDK version respectively. rdar://45774000 Differential Revision: https://reviews.llvm.org/D55612 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349119 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/RandomNumberGenerator.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
@@ -547,6 +548,45 @@ void Module::setRtLibUseGOT() {
|
||||
addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
|
||||
}
|
||||
|
||||
void Module::setSDKVersion(const VersionTuple &V) {
|
||||
SmallVector<unsigned, 3> Entries;
|
||||
Entries.push_back(V.getMajor());
|
||||
if (auto Minor = V.getMinor()) {
|
||||
Entries.push_back(*Minor);
|
||||
if (auto Subminor = V.getSubminor())
|
||||
Entries.push_back(*Subminor);
|
||||
// Ignore the 'build' component as it can't be represented in the object
|
||||
// file.
|
||||
}
|
||||
addModuleFlag(ModFlagBehavior::Warning, "SDK Version",
|
||||
ConstantDataArray::get(Context, Entries));
|
||||
}
|
||||
|
||||
VersionTuple Module::getSDKVersion() const {
|
||||
auto *CM = dyn_cast_or_null<ConstantAsMetadata>(getModuleFlag("SDK Version"));
|
||||
if (!CM)
|
||||
return {};
|
||||
auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
|
||||
if (!Arr)
|
||||
return {};
|
||||
auto getVersionComponent = [&](unsigned Index) -> Optional<unsigned> {
|
||||
if (Index >= Arr->getNumElements())
|
||||
return None;
|
||||
return (unsigned)Arr->getElementAsInteger(Index);
|
||||
};
|
||||
auto Major = getVersionComponent(0);
|
||||
if (!Major)
|
||||
return {};
|
||||
VersionTuple Result = VersionTuple(*Major);
|
||||
if (auto Minor = getVersionComponent(1)) {
|
||||
Result = VersionTuple(*Major, *Minor);
|
||||
if (auto Subminor = getVersionComponent(2)) {
|
||||
Result = VersionTuple(*Major, *Minor, *Subminor);
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
GlobalVariable *llvm::collectUsedGlobalVariables(
|
||||
const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
|
||||
const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
|
||||
|
||||
Reference in New Issue
Block a user