| Rafael Espindola | beee25e | 2015-08-14 14:12:54 +0000 | [diff] [blame] | 1 | //===- Config.h -------------------------------------------------*- C++ -*-===// |
| Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 2 | // |
| 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 Ueyama | 3d3e6fb | 2015-05-29 16:06:00 +0000 | [diff] [blame] | 14 | #include "llvm/Object/COFF.h" |
| Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 15 | #include <cstdint> |
| Rui Ueyama | 8854d8a | 2015-06-04 19:21:24 +0000 | [diff] [blame] | 16 | #include <map> |
| Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 17 | #include <set> |
| 18 | #include <string> |
| 19 | |
| 20 | namespace lld { |
| 21 | namespace coff { |
| 22 | |
| Rui Ueyama | e16a75d5 | 2015-07-08 18:14:51 +0000 | [diff] [blame] | 23 | using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; |
| Rui Ueyama | 15cc47e | 2015-05-29 16:34:31 +0000 | [diff] [blame] | 24 | using llvm::COFF::WindowsSubsystem; |
| Rui Ueyama | d21b00b | 2015-05-31 19:17:14 +0000 | [diff] [blame] | 25 | using llvm::StringRef; |
| Rui Ueyama | cd3f99b | 2015-07-24 23:51:14 +0000 | [diff] [blame] | 26 | class DefinedAbsolute; |
| 27 | class DefinedRelative; |
| Rui Ueyama | 84425d7 | 2016-01-09 01:22:00 +0000 | [diff] [blame] | 28 | class StringChunk; |
| Peter Collingbourne | 79a5e6b | 2016-12-09 21:55:24 +0000 | [diff] [blame] | 29 | struct Symbol; |
| 30 | class SymbolBody; |
| Rui Ueyama | 15cc47e | 2015-05-29 16:34:31 +0000 | [diff] [blame] | 31 | |
| Rui Ueyama | 35ccb0f | 2015-07-25 00:20:06 +0000 | [diff] [blame] | 32 | // Short aliases. |
| 33 | static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64; |
| Rui Ueyama | a265b01 | 2015-07-25 02:25:14 +0000 | [diff] [blame] | 34 | static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT; |
| Rui Ueyama | 35ccb0f | 2015-07-25 00:20:06 +0000 | [diff] [blame] | 35 | static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386; |
| 36 | |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 37 | // Represents an /export option. |
| 38 | struct Export { |
| Rui Ueyama | 9420dee | 2015-07-28 22:34:24 +0000 | [diff] [blame] | 39 | StringRef Name; // N in /export:N or /export:E=N |
| 40 | StringRef ExtName; // E in /export:E=N |
| Peter Collingbourne | 79a5e6b | 2016-12-09 21:55:24 +0000 | [diff] [blame] | 41 | SymbolBody *Sym = nullptr; |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 42 | uint16_t Ordinal = 0; |
| 43 | bool Noname = false; |
| 44 | bool Data = false; |
| 45 | bool Private = false; |
| Rui Ueyama | 4b8cdd2 | 2015-07-03 23:23:29 +0000 | [diff] [blame] | 46 | |
| Rui Ueyama | 84425d7 | 2016-01-09 01:22:00 +0000 | [diff] [blame] | 47 | // If an export is a form of /export:foo=dllname.bar, that means |
| 48 | // that foo should be exported as an alias to bar in the DLL. |
| 49 | // ForwardTo is set to "dllname.bar" part. Usually empty. |
| 50 | StringRef ForwardTo; |
| 51 | StringChunk *ForwardChunk = nullptr; |
| 52 | |
| Rui Ueyama | f10a320 | 2015-08-31 08:43:21 +0000 | [diff] [blame] | 53 | // True if this /export option was in .drectves section. |
| 54 | bool Directives = false; |
| 55 | StringRef SymbolName; |
| 56 | StringRef ExportName; // Name in DLL |
| 57 | |
| Rui Ueyama | 4b8cdd2 | 2015-07-03 23:23:29 +0000 | [diff] [blame] | 58 | bool operator==(const Export &E) { |
| 59 | return (Name == E.Name && ExtName == E.ExtName && |
| 60 | Ordinal == E.Ordinal && Noname == E.Noname && |
| 61 | Data == E.Data && Private == E.Private); |
| 62 | } |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| Saleem Abdulrasool | a2cca7e | 2016-08-08 22:02:44 +0000 | [diff] [blame] | 65 | enum class DebugType { |
| 66 | None = 0x0, |
| 67 | CV = 0x1, /// CodeView |
| 68 | PData = 0x2, /// Procedure Data |
| 69 | Fixup = 0x4, /// Relocation Table |
| 70 | }; |
| 71 | |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 72 | // Global configuration. |
| 73 | struct Configuration { |
| Rui Ueyama | 24c5fd0 | 2015-06-18 00:12:42 +0000 | [diff] [blame] | 74 | enum ManifestKind { SideBySide, Embed, No }; |
| Rui Ueyama | 5e706b3 | 2015-07-25 21:54:50 +0000 | [diff] [blame] | 75 | bool is64() { return Machine == AMD64; } |
| Rui Ueyama | 24c5fd0 | 2015-06-18 00:12:42 +0000 | [diff] [blame] | 76 | |
| Rui Ueyama | 5e706b3 | 2015-07-25 21:54:50 +0000 | [diff] [blame] | 77 | llvm::COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN; |
| Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 78 | bool Verbose = false; |
| Rui Ueyama | 3ee0fe4 | 2015-05-31 03:55:46 +0000 | [diff] [blame] | 79 | WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN; |
| Peter Collingbourne | 79a5e6b | 2016-12-09 21:55:24 +0000 | [diff] [blame] | 80 | SymbolBody *Entry = nullptr; |
| Rui Ueyama | a8b6045 | 2015-06-28 19:56:30 +0000 | [diff] [blame] | 81 | bool NoEntry = false; |
| Rui Ueyama | ad66098 | 2015-06-07 00:20:32 +0000 | [diff] [blame] | 82 | std::string OutputFile; |
| Rui Ueyama | e2cbfea | 2015-06-07 03:17:42 +0000 | [diff] [blame] | 83 | bool DoGC = true; |
| Rui Ueyama | b02a320 | 2015-09-16 16:41:38 +0000 | [diff] [blame] | 84 | bool DoICF = true; |
| Rui Ueyama | 588e832 | 2015-06-15 01:23:58 +0000 | [diff] [blame] | 85 | bool Relocatable = true; |
| Rui Ueyama | 95925fd | 2015-06-28 19:35:15 +0000 | [diff] [blame] | 86 | bool Force = false; |
| Rui Ueyama | 6600eb1 | 2015-07-04 23:37:32 +0000 | [diff] [blame] | 87 | bool Debug = false; |
| Rui Ueyama | 9640173 | 2015-09-21 23:43:31 +0000 | [diff] [blame] | 88 | bool WriteSymtab = true; |
| Saleem Abdulrasool | a2cca7e | 2016-08-08 22:02:44 +0000 | [diff] [blame] | 89 | unsigned DebugTypes = static_cast<unsigned>(DebugType::None); |
| Saleem Abdulrasool | 8fcff93 | 2016-08-29 21:20:46 +0000 | [diff] [blame] | 90 | StringRef PDBPath; |
| Rui Ueyama | eb262ce | 2015-06-04 02:12:16 +0000 | [diff] [blame] | 91 | |
| 92 | // Symbols in this set are considered as live by the garbage collector. |
| Peter Collingbourne | 79a5e6b | 2016-12-09 21:55:24 +0000 | [diff] [blame] | 93 | std::set<SymbolBody *> GCRoot; |
| Rui Ueyama | b41b7e5 | 2015-05-29 16:21:11 +0000 | [diff] [blame] | 94 | |
| Rui Ueyama | d21b00b | 2015-05-31 19:17:14 +0000 | [diff] [blame] | 95 | std::set<StringRef> NoDefaultLibs; |
| 96 | bool NoDefaultLibAll = false; |
| 97 | |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 98 | // True if we are creating a DLL. |
| 99 | bool DLL = false; |
| Rui Ueyama | b95188c | 2015-06-18 20:27:09 +0000 | [diff] [blame] | 100 | StringRef Implib; |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 101 | std::vector<Export> Exports; |
| Rui Ueyama | 7a247ee | 2015-07-03 01:40:14 +0000 | [diff] [blame] | 102 | std::set<std::string> DelayLoads; |
| Rui Ueyama | bfbd277 | 2015-09-02 07:27:31 +0000 | [diff] [blame] | 103 | std::map<std::string, int> DLLOrder; |
| Peter Collingbourne | 79a5e6b | 2016-12-09 21:55:24 +0000 | [diff] [blame] | 104 | SymbolBody *DelayLoadHelper = nullptr; |
| Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 +0000 | [diff] [blame] | 105 | |
| Rui Ueyama | cd3f99b | 2015-07-24 23:51:14 +0000 | [diff] [blame] | 106 | // Used for SafeSEH. |
| Peter Collingbourne | 79a5e6b | 2016-12-09 21:55:24 +0000 | [diff] [blame] | 107 | Symbol *SEHTable = nullptr; |
| 108 | Symbol *SEHCount = nullptr; |
| Rui Ueyama | cd3f99b | 2015-07-24 23:51:14 +0000 | [diff] [blame] | 109 | |
| Peter Collingbourne | 526ff15 | 2015-08-14 04:47:07 +0000 | [diff] [blame] | 110 | // Used for /opt:lldlto=N |
| 111 | unsigned LTOOptLevel = 2; |
| 112 | |
| Peter Collingbourne | df5783b | 2015-08-28 22:16:09 +0000 | [diff] [blame] | 113 | // Used for /opt:lldltojobs=N |
| 114 | unsigned LTOJobs = 1; |
| 115 | |
| Rui Ueyama | 6600eb1 | 2015-07-04 23:37:32 +0000 | [diff] [blame] | 116 | // Used for /merge:from=to (e.g. /merge:.rdata=.text) |
| 117 | std::map<StringRef, StringRef> Merge; |
| 118 | |
| Rui Ueyama | 440138c | 2016-06-20 03:39:39 +0000 | [diff] [blame] | 119 | // Used for /section=.name,{DEKPRSW} to set section attributes. |
| 120 | std::map<StringRef, uint32_t> Section; |
| 121 | |
| Rui Ueyama | 24c5fd0 | 2015-06-18 00:12:42 +0000 | [diff] [blame] | 122 | // Options for manifest files. |
| 123 | ManifestKind Manifest = SideBySide; |
| 124 | int ManifestID = 1; |
| 125 | StringRef ManifestDependency; |
| 126 | bool ManifestUAC = true; |
| Rui Ueyama | afb1901 | 2016-04-19 01:21:58 +0000 | [diff] [blame] | 127 | std::vector<std::string> ManifestInput; |
| Rui Ueyama | 24c5fd0 | 2015-06-18 00:12:42 +0000 | [diff] [blame] | 128 | StringRef ManifestLevel = "'asInvoker'"; |
| 129 | StringRef ManifestUIAccess = "'false'"; |
| 130 | StringRef ManifestFile; |
| 131 | |
| Rui Ueyama | 2edb35a | 2015-06-18 19:09:30 +0000 | [diff] [blame] | 132 | // Used for /failifmismatch. |
| Rui Ueyama | 8854d8a | 2015-06-04 19:21:24 +0000 | [diff] [blame] | 133 | std::map<StringRef, StringRef> MustMatch; |
| 134 | |
| Rui Ueyama | 2edb35a | 2015-06-18 19:09:30 +0000 | [diff] [blame] | 135 | // Used for /alternatename. |
| Rui Ueyama | e8d56b5 | 2015-06-18 23:04:26 +0000 | [diff] [blame] | 136 | std::map<StringRef, StringRef> AlternateNames; |
| Rui Ueyama | 2edb35a | 2015-06-18 19:09:30 +0000 | [diff] [blame] | 137 | |
| Peter Collingbourne | 6f24fdb | 2017-01-14 03:14:46 +0000 | [diff] [blame^] | 138 | // Used for /lldmap. |
| 139 | std::string MapFile; |
| 140 | |
| Rui Ueyama | 5c437cd | 2015-07-25 21:42:33 +0000 | [diff] [blame] | 141 | uint64_t ImageBase = -1; |
| Rui Ueyama | b41b7e5 | 2015-05-29 16:21:11 +0000 | [diff] [blame] | 142 | uint64_t StackReserve = 1024 * 1024; |
| 143 | uint64_t StackCommit = 4096; |
| Rui Ueyama | c377e9a | 2015-05-29 16:23:40 +0000 | [diff] [blame] | 144 | uint64_t HeapReserve = 1024 * 1024; |
| 145 | uint64_t HeapCommit = 4096; |
| Rui Ueyama | b9dcdb5 | 2015-05-29 16:28:29 +0000 | [diff] [blame] | 146 | uint32_t MajorImageVersion = 0; |
| 147 | uint32_t MinorImageVersion = 0; |
| Rui Ueyama | 15cc47e | 2015-05-29 16:34:31 +0000 | [diff] [blame] | 148 | uint32_t MajorOSVersion = 6; |
| 149 | uint32_t MinorOSVersion = 0; |
| Rui Ueyama | 6592ff8 | 2015-06-16 23:13:00 +0000 | [diff] [blame] | 150 | bool DynamicBase = true; |
| Rui Ueyama | 6592ff8 | 2015-06-16 23:13:00 +0000 | [diff] [blame] | 151 | bool AllowBind = true; |
| 152 | bool NxCompat = true; |
| 153 | bool AllowIsolation = true; |
| 154 | bool TerminalServerAware = true; |
| Rui Ueyama | 4d54534 | 2015-07-28 03:12:00 +0000 | [diff] [blame] | 155 | bool LargeAddressAware = false; |
| Rui Ueyama | d68e211 | 2015-07-28 03:15:57 +0000 | [diff] [blame] | 156 | bool HighEntropyVA = false; |
| Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 157 | |
| 158 | // This is for debugging. |
| Rui Ueyama | 327705d | 2016-12-10 17:23:23 +0000 | [diff] [blame] | 159 | bool DebugPdb = false; |
| Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 160 | bool DumpPdb = false; |
| Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | extern Configuration *Config; |
| 164 | |
| 165 | } // namespace coff |
| 166 | } // namespace lld |
| 167 | |
| 168 | #endif |