brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.0 KiB · a2ca577 Raw
273 lines · c
1//===- Config.h -------------------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLD_MACHO_CONFIG_H10#define LLD_MACHO_CONFIG_H11 12#include "llvm/ADT/CachedHashString.h"13#include "llvm/ADT/DenseMap.h"14#include "llvm/ADT/DenseSet.h"15#include "llvm/ADT/SetVector.h"16#include "llvm/ADT/SmallVector.h"17#include "llvm/ADT/StringRef.h"18#include "llvm/ADT/StringSet.h"19#include "llvm/BinaryFormat/MachO.h"20#include "llvm/Support/CachePruning.h"21#include "llvm/Support/GlobPattern.h"22#include "llvm/Support/VersionTuple.h"23#include "llvm/TextAPI/Architecture.h"24#include "llvm/TextAPI/Platform.h"25#include "llvm/TextAPI/Target.h"26 27#include <vector>28 29namespace llvm {30enum class CodeGenOptLevel;31} // namespace llvm32 33namespace lld {34namespace macho {35 36class InputSection;37class Symbol;38 39using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;40using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;41using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;42 43struct PlatformInfo {44  llvm::MachO::Target target;45  llvm::VersionTuple sdk;46};47 48inline uint32_t encodeVersion(const llvm::VersionTuple &version) {49  return ((version.getMajor() << 020) |50          (version.getMinor().value_or(0) << 010) |51          version.getSubminor().value_or(0));52}53 54enum class NamespaceKind {55  twolevel,56  flat,57};58 59enum class UndefinedSymbolTreatment {60  unknown,61  error,62  warning,63  suppress,64  dynamic_lookup,65};66 67enum class ICFLevel {68  unknown,69  none,70  safe,71  safe_thunks,72  all,73};74 75enum class ObjCStubsMode {76  fast,77  small,78};79 80struct SectionAlign {81  llvm::StringRef segName;82  llvm::StringRef sectName;83  uint32_t align;84};85 86struct SegmentProtection {87  llvm::StringRef name;88  uint32_t maxProt;89  uint32_t initProt;90};91 92class SymbolPatterns {93public:94  // GlobPattern can also match literals,95  // but we prefer the O(1) lookup of DenseSet.96  llvm::SetVector<llvm::CachedHashStringRef> literals;97  std::vector<llvm::GlobPattern> globs;98 99  bool empty() const { return literals.empty() && globs.empty(); }100  void clear();101  void insert(llvm::StringRef symbolName);102  bool matchLiteral(llvm::StringRef symbolName) const;103  bool matchGlob(llvm::StringRef symbolName) const;104  bool match(llvm::StringRef symbolName) const;105};106 107enum class SymtabPresence {108  All,109  None,110  SelectivelyIncluded,111  SelectivelyExcluded,112};113 114struct Configuration {115  Symbol *entry = nullptr;116  bool hasReexports = false;117  bool allLoad = false;118  bool applicationExtension = false;119  bool archMultiple = false;120  bool exportDynamic = false;121  bool forceLoadObjC = false;122  bool forceLoadSwift = false; // Only applies to LC_LINKER_OPTIONs.123  bool staticLink = false;124  bool implicitDylibs = false;125  bool isPic = false;126  bool headerPadMaxInstallNames = false;127  bool markDeadStrippableDylib = false;128  bool printDylibSearch = false;129  bool printEachFile = false;130  bool printWhyLoad = false;131  bool searchDylibsFirst = false;132  bool saveTemps = false;133  bool adhocCodesign = false;134  bool emitFunctionStarts = false;135  bool emitDataInCodeInfo = false;136  bool emitEncryptionInfo = false;137  bool emitInitOffsets = false;138  bool emitChainedFixups = false;139  bool emitRelativeMethodLists = false;140  bool thinLTOEmitImportsFiles;141  bool thinLTOEmitIndexFiles;142  bool thinLTOIndexOnly;143  bool timeTraceEnabled = false;144  bool dataConst = false;145  bool dedupStrings = true;146  bool dedupSymbolStrings = true;147  bool deadStripDuplicates = false;148  bool omitDebugInfo = false;149  bool warnDylibInstallName = false;150  bool ignoreOptimizationHints = false;151  bool forceExactCpuSubtypeMatch = false;152  uint32_t headerPad;153  uint32_t dylibCompatibilityVersion = 0;154  uint32_t dylibCurrentVersion = 0;155  uint32_t timeTraceGranularity = 500;156  unsigned optimize;157  std::string progName;158 159  // For `clang -arch arm64 -arch x86_64`, clang will:160  // 1. invoke the linker twice, to write one temporary output per arch161  // 2. invoke `lipo` to merge the two outputs into a single file162  // `outputFile` is the name of the temporary file the linker writes to.163  // `finalOutput `is the name of the file lipo writes to after the link.164  llvm::StringRef outputFile;165  llvm::StringRef finalOutput;166 167  llvm::StringRef installName;168  llvm::StringRef clientName;169  llvm::StringRef mapFile;170  llvm::StringRef ltoNewPmPasses;171  llvm::StringRef ltoObjPath;172  llvm::StringRef thinLTOJobs;173  llvm::StringRef umbrella;174  uint32_t ltoo = 2;175  llvm::CodeGenOptLevel ltoCgo;176  llvm::CachePruningPolicy thinLTOCachePolicy;177  llvm::StringRef thinLTOCacheDir;178  llvm::StringRef thinLTOIndexOnlyArg;179  std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;180  llvm::StringRef thinLTOPrefixReplaceOld;181  llvm::StringRef thinLTOPrefixReplaceNew;182  llvm::StringRef thinLTOPrefixReplaceNativeObject;183  bool deadStripDylibs = false;184  bool demangle = false;185  bool deadStrip = false;186  bool interposable = false;187  bool errorForArchMismatch = false;188  bool ignoreAutoLink = false;189  int readWorkers = 0;190  // ld64 allows invalid auto link options as long as the link succeeds. LLD191  // does not, but there are cases in the wild where the invalid linker options192  // exist. This allows users to ignore the specific invalid options in the case193  // they can't easily fix them.194  llvm::StringSet<> ignoreAutoLinkOptions;195  bool strictAutoLink = false;196  PlatformInfo platformInfo;197  std::optional<PlatformInfo> secondaryPlatformInfo;198  NamespaceKind namespaceKind = NamespaceKind::twolevel;199  UndefinedSymbolTreatment undefinedSymbolTreatment =200      UndefinedSymbolTreatment::error;201  ICFLevel icfLevel = ICFLevel::none;202  bool keepICFStabs = false;203  ObjCStubsMode objcStubsMode = ObjCStubsMode::fast;204  llvm::MachO::HeaderFileType outputType;205  std::vector<llvm::StringRef> systemLibraryRoots;206  std::vector<llvm::StringRef> librarySearchPaths;207  std::vector<llvm::StringRef> frameworkSearchPaths;208  bool warnDuplicateRpath = true;209  llvm::SmallVector<llvm::StringRef, 0> runtimePaths;210  llvm::SmallVector<llvm::StringRef, 0> allowableClients;211  std::vector<std::string> astPaths;212  std::vector<Symbol *> explicitUndefineds;213  llvm::StringSet<> explicitDynamicLookups;214  // There are typically few custom sectionAlignments or segmentProtections,215  // so use a vector instead of a map.216  std::vector<SectionAlign> sectionAlignments;217  std::vector<SegmentProtection> segmentProtections;218  bool ltoDebugPassManager = false;219  llvm::StringRef codegenDataGeneratePath;220  bool csProfileGenerate = false;221  llvm::StringRef csProfilePath;222  bool pgoWarnMismatch;223  bool warnThinArchiveMissingMembers;224  bool disableVerify;225  bool separateCstringLiteralSections;226  bool tailMergeStrings;227 228  bool callGraphProfileSort = false;229  llvm::StringRef printSymbolOrder;230 231  llvm::StringRef irpgoProfilePath;232  bool bpStartupFunctionSort = false;233  bool bpCompressionSortStartupFunctions = false;234  bool bpFunctionOrderForCompression = false;235  bool bpDataOrderForCompression = false;236  bool bpVerboseSectionOrderer = false;237 238  SectionRenameMap sectionRenameMap;239  SegmentRenameMap segmentRenameMap;240 241  bool hasExplicitExports = false;242  SymbolPatterns exportedSymbols;243  SymbolPatterns unexportedSymbols;244  SymbolPatterns whyLive;245 246  std::vector<std::pair<llvm::StringRef, llvm::StringRef>> aliasedSymbols;247 248  SymtabPresence localSymbolsPresence = SymtabPresence::All;249  SymbolPatterns localSymbolPatterns;250  llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;251  llvm::SmallVector<llvm::StringRef, 0> passPlugins;252 253  bool zeroModTime = true;254  bool generateUuid = true;255 256  llvm::StringRef osoPrefix;257 258  std::vector<llvm::StringRef> dyldEnvs;259 260  llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }261 262  llvm::MachO::PlatformType platform() const {263    return platformInfo.target.Platform;264  }265};266 267extern std::unique_ptr<Configuration> config;268 269} // namespace macho270} // namespace lld271 272#endif273