diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -124,6 +124,12 @@ 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 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -619,7 +619,7 @@ 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 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 @@ std::array 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 @@ 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 @@ 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 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -146,11 +146,11 @@ 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 @@ auto *hdr = reinterpret_cast(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 @@ // 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 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -117,10 +117,9 @@ 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 --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -108,9 +108,8 @@ 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 --- a/lld/MachO/OutputSegment.cpp +++ b/lld/MachO/OutputSegment.cpp @@ -37,7 +37,7 @@ } 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); } diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -99,7 +99,7 @@ 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;