blob: 2bb6a986b89a321858b80f27c59448d92dabecc7 [file] [log] [blame]
Rafael Espindolabeee25e2015-08-14 14:12:54 +00001//===- Config.h -------------------------------------------------*- C++ -*-===//
Rui Ueyama411c63602015-05-28 19:09:30 +00002//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLD_COFF_CONFIG_H
11#define LLD_COFF_CONFIG_H
12
13#include "llvm/ADT/StringRef.h"
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +000014#include "llvm/Object/COFF.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000015#include <cstdint>
Rui Ueyama8854d8a2015-06-04 19:21:24 +000016#include <map>
Rui Ueyama411c63602015-05-28 19:09:30 +000017#include <set>
18#include <string>
19
20namespace lld {
21namespace coff {
22
Rui Ueyamae16a75d52015-07-08 18:14:51 +000023using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
Rui Ueyama15cc47e2015-05-29 16:34:31 +000024using llvm::COFF::WindowsSubsystem;
Rui Ueyamad21b00b2015-05-31 19:17:14 +000025using llvm::StringRef;
Rui Ueyamacd3f99b2015-07-24 23:51:14 +000026class DefinedAbsolute;
27class DefinedRelative;
Rui Ueyama84425d72016-01-09 01:22:00 +000028class StringChunk;
Rui Ueyama6bf638e2015-07-02 00:04:14 +000029class Undefined;
Rui Ueyama15cc47e2015-05-29 16:34:31 +000030
Rui Ueyama35ccb0f2015-07-25 00:20:06 +000031// Short aliases.
32static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
Rui Ueyamaa265b012015-07-25 02:25:14 +000033static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
Rui Ueyama35ccb0f2015-07-25 00:20:06 +000034static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
35
Rui Ueyama97dff9e2015-06-17 00:16:33 +000036// Represents an /export option.
37struct Export {
Rui Ueyama9420dee2015-07-28 22:34:24 +000038 StringRef Name; // N in /export:N or /export:E=N
39 StringRef ExtName; // E in /export:E=N
Rui Ueyama6bf638e2015-07-02 00:04:14 +000040 Undefined *Sym = nullptr;
Rui Ueyama97dff9e2015-06-17 00:16:33 +000041 uint16_t Ordinal = 0;
42 bool Noname = false;
43 bool Data = false;
44 bool Private = false;
Rui Ueyama4b8cdd22015-07-03 23:23:29 +000045
Rui Ueyama84425d72016-01-09 01:22:00 +000046 // If an export is a form of /export:foo=dllname.bar, that means
47 // that foo should be exported as an alias to bar in the DLL.
48 // ForwardTo is set to "dllname.bar" part. Usually empty.
49 StringRef ForwardTo;
50 StringChunk *ForwardChunk = nullptr;
51
Rui Ueyamaf10a3202015-08-31 08:43:21 +000052 // True if this /export option was in .drectves section.
53 bool Directives = false;
54 StringRef SymbolName;
55 StringRef ExportName; // Name in DLL
56
Rui Ueyama4b8cdd22015-07-03 23:23:29 +000057 bool operator==(const Export &E) {
58 return (Name == E.Name && ExtName == E.ExtName &&
59 Ordinal == E.Ordinal && Noname == E.Noname &&
60 Data == E.Data && Private == E.Private);
61 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +000062};
63
Saleem Abdulrasoola2cca7e2016-08-08 22:02:44 +000064enum class DebugType {
65 None = 0x0,
66 CV = 0x1, /// CodeView
67 PData = 0x2, /// Procedure Data
68 Fixup = 0x4, /// Relocation Table
69};
70
Rui Ueyama97dff9e2015-06-17 00:16:33 +000071// Global configuration.
72struct Configuration {
Rui Ueyama24c5fd02015-06-18 00:12:42 +000073 enum ManifestKind { SideBySide, Embed, No };
Rui Ueyama5e706b32015-07-25 21:54:50 +000074 bool is64() { return Machine == AMD64; }
Rui Ueyama24c5fd02015-06-18 00:12:42 +000075
Rui Ueyama5e706b32015-07-25 21:54:50 +000076 llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN;
Rui Ueyama411c63602015-05-28 19:09:30 +000077 bool Verbose = false;
Rui Ueyama3ee0fe42015-05-31 03:55:46 +000078 WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
Rui Ueyama6bf638e2015-07-02 00:04:14 +000079 Undefined *Entry = nullptr;
Rui Ueyamaa8b60452015-06-28 19:56:30 +000080 bool NoEntry = false;
Rui Ueyamaad660982015-06-07 00:20:32 +000081 std::string OutputFile;
Rui Ueyamae2cbfea2015-06-07 03:17:42 +000082 bool DoGC = true;
Rui Ueyamab02a3202015-09-16 16:41:38 +000083 bool DoICF = true;
Rui Ueyama588e8322015-06-15 01:23:58 +000084 bool Relocatable = true;
Rui Ueyama95925fd2015-06-28 19:35:15 +000085 bool Force = false;
Rui Ueyama6600eb12015-07-04 23:37:32 +000086 bool Debug = false;
Rui Ueyama96401732015-09-21 23:43:31 +000087 bool WriteSymtab = true;
Saleem Abdulrasoola2cca7e2016-08-08 22:02:44 +000088 unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
Rui Ueyamaeb262ce2015-06-04 02:12:16 +000089
90 // Symbols in this set are considered as live by the garbage collector.
Rui Ueyama18f8d2c2015-07-02 00:21:08 +000091 std::set<Undefined *> GCRoot;
Rui Ueyamab41b7e52015-05-29 16:21:11 +000092
Rui Ueyamad21b00b2015-05-31 19:17:14 +000093 std::set<StringRef> NoDefaultLibs;
94 bool NoDefaultLibAll = false;
95
Rui Ueyama97dff9e2015-06-17 00:16:33 +000096 // True if we are creating a DLL.
97 bool DLL = false;
Rui Ueyamab95188c2015-06-18 20:27:09 +000098 StringRef Implib;
Rui Ueyama97dff9e2015-06-17 00:16:33 +000099 std::vector<Export> Exports;
Rui Ueyama7a247ee2015-07-03 01:40:14 +0000100 std::set<std::string> DelayLoads;
Rui Ueyamabfbd2772015-09-02 07:27:31 +0000101 std::map<std::string, int> DLLOrder;
Rui Ueyama6d249082015-07-13 22:31:45 +0000102 Undefined *DelayLoadHelper = nullptr;
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000103
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000104 // Used for SafeSEH.
105 DefinedRelative *SEHTable = nullptr;
106 DefinedAbsolute *SEHCount = nullptr;
107
Peter Collingbourne526ff152015-08-14 04:47:07 +0000108 // Used for /opt:lldlto=N
109 unsigned LTOOptLevel = 2;
110
Peter Collingbournedf5783b2015-08-28 22:16:09 +0000111 // Used for /opt:lldltojobs=N
112 unsigned LTOJobs = 1;
113
Rui Ueyama6600eb12015-07-04 23:37:32 +0000114 // Used for /merge:from=to (e.g. /merge:.rdata=.text)
115 std::map<StringRef, StringRef> Merge;
116
Rui Ueyama440138c2016-06-20 03:39:39 +0000117 // Used for /section=.name,{DEKPRSW} to set section attributes.
118 std::map<StringRef, uint32_t> Section;
119
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000120 // Options for manifest files.
121 ManifestKind Manifest = SideBySide;
122 int ManifestID = 1;
123 StringRef ManifestDependency;
124 bool ManifestUAC = true;
Rui Ueyamaafb19012016-04-19 01:21:58 +0000125 std::vector<std::string> ManifestInput;
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000126 StringRef ManifestLevel = "'asInvoker'";
127 StringRef ManifestUIAccess = "'false'";
128 StringRef ManifestFile;
129
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000130 // Used for /failifmismatch.
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000131 std::map<StringRef, StringRef> MustMatch;
132
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000133 // Used for /alternatename.
Rui Ueyamae8d56b52015-06-18 23:04:26 +0000134 std::map<StringRef, StringRef> AlternateNames;
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000135
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000136 uint64_t ImageBase = -1;
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000137 uint64_t StackReserve = 1024 * 1024;
138 uint64_t StackCommit = 4096;
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000139 uint64_t HeapReserve = 1024 * 1024;
140 uint64_t HeapCommit = 4096;
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000141 uint32_t MajorImageVersion = 0;
142 uint32_t MinorImageVersion = 0;
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000143 uint32_t MajorOSVersion = 6;
144 uint32_t MinorOSVersion = 0;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000145 bool DynamicBase = true;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000146 bool AllowBind = true;
147 bool NxCompat = true;
148 bool AllowIsolation = true;
149 bool TerminalServerAware = true;
Rui Ueyama4d545342015-07-28 03:12:00 +0000150 bool LargeAddressAware = false;
Rui Ueyamad68e2112015-07-28 03:15:57 +0000151 bool HighEntropyVA = false;
Rui Ueyama411c63602015-05-28 19:09:30 +0000152};
153
154extern Configuration *Config;
155
156} // namespace coff
157} // namespace lld
158
159#endif