comparison lld/MachO/Config.h @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
comparison
equal deleted inserted replaced
173:0572611fdcc8 207:2e18cbf3894f
7 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
8 8
9 #ifndef LLD_MACHO_CONFIG_H 9 #ifndef LLD_MACHO_CONFIG_H
10 #define LLD_MACHO_CONFIG_H 10 #define LLD_MACHO_CONFIG_H
11 11
12 #include "llvm/ADT/CachedHashString.h"
12 #include "llvm/ADT/DenseMap.h" 13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/DenseSet.h"
13 #include "llvm/ADT/StringRef.h" 15 #include "llvm/ADT/StringRef.h"
14 #include "llvm/BinaryFormat/MachO.h" 16 #include "llvm/BinaryFormat/MachO.h"
17 #include "llvm/Support/GlobPattern.h"
18 #include "llvm/Support/VersionTuple.h"
19 #include "llvm/TextAPI/Architecture.h"
20 #include "llvm/TextAPI/Platform.h"
21 #include "llvm/TextAPI/Target.h"
15 22
16 #include <vector> 23 #include <vector>
17 24
18 namespace lld { 25 namespace lld {
19 namespace macho { 26 namespace macho {
20 27
21 class Symbol; 28 class Symbol;
22 struct SymbolPriorityEntry; 29 struct SymbolPriorityEntry;
23 30
31 using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;
32 using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;
33 using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;
34
35 struct PlatformInfo {
36 llvm::MachO::Target target;
37 llvm::VersionTuple minimum;
38 llvm::VersionTuple sdk;
39 };
40
41 inline uint32_t encodeVersion(const llvm::VersionTuple &version) {
42 return ((version.getMajor() << 020) |
43 (version.getMinor().getValueOr(0) << 010) |
44 version.getSubminor().getValueOr(0));
45 }
46
47 enum class NamespaceKind {
48 twolevel,
49 flat,
50 };
51
52 enum class UndefinedSymbolTreatment {
53 unknown,
54 error,
55 warning,
56 suppress,
57 dynamic_lookup,
58 };
59
60 struct SectionAlign {
61 llvm::StringRef segName;
62 llvm::StringRef sectName;
63 uint32_t align;
64 };
65
66 struct SegmentProtection {
67 llvm::StringRef name;
68 uint32_t maxProt;
69 uint32_t initProt;
70 };
71
72 class SymbolPatterns {
73 public:
74 // GlobPattern can also match literals,
75 // but we prefer the O(1) lookup of DenseSet.
76 llvm::DenseSet<llvm::CachedHashStringRef> literals;
77 std::vector<llvm::GlobPattern> globs;
78
79 bool empty() const { return literals.empty() && globs.empty(); }
80 void clear();
81 void insert(llvm::StringRef symbolName);
82 bool matchLiteral(llvm::StringRef symbolName) const;
83 bool matchGlob(llvm::StringRef symbolName) const;
84 bool match(llvm::StringRef symbolName) const;
85 };
86
24 struct Configuration { 87 struct Configuration {
25 Symbol *entry; 88 Symbol *entry = nullptr;
26 bool hasReexports = false; 89 bool hasReexports = false;
90 bool allLoad = false;
91 bool forceLoadObjC = false;
92 bool staticLink = false;
93 bool implicitDylibs = false;
94 bool isPic = false;
95 bool headerPadMaxInstallNames = false;
96 bool ltoNewPassManager = LLVM_ENABLE_NEW_PASS_MANAGER;
97 bool markDeadStrippableDylib = false;
98 bool printEachFile = false;
99 bool printWhyLoad = false;
100 bool searchDylibsFirst = false;
101 bool saveTemps = false;
102 bool adhocCodesign = false;
103 bool emitFunctionStarts = false;
104 bool emitBitcodeBundle = false;
105 bool emitEncryptionInfo = false;
106 bool timeTraceEnabled = false;
107 bool dataConst = false;
108 uint32_t headerPad;
109 uint32_t dylibCompatibilityVersion = 0;
110 uint32_t dylibCurrentVersion = 0;
111 uint32_t timeTraceGranularity = 500;
112 std::string progName;
27 llvm::StringRef installName; 113 llvm::StringRef installName;
114 llvm::StringRef mapFile;
28 llvm::StringRef outputFile; 115 llvm::StringRef outputFile;
116 llvm::StringRef ltoObjPath;
117 llvm::StringRef thinLTOJobs;
118 bool deadStripDylibs = false;
119 bool demangle = false;
120 bool deadStrip = false;
121 PlatformInfo platformInfo;
122 NamespaceKind namespaceKind = NamespaceKind::twolevel;
123 UndefinedSymbolTreatment undefinedSymbolTreatment =
124 UndefinedSymbolTreatment::error;
29 llvm::MachO::HeaderFileType outputType; 125 llvm::MachO::HeaderFileType outputType;
30 std::vector<llvm::StringRef> searchPaths; 126 std::vector<llvm::StringRef> systemLibraryRoots;
127 std::vector<llvm::StringRef> librarySearchPaths;
128 std::vector<llvm::StringRef> frameworkSearchPaths;
129 std::vector<llvm::StringRef> runtimePaths;
130 std::vector<std::string> astPaths;
131 std::vector<Symbol *> explicitUndefineds;
132 // There are typically few custom sectionAlignments or segmentProtections,
133 // so use a vector instead of a map.
134 std::vector<SectionAlign> sectionAlignments;
135 std::vector<SegmentProtection> segmentProtections;
136
31 llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities; 137 llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;
138 SectionRenameMap sectionRenameMap;
139 SegmentRenameMap segmentRenameMap;
140
141 SymbolPatterns exportedSymbols;
142 SymbolPatterns unexportedSymbols;
143
144 bool zeroModTime = false;
145
146 llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
147
148 llvm::MachO::PlatformKind platform() const {
149 return platformInfo.target.Platform;
150 }
32 }; 151 };
33 152
34 // The symbol with the highest priority should be ordered first in the output 153 // The symbol with the highest priority should be ordered first in the output
35 // section (modulo input section contiguity constraints). Using priority 154 // section (modulo input section contiguity constraints). Using priority
36 // (highest first) instead of order (lowest first) has the convenient property 155 // (highest first) instead of order (lowest first) has the convenient property