Path: blob/main/contrib/llvm-project/lld/MachO/Config.h
34879 views
//===- Config.h -------------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLD_MACHO_CONFIG_H9#define LLD_MACHO_CONFIG_H1011#include "llvm/ADT/CachedHashString.h"12#include "llvm/ADT/DenseMap.h"13#include "llvm/ADT/DenseSet.h"14#include "llvm/ADT/SetVector.h"15#include "llvm/ADT/SmallVector.h"16#include "llvm/ADT/StringRef.h"17#include "llvm/ADT/StringSet.h"18#include "llvm/BinaryFormat/MachO.h"19#include "llvm/Support/CachePruning.h"20#include "llvm/Support/GlobPattern.h"21#include "llvm/Support/VersionTuple.h"22#include "llvm/TextAPI/Architecture.h"23#include "llvm/TextAPI/Platform.h"24#include "llvm/TextAPI/Target.h"2526#include <vector>2728namespace llvm {29enum class CodeGenOptLevel;30} // namespace llvm3132namespace lld {33namespace macho {3435class InputSection;36class Symbol;3738using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;39using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;40using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;4142struct PlatformInfo {43llvm::MachO::Target target;44llvm::VersionTuple sdk;45};4647inline uint32_t encodeVersion(const llvm::VersionTuple &version) {48return ((version.getMajor() << 020) |49(version.getMinor().value_or(0) << 010) |50version.getSubminor().value_or(0));51}5253enum class NamespaceKind {54twolevel,55flat,56};5758enum class UndefinedSymbolTreatment {59unknown,60error,61warning,62suppress,63dynamic_lookup,64};6566enum class ICFLevel {67unknown,68none,69safe,70all,71};7273enum class ObjCStubsMode {74fast,75small,76};7778struct SectionAlign {79llvm::StringRef segName;80llvm::StringRef sectName;81uint32_t align;82};8384struct SegmentProtection {85llvm::StringRef name;86uint32_t maxProt;87uint32_t initProt;88};8990class SymbolPatterns {91public:92// GlobPattern can also match literals,93// but we prefer the O(1) lookup of DenseSet.94llvm::SetVector<llvm::CachedHashStringRef> literals;95std::vector<llvm::GlobPattern> globs;9697bool empty() const { return literals.empty() && globs.empty(); }98void clear();99void insert(llvm::StringRef symbolName);100bool matchLiteral(llvm::StringRef symbolName) const;101bool matchGlob(llvm::StringRef symbolName) const;102bool match(llvm::StringRef symbolName) const;103};104105enum class SymtabPresence {106All,107None,108SelectivelyIncluded,109SelectivelyExcluded,110};111112struct Configuration {113Symbol *entry = nullptr;114bool hasReexports = false;115bool allLoad = false;116bool applicationExtension = false;117bool archMultiple = false;118bool exportDynamic = false;119bool forceLoadObjC = false;120bool forceLoadSwift = false; // Only applies to LC_LINKER_OPTIONs.121bool staticLink = false;122bool implicitDylibs = false;123bool isPic = false;124bool headerPadMaxInstallNames = false;125bool markDeadStrippableDylib = false;126bool printDylibSearch = false;127bool printEachFile = false;128bool printWhyLoad = false;129bool searchDylibsFirst = false;130bool saveTemps = false;131bool adhocCodesign = false;132bool emitFunctionStarts = false;133bool emitDataInCodeInfo = false;134bool emitEncryptionInfo = false;135bool emitInitOffsets = false;136bool emitChainedFixups = false;137bool emitRelativeMethodLists = false;138bool thinLTOEmitImportsFiles;139bool thinLTOEmitIndexFiles;140bool thinLTOIndexOnly;141bool timeTraceEnabled = false;142bool dataConst = false;143bool dedupStrings = true;144bool deadStripDuplicates = false;145bool omitDebugInfo = false;146bool warnDylibInstallName = false;147bool ignoreOptimizationHints = false;148bool forceExactCpuSubtypeMatch = false;149uint32_t headerPad;150uint32_t dylibCompatibilityVersion = 0;151uint32_t dylibCurrentVersion = 0;152uint32_t timeTraceGranularity = 500;153unsigned optimize;154std::string progName;155156// For `clang -arch arm64 -arch x86_64`, clang will:157// 1. invoke the linker twice, to write one temporary output per arch158// 2. invoke `lipo` to merge the two outputs into a single file159// `outputFile` is the name of the temporary file the linker writes to.160// `finalOutput `is the name of the file lipo writes to after the link.161llvm::StringRef outputFile;162llvm::StringRef finalOutput;163164llvm::StringRef installName;165llvm::StringRef mapFile;166llvm::StringRef ltoObjPath;167llvm::StringRef thinLTOJobs;168llvm::StringRef umbrella;169uint32_t ltoo = 2;170llvm::CodeGenOptLevel ltoCgo;171llvm::CachePruningPolicy thinLTOCachePolicy;172llvm::StringRef thinLTOCacheDir;173llvm::StringRef thinLTOIndexOnlyArg;174std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;175llvm::StringRef thinLTOPrefixReplaceOld;176llvm::StringRef thinLTOPrefixReplaceNew;177llvm::StringRef thinLTOPrefixReplaceNativeObject;178bool deadStripDylibs = false;179bool demangle = false;180bool deadStrip = false;181bool errorForArchMismatch = false;182bool ignoreAutoLink = false;183// ld64 allows invalid auto link options as long as the link succeeds. LLD184// does not, but there are cases in the wild where the invalid linker options185// exist. This allows users to ignore the specific invalid options in the case186// they can't easily fix them.187llvm::StringSet<> ignoreAutoLinkOptions;188bool strictAutoLink = false;189PlatformInfo platformInfo;190std::optional<PlatformInfo> secondaryPlatformInfo;191NamespaceKind namespaceKind = NamespaceKind::twolevel;192UndefinedSymbolTreatment undefinedSymbolTreatment =193UndefinedSymbolTreatment::error;194ICFLevel icfLevel = ICFLevel::none;195bool keepICFStabs = false;196ObjCStubsMode objcStubsMode = ObjCStubsMode::fast;197llvm::MachO::HeaderFileType outputType;198std::vector<llvm::StringRef> systemLibraryRoots;199std::vector<llvm::StringRef> librarySearchPaths;200std::vector<llvm::StringRef> frameworkSearchPaths;201bool warnDuplicateRpath = true;202llvm::SmallVector<llvm::StringRef, 0> runtimePaths;203std::vector<std::string> astPaths;204std::vector<Symbol *> explicitUndefineds;205llvm::StringSet<> explicitDynamicLookups;206// There are typically few custom sectionAlignments or segmentProtections,207// so use a vector instead of a map.208std::vector<SectionAlign> sectionAlignments;209std::vector<SegmentProtection> segmentProtections;210bool ltoDebugPassManager = false;211bool csProfileGenerate = false;212llvm::StringRef csProfilePath;213bool pgoWarnMismatch;214bool warnThinArchiveMissingMembers;215216bool callGraphProfileSort = false;217llvm::StringRef printSymbolOrder;218219SectionRenameMap sectionRenameMap;220SegmentRenameMap segmentRenameMap;221222bool hasExplicitExports = false;223SymbolPatterns exportedSymbols;224SymbolPatterns unexportedSymbols;225SymbolPatterns whyLive;226227std::vector<std::pair<llvm::StringRef, llvm::StringRef>> aliasedSymbols;228229SymtabPresence localSymbolsPresence = SymtabPresence::All;230SymbolPatterns localSymbolPatterns;231llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;232233bool zeroModTime = true;234bool generateUuid = true;235236llvm::StringRef osoPrefix;237238std::vector<llvm::StringRef> dyldEnvs;239240llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }241242llvm::MachO::PlatformType platform() const {243return platformInfo.target.Platform;244}245};246247extern std::unique_ptr<Configuration> config;248249} // namespace macho250} // namespace lld251252#endif253254255