[lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields

As discussed here: https://reviews.llvm.org/D100523#inline-951543

Reviewed By: #lld-macho, thakis, alexshap

Differential Revision: https://reviews.llvm.org/D100978
This commit is contained in:
Jez Ng 2021-04-21 15:43:38 -04:00
parent 24e9fbc1a3
commit ed4a4e3312
7 changed files with 29 additions and 28 deletions

View File

@ -124,6 +124,12 @@ struct Configuration {
SymbolPatterns exportedSymbols;
SymbolPatterns unexportedSymbols;
llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
llvm::MachO::PlatformKind platform() const {
return platformInfo.target.Platform;
}
};
// The symbol with the highest priority should be ordered first in the output

View File

@ -619,7 +619,7 @@ static TargetInfo *createTargetInfo(InputArgList &args) {
config->platformInfo.target =
MachO::Target(getArchitectureFromName(archName), platform);
switch (getCPUTypeFromArchitecture(config->platformInfo.target.Arch).first) {
switch (getCPUTypeFromArchitecture(config->arch()).first) {
case CPU_TYPE_X86_64:
return createX86_64TargetInfo();
case CPU_TYPE_ARM64:
@ -700,16 +700,14 @@ static const char *getReproduceOption(InputArgList &args) {
static bool isPie(InputArgList &args) {
if (config->outputType != MH_EXECUTE || args.hasArg(OPT_no_pie))
return false;
if (config->platformInfo.target.Arch == AK_arm64 ||
config->platformInfo.target.Arch == AK_arm64e ||
config->platformInfo.target.Arch == AK_arm64_32)
if (config->arch() == AK_arm64 || config->arch() == AK_arm64e ||
config->arch() == AK_arm64_32)
return true;
// TODO: add logic here as we support more archs. E.g. i386 should default
// to PIE from 10.7
assert(config->platformInfo.target.Arch == AK_x86_64 ||
config->platformInfo.target.Arch == AK_x86_64h ||
config->platformInfo.target.Arch == AK_arm64_32);
assert(config->arch() == AK_x86_64 || config->arch() == AK_x86_64h ||
config->arch() == AK_arm64_32);
PlatformKind kind = config->platformInfo.target.Platform;
if (kind == PlatformKind::macOS &&
@ -965,9 +963,9 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
std::array<PlatformKind, 3> encryptablePlatforms{
PlatformKind::iOS, PlatformKind::watchOS, PlatformKind::tvOS};
config->emitEncryptionInfo = args.hasFlag(
OPT_encryptable, OPT_no_encryption,
is_contained(encryptablePlatforms, config->platformInfo.target.Platform));
config->emitEncryptionInfo =
args.hasFlag(OPT_encryptable, OPT_no_encryption,
is_contained(encryptablePlatforms, config->platform()));
#ifndef HAVE_LIBXAR
if (config->emitBitcodeBundle)
@ -1037,7 +1035,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
StringRef segName = arg->getValue(0);
uint32_t maxProt = parseProtection(arg->getValue(1));
uint32_t initProt = parseProtection(arg->getValue(2));
if (maxProt != initProt && config->platformInfo.target.Arch != AK_i386)
if (maxProt != initProt && config->arch() != AK_i386)
error("invalid argument '" + arg->getAsString(args) +
"': max and init must be the same for non-i386 archs");
if (segName == segment_names::linkEdit)
@ -1059,9 +1057,8 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
config->adhocCodesign = args.hasFlag(
OPT_adhoc_codesign, OPT_no_adhoc_codesign,
(config->platformInfo.target.Arch == AK_arm64 ||
config->platformInfo.target.Arch == AK_arm64e) &&
config->platformInfo.target.Platform == PlatformKind::macOS);
(config->arch() == AK_arm64 || config->arch() == AK_arm64e) &&
config->platform() == PlatformKind::macOS);
if (args.hasArg(OPT_v)) {
message(getLLDVersion());

View File

@ -146,11 +146,11 @@ template <class LP> static bool checkCompatibility(const InputFile *input) {
if (!platformInfo)
return true;
// TODO: Correctly detect simulator platforms or relax this check.
if (config->platformInfo.target.Platform != platformInfo->target.Platform) {
if (config->platform() != platformInfo->target.Platform) {
error(toString(input) + " has platform " +
getPlatformName(platformInfo->target.Platform) +
Twine(", which is different from target platform ") +
getPlatformName(config->platformInfo.target.Platform));
getPlatformName(config->platform()));
return false;
}
if (platformInfo->minimum >= config->platformInfo.minimum)
@ -583,10 +583,10 @@ template <class LP> void ObjFile::parse() {
auto *hdr = reinterpret_cast<const Header *>(mb.getBufferStart());
Architecture arch = getArchitectureFromCpuType(hdr->cputype, hdr->cpusubtype);
if (arch != config->platformInfo.target.Arch) {
if (arch != config->arch()) {
error(toString(this) + " has architecture " + getArchitectureName(arch) +
" which is incompatible with target architecture " +
getArchitectureName(config->platformInfo.target.Arch));
getArchitectureName(config->arch()));
return;
}
@ -841,7 +841,7 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
// TODO(compnerd) filter out symbols based on the target platform
// TODO: handle weak defs, thread locals
for (const auto *symbol : interface.symbols()) {
if (!symbol->getArchitectures().has(config->platformInfo.target.Arch))
if (!symbol->getArchitectures().has(config->arch()))
continue;
switch (symbol->getKind()) {

View File

@ -117,10 +117,9 @@ std::vector<ObjFile *> BitcodeCompiler::compile() {
uint32_t modTime = 0;
if (!config->ltoObjPath.empty()) {
filePath = config->ltoObjPath;
path::append(filePath,
Twine(i) + "." +
getArchitectureName(config->platformInfo.target.Arch) +
".lto.o");
path::append(filePath, Twine(i) + "." +
getArchitectureName(config->arch()) +
".lto.o");
saveBuffer(buf[i], filePath);
modTime = getModTime(filePath);
}

View File

@ -108,9 +108,8 @@ void macho::writeMapFile() {
os << format("# Path: %s\n", config->outputFile.str().c_str());
// Dump output architecture.
os << format(
"# Arch: %s\n",
getArchitectureName(config->platformInfo.target.Arch).str().c_str());
os << format("# Arch: %s\n",
getArchitectureName(config->arch()).str().c_str());
// Dump table of object files.
os << "# Object files:\n";

View File

@ -37,7 +37,7 @@ static uint32_t initProt(StringRef name) {
}
static uint32_t maxProt(StringRef name) {
assert(config->platformInfo.target.Arch != AK_i386 &&
assert(config->arch() != AK_i386 &&
"TODO: i386 has different maxProt requirements");
return initProt(name);
}

View File

@ -99,7 +99,7 @@ static uint32_t cpuSubtype() {
if (config->outputType == MH_EXECUTE && !config->staticLink &&
target->cpuSubtype == CPU_SUBTYPE_X86_64_ALL &&
config->platformInfo.target.Platform == PlatformKind::macOS &&
config->platform() == PlatformKind::macOS &&
config->platformInfo.minimum >= VersionTuple(10, 5))
subtype |= CPU_SUBTYPE_LIB64;