Config.h 4.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//===- Config.h -------------------------------------------------*- C++ -*-===//
//
//                             The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef LLD_COFF_CONFIG_H
#define LLD_COFF_CONFIG_H

#include "llvm/ADT/StringRef.h"
#include "llvm/Object/COFF.h"
15
#include "llvm/Support/CachePruning.h"
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <cstdint>
#include <map>
#include <set>
#include <string>

namespace lld {
namespace coff {

using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
using llvm::COFF::WindowsSubsystem;
using llvm::StringRef;
class DefinedAbsolute;
class DefinedRelative;
29
class StringChunk;
30
class Symbol;
31
32
33

// Short aliases.
static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
34
static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
35
36
37
38
39
40
41
static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;

// Represents an /export option.
struct Export {
  StringRef Name;       // N in /export:N or /export:E=N
  StringRef ExtName;    // E in /export:E=N
42
  Symbol *Sym = nullptr;
43
44
45
46
  uint16_t Ordinal = 0;
  bool Noname = false;
  bool Data = false;
  bool Private = false;
47
  bool Constant = false;
48

49
50
51
52
53
54
  // If an export is a form of /export:foo=dllname.bar, that means
  // that foo should be exported as an alias to bar in the DLL.
  // ForwardTo is set to "dllname.bar" part. Usually empty.
  StringRef ForwardTo;
  StringChunk *ForwardChunk = nullptr;

55
56
57
58
59
60
61
62
63
64
65
66
  // True if this /export option was in .drectves section.
  bool Directives = false;
  StringRef SymbolName;
  StringRef ExportName; // Name in DLL

  bool operator==(const Export &E) {
    return (Name == E.Name && ExtName == E.ExtName &&
            Ordinal == E.Ordinal && Noname == E.Noname &&
            Data == E.Data && Private == E.Private);
  }
};

67
68
69
70
71
72
73
enum class DebugType {
  None  = 0x0,
  CV    = 0x1,  /// CodeView
  PData = 0x2,  /// Procedure Data
  Fixup = 0x4,  /// Relocation Table
};

74
75
76
// Global configuration.
struct Configuration {
  enum ManifestKind { SideBySide, Embed, No };
77
  bool is64() { return Machine == AMD64 || Machine == ARM64; }
78
79
80
81

  llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN;
  bool Verbose = false;
  WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
82
  Symbol *Entry = nullptr;
83
84
  bool NoEntry = false;
  std::string OutputFile;
85
  std::string ImportName;
86
87
88
89
90
  bool DoGC = true;
  bool DoICF = true;
  bool Relocatable = true;
  bool Force = false;
  bool Debug = false;
91
92
  bool DebugDwarf = false;
  bool DebugGHashes = false;
93
  unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
94
  llvm::SmallString<128> PDBPath;
95
  std::vector<llvm::StringRef> Argv;
96
97

  // Symbols in this set are considered as live by the garbage collector.
98
  std::vector<Symbol *> GCRoot;
99
100
101
102
103
104
105
106
107
108

  std::set<StringRef> NoDefaultLibs;
  bool NoDefaultLibAll = false;

  // True if we are creating a DLL.
  bool DLL = false;
  StringRef Implib;
  std::vector<Export> Exports;
  std::set<std::string> DelayLoads;
  std::map<std::string, int> DLLOrder;
109
  Symbol *DelayLoadHelper = nullptr;
110

111
112
  bool SaveTemps = false;

113
  // Used for SafeSEH.
114
115
  Symbol *SEHTable = nullptr;
  Symbol *SEHCount = nullptr;
116
117
118
119
120

  // Used for /opt:lldlto=N
  unsigned LTOOptLevel = 2;

  // Used for /opt:lldltojobs=N
121
122
123
  unsigned LTOJobs = 0;
  // Used for /opt:lldltopartitions=N
  unsigned LTOPartitions = 1;
124

125
126
127
128
129
  // Used for /opt:lldltocache=path
  StringRef LTOCache;
  // Used for /opt:lldltocachepolicy=policy
  llvm::CachePruningPolicy LTOCachePolicy;

130
131
132
  // Used for /merge:from=to (e.g. /merge:.rdata=.text)
  std::map<StringRef, StringRef> Merge;

133
134
135
  // Used for /section=.name,{DEKPRSW} to set section attributes.
  std::map<StringRef, uint32_t> Section;

136
  // Options for manifest files.
137
  ManifestKind Manifest = No;
138
139
140
  int ManifestID = 1;
  StringRef ManifestDependency;
  bool ManifestUAC = true;
141
  std::vector<std::string> ManifestInput;
142
143
144
145
  StringRef ManifestLevel = "'asInvoker'";
  StringRef ManifestUIAccess = "'false'";
  StringRef ManifestFile;

146
147
148
  // Used for /aligncomm.
  std::map<std::string, int> AlignComm;

149
150
151
152
153
154
  // Used for /failifmismatch.
  std::map<StringRef, StringRef> MustMatch;

  // Used for /alternatename.
  std::map<StringRef, StringRef> AlternateNames;

155
156
157
  // Used for /lldmap.
  std::string MapFile;

158
159
160
161
162
163
164
165
166
  uint64_t ImageBase = -1;
  uint64_t StackReserve = 1024 * 1024;
  uint64_t StackCommit = 4096;
  uint64_t HeapReserve = 1024 * 1024;
  uint64_t HeapCommit = 4096;
  uint32_t MajorImageVersion = 0;
  uint32_t MinorImageVersion = 0;
  uint32_t MajorOSVersion = 6;
  uint32_t MinorOSVersion = 0;
167
  bool CanExitEarly = false;
168
  bool DynamicBase = true;
169
  bool AllowBind = true;
170
171
172
173
174
  bool NxCompat = true;
  bool AllowIsolation = true;
  bool TerminalServerAware = true;
  bool LargeAddressAware = false;
  bool HighEntropyVA = false;
175
  bool AppContainer = false;
176
  bool MinGW = false;
177
178
179
180
181
182
183
184
};

extern Configuration *Config;

} // namespace coff
} // namespace lld

#endif