[lld] ed4a4e3 - [lld-macho][nfc] Add accessors for commonly-used PlatformInfo fields
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 21 12:44:25 PDT 2021
Author: Jez Ng
Date: 2021-04-21T15:43:56-04:00
New Revision: ed4a4e33129b259de1a946fbd4887e9e8300198c
URL: https://github.com/llvm/llvm-project/commit/ed4a4e33129b259de1a946fbd4887e9e8300198c
DIFF: https://github.com/llvm/llvm-project/commit/ed4a4e33129b259de1a946fbd4887e9e8300198c.diff
LOG: [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
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/LTO.cpp
lld/MachO/MapFile.cpp
lld/MachO/OutputSegment.cpp
lld/MachO/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 280bf8ecd87a..fdd3e6c92121 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -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
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 88937d726451..0b626baa47b6 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -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());
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 61f2840b2f83..7c1b3e1cd77d 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -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
diff erent 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()) {
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index a3d4b44749cb..55e155e1a7dd 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -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);
}
diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp
index 42726809ff64..2262a8cb890d 100644
--- a/lld/MachO/MapFile.cpp
+++ b/lld/MachO/MapFile.cpp
@@ -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";
diff --git a/lld/MachO/OutputSegment.cpp b/lld/MachO/OutputSegment.cpp
index 039001b8e13d..a561a5a6037d 100644
--- a/lld/MachO/OutputSegment.cpp
+++ b/lld/MachO/OutputSegment.cpp
@@ -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
diff erent maxProt requirements");
return initProt(name);
}
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 6d7515d2de83..66e1effcaf0f 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -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;
More information about the llvm-commits
mailing list