blob: 088e5369e909452f1894e6c2169af3f50965de1b [file] [log] [blame]
Rui Ueyama411c63602015-05-28 19:09:30 +00001//===- Driver.cpp ---------------------------------------------------------===//
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#include "Config.h"
11#include "Driver.h"
Rui Ueyama562daa82015-06-18 21:50:38 +000012#include "Error.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000013#include "InputFiles.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000014#include "SymbolTable.h"
Rui Ueyama685c41c2015-08-05 23:43:53 +000015#include "Symbols.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000016#include "Writer.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000017#include "llvm/ADT/Optional.h"
18#include "llvm/ADT/STLExtras.h"
Rui Ueyama3ee0fe42015-05-31 03:55:46 +000019#include "llvm/ADT/StringSwitch.h"
Peter Collingbournebd1cb792015-06-09 21:52:48 +000020#include "llvm/LibDriver/LibDriver.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000021#include "llvm/Option/Arg.h"
22#include "llvm/Option/ArgList.h"
23#include "llvm/Option/Option.h"
24#include "llvm/Support/CommandLine.h"
25#include "llvm/Support/Debug.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000026#include "llvm/Support/Path.h"
Rui Ueyama54b71da2015-05-31 19:17:12 +000027#include "llvm/Support/Process.h"
Peter Collingbourne60c16162015-06-01 20:10:10 +000028#include "llvm/Support/TargetSelect.h"
Rui Ueyama411c63602015-05-28 19:09:30 +000029#include "llvm/Support/raw_ostream.h"
Rui Ueyama2bf6a122015-06-14 21:50:50 +000030#include <algorithm>
Rui Ueyama411c63602015-05-28 19:09:30 +000031#include <memory>
32
33using namespace llvm;
Rui Ueyama84936e02015-07-07 23:39:18 +000034using namespace llvm::COFF;
Rui Ueyama54b71da2015-05-31 19:17:12 +000035using llvm::sys::Process;
Peter Collingbournebaf5f872015-06-26 19:20:09 +000036using llvm::sys::fs::OpenFlags;
Rui Ueyama711cd2d2015-05-31 21:17:10 +000037using llvm::sys::fs::file_magic;
38using llvm::sys::fs::identify_magic;
Rui Ueyama411c63602015-05-28 19:09:30 +000039
Rui Ueyama3500f662015-05-28 20:30:06 +000040namespace lld {
41namespace coff {
Rui Ueyama411c63602015-05-28 19:09:30 +000042
Rui Ueyama3500f662015-05-28 20:30:06 +000043Configuration *Config;
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000044LinkerDriver *Driver;
45
David Blaikie00818192015-06-22 22:06:48 +000046bool link(llvm::ArrayRef<const char *> Args) {
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000047 auto C = make_unique<Configuration>();
48 Config = C.get();
49 auto D = make_unique<LinkerDriver>();
50 Driver = D.get();
David Blaikieb2b1c7c2015-06-21 06:32:10 +000051 return Driver->link(Args);
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000052}
Rui Ueyama411c63602015-05-28 19:09:30 +000053
Rui Ueyamaad660982015-06-07 00:20:32 +000054// Drop directory components and replace extension with ".exe".
55static std::string getOutputPath(StringRef Path) {
56 auto P = Path.find_last_of("\\/");
57 StringRef S = (P == StringRef::npos) ? Path : Path.substr(P + 1);
58 return (S.substr(0, S.rfind('.')) + ".exe").str();
Rui Ueyama411c63602015-05-28 19:09:30 +000059}
60
Rui Ueyamad7c2f582015-05-31 21:04:56 +000061// Opens a file. Path has to be resolved already.
62// Newly created memory buffers are owned by this driver.
Rui Ueyama2bf6a122015-06-14 21:50:50 +000063ErrorOr<MemoryBufferRef> LinkerDriver::openFile(StringRef Path) {
Rui Ueyamad7c2f582015-05-31 21:04:56 +000064 auto MBOrErr = MemoryBuffer::getFile(Path);
65 if (auto EC = MBOrErr.getError())
66 return EC;
67 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
68 MemoryBufferRef MBRef = MB->getMemBufferRef();
69 OwningMBs.push_back(std::move(MB)); // take ownership
Rui Ueyama2bf6a122015-06-14 21:50:50 +000070 return MBRef;
71}
Rui Ueyama711cd2d2015-05-31 21:17:10 +000072
Rui Ueyama2bf6a122015-06-14 21:50:50 +000073static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
Rui Ueyama711cd2d2015-05-31 21:17:10 +000074 // File type is detected by contents, not by file extension.
Rui Ueyama2bf6a122015-06-14 21:50:50 +000075 file_magic Magic = identify_magic(MB.getBuffer());
Rui Ueyama711cd2d2015-05-31 21:17:10 +000076 if (Magic == file_magic::archive)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000077 return std::unique_ptr<InputFile>(new ArchiveFile(MB));
Peter Collingbourne60c16162015-06-01 20:10:10 +000078 if (Magic == file_magic::bitcode)
Rui Ueyama2bf6a122015-06-14 21:50:50 +000079 return std::unique_ptr<InputFile>(new BitcodeFile(MB));
Rui Ueyamaad660982015-06-07 00:20:32 +000080 if (Config->OutputFile == "")
Rui Ueyama2bf6a122015-06-14 21:50:50 +000081 Config->OutputFile = getOutputPath(MB.getBufferIdentifier());
82 return std::unique_ptr<InputFile>(new ObjectFile(MB));
Rui Ueyama411c63602015-05-28 19:09:30 +000083}
84
Rui Ueyama411c63602015-05-28 19:09:30 +000085// Parses .drectve section contents and returns a list of files
86// specified by /defaultlib.
Rui Ueyamaa9cbbf82015-05-31 19:17:09 +000087std::error_code
Rui Ueyama0d2e9992015-06-23 23:56:39 +000088LinkerDriver::parseDirectives(StringRef S) {
Rui Ueyama115d7c12015-06-07 02:55:19 +000089 auto ArgsOrErr = Parser.parse(S);
Rui Ueyama411c63602015-05-28 19:09:30 +000090 if (auto EC = ArgsOrErr.getError())
91 return EC;
David Blaikie6521ed92015-06-22 22:06:52 +000092 llvm::opt::InputArgList Args = std::move(ArgsOrErr.get());
Rui Ueyama411c63602015-05-28 19:09:30 +000093
David Blaikie6521ed92015-06-22 22:06:52 +000094 for (auto *Arg : Args) {
Rui Ueyama562daa82015-06-18 21:50:38 +000095 switch (Arg->getOption().getID()) {
96 case OPT_alternatename:
97 if (auto EC = parseAlternateName(Arg->getValue()))
Rui Ueyamad7c2f582015-05-31 21:04:56 +000098 return EC;
Rui Ueyama562daa82015-06-18 21:50:38 +000099 break;
100 case OPT_defaultlib:
101 if (Optional<StringRef> Path = findLib(Arg->getValue())) {
102 ErrorOr<MemoryBufferRef> MBOrErr = openFile(*Path);
103 if (auto EC = MBOrErr.getError())
104 return EC;
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000105 Symtab.addFile(createFile(MBOrErr.get()));
Rui Ueyama562daa82015-06-18 21:50:38 +0000106 }
107 break;
108 case OPT_export: {
109 ErrorOr<Export> E = parseExport(Arg->getValue());
110 if (auto EC = E.getError())
111 return EC;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000112 if (Config->Machine == I386 && E->ExtName.startswith("_"))
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000113 E->ExtName = E->ExtName.substr(1);
Rui Ueyama562daa82015-06-18 21:50:38 +0000114 Config->Exports.push_back(E.get());
115 break;
116 }
117 case OPT_failifmismatch:
118 if (auto EC = checkFailIfMismatch(Arg->getValue()))
119 return EC;
120 break;
Rui Ueyama08d5e182015-06-18 23:20:11 +0000121 case OPT_incl:
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000122 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000123 break;
Rui Ueyamace86c992015-06-18 23:22:39 +0000124 case OPT_merge:
Rui Ueyama6600eb12015-07-04 23:37:32 +0000125 if (auto EC = parseMerge(Arg->getValue()))
126 return EC;
Rui Ueyamace86c992015-06-18 23:22:39 +0000127 break;
128 case OPT_nodefaultlib:
129 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
130 break;
Rui Ueyama432383172015-07-29 21:01:15 +0000131 case OPT_throwingnew:
Rui Ueyama46682632015-07-29 20:29:15 +0000132 break;
Rui Ueyama562daa82015-06-18 21:50:38 +0000133 default:
134 llvm::errs() << Arg->getSpelling() << " is not allowed in .drectve\n";
135 return make_error_code(LLDError::InvalidOption);
Rui Ueyamad7c2f582015-05-31 21:04:56 +0000136 }
137 }
Rui Ueyama411c63602015-05-28 19:09:30 +0000138 return std::error_code();
139}
140
Rui Ueyama54b71da2015-05-31 19:17:12 +0000141// Find file from search paths. You can omit ".obj", this function takes
142// care of that. Note that the returned path is not guaranteed to exist.
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000143StringRef LinkerDriver::doFindFile(StringRef Filename) {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000144 bool hasPathSep = (Filename.find_first_of("/\\") != StringRef::npos);
145 if (hasPathSep)
146 return Filename;
147 bool hasExt = (Filename.find('.') != StringRef::npos);
148 for (StringRef Dir : SearchPaths) {
149 SmallString<128> Path = Dir;
150 llvm::sys::path::append(Path, Filename);
151 if (llvm::sys::fs::exists(Path.str()))
152 return Alloc.save(Path.str());
153 if (!hasExt) {
154 Path.append(".obj");
155 if (llvm::sys::fs::exists(Path.str()))
156 return Alloc.save(Path.str());
157 }
158 }
159 return Filename;
160}
161
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000162// Resolves a file path. This never returns the same path
163// (in that case, it returns None).
164Optional<StringRef> LinkerDriver::findFile(StringRef Filename) {
165 StringRef Path = doFindFile(Filename);
166 bool Seen = !VisitedFiles.insert(Path.lower()).second;
167 if (Seen)
168 return None;
169 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000170}
171
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000172// Find library file from search path.
173StringRef LinkerDriver::doFindLib(StringRef Filename) {
174 // Add ".lib" to Filename if that has no file extension.
Rui Ueyama54b71da2015-05-31 19:17:12 +0000175 bool hasExt = (Filename.find('.') != StringRef::npos);
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000176 if (!hasExt)
177 Filename = Alloc.save(Filename + ".lib");
178 return doFindFile(Filename);
179}
180
181// Resolves a library path. /nodefaultlib options are taken into
182// consideration. This never returns the same path (in that case,
183// it returns None).
184Optional<StringRef> LinkerDriver::findLib(StringRef Filename) {
185 if (Config->NoDefaultLibAll)
186 return None;
187 StringRef Path = doFindLib(Filename);
188 if (Config->NoDefaultLibs.count(Path))
189 return None;
190 bool Seen = !VisitedFiles.insert(Path.lower()).second;
191 if (Seen)
192 return None;
193 return Path;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000194}
195
196// Parses LIB environment which contains a list of search paths.
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000197void LinkerDriver::addLibSearchPaths() {
Rui Ueyama54b71da2015-05-31 19:17:12 +0000198 Optional<std::string> EnvOpt = Process::GetEnv("LIB");
199 if (!EnvOpt.hasValue())
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000200 return;
Rui Ueyama54b71da2015-05-31 19:17:12 +0000201 StringRef Env = Alloc.save(*EnvOpt);
202 while (!Env.empty()) {
203 StringRef Path;
204 std::tie(Path, Env) = Env.split(';');
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000205 SearchPaths.push_back(Path);
Rui Ueyama54b71da2015-05-31 19:17:12 +0000206 }
Rui Ueyama54b71da2015-05-31 19:17:12 +0000207}
208
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000209Undefined *LinkerDriver::addUndefined(StringRef Name) {
210 Undefined *U = Symtab.addUndefined(Name);
Rui Ueyama18f8d2c2015-07-02 00:21:08 +0000211 Config->GCRoot.insert(U);
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000212 return U;
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000213}
214
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000215// Symbol names are mangled by appending "_" prefix on x86.
216StringRef LinkerDriver::mangle(StringRef Sym) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000217 assert(Config->Machine != IMAGE_FILE_MACHINE_UNKNOWN);
218 if (Config->Machine == I386)
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000219 return Alloc.save("_" + Sym);
220 return Sym;
221}
222
Rui Ueyama45044f42015-06-29 01:03:53 +0000223// Windows specific -- find default entry point name.
224StringRef LinkerDriver::findDefaultEntry() {
225 // User-defined main functions and their corresponding entry points.
226 static const char *Entries[][2] = {
227 {"main", "mainCRTStartup"},
228 {"wmain", "wmainCRTStartup"},
229 {"WinMain", "WinMainCRTStartup"},
230 {"wWinMain", "wWinMainCRTStartup"},
231 };
232 for (auto E : Entries) {
Rui Ueyamaa50387f2015-07-14 02:58:13 +0000233 StringRef Entry = Symtab.findMangle(mangle(E[0]));
234 if (!Entry.empty() && !isa<Undefined>(Symtab.find(Entry)->Body))
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000235 return mangle(E[1]);
Rui Ueyama45044f42015-06-29 01:03:53 +0000236 }
237 return "";
238}
239
240WindowsSubsystem LinkerDriver::inferSubsystem() {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000241 if (Config->DLL)
242 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000243 if (Symtab.find(mangle("main")) || Symtab.find(mangle("wmain")))
Rui Ueyama45044f42015-06-29 01:03:53 +0000244 return IMAGE_SUBSYSTEM_WINDOWS_CUI;
Rui Ueyama7c3e23f2015-07-09 01:25:49 +0000245 if (Symtab.find(mangle("WinMain")) || Symtab.find(mangle("wWinMain")))
Rui Ueyama45044f42015-06-29 01:03:53 +0000246 return IMAGE_SUBSYSTEM_WINDOWS_GUI;
247 return IMAGE_SUBSYSTEM_UNKNOWN;
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000248}
249
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000250static uint64_t getDefaultImageBase() {
251 if (Config->is64())
252 return Config->DLL ? 0x180000000 : 0x140000000;
253 return Config->DLL ? 0x10000000 : 0x400000;
254}
255
David Blaikie00818192015-06-22 22:06:48 +0000256bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
Peter Collingbourne60c16162015-06-01 20:10:10 +0000257 // Needed for LTO.
258 llvm::InitializeAllTargetInfos();
259 llvm::InitializeAllTargets();
260 llvm::InitializeAllTargetMCs();
261 llvm::InitializeAllAsmParsers();
262 llvm::InitializeAllAsmPrinters();
263 llvm::InitializeAllDisassemblers();
264
Peter Collingbournebd1cb792015-06-09 21:52:48 +0000265 // If the first command line argument is "/lib", link.exe acts like lib.exe.
266 // We call our own implementation of lib.exe that understands bitcode files.
David Blaikieb2b1c7c2015-06-21 06:32:10 +0000267 if (ArgsArr.size() > 1 && StringRef(ArgsArr[1]).equals_lower("/lib"))
268 return llvm::libDriverMain(ArgsArr.slice(1)) == 0;
Peter Collingbournebd1cb792015-06-09 21:52:48 +0000269
Rui Ueyama411c63602015-05-28 19:09:30 +0000270 // Parse command line options.
Rui Ueyama9d72f092015-06-28 03:05:38 +0000271 auto ArgsOrErr = Parser.parseLINK(ArgsArr.slice(1));
Rui Ueyama411c63602015-05-28 19:09:30 +0000272 if (auto EC = ArgsOrErr.getError()) {
273 llvm::errs() << EC.message() << "\n";
274 return false;
275 }
David Blaikie6521ed92015-06-22 22:06:52 +0000276 llvm::opt::InputArgList Args = std::move(ArgsOrErr.get());
Rui Ueyama411c63602015-05-28 19:09:30 +0000277
Rui Ueyama5c726432015-05-29 16:11:52 +0000278 // Handle /help
David Blaikie6521ed92015-06-22 22:06:52 +0000279 if (Args.hasArg(OPT_help)) {
David Blaikieb2b1c7c2015-06-21 06:32:10 +0000280 printHelp(ArgsArr[0]);
Rui Ueyama5c726432015-05-29 16:11:52 +0000281 return true;
282 }
283
David Blaikie6521ed92015-06-22 22:06:52 +0000284 if (Args.filtered_begin(OPT_INPUT) == Args.filtered_end()) {
Rui Ueyama411c63602015-05-28 19:09:30 +0000285 llvm::errs() << "no input files.\n";
286 return false;
287 }
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000288
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000289 // Construct search path list.
290 SearchPaths.push_back("");
David Blaikie6521ed92015-06-22 22:06:52 +0000291 for (auto *Arg : Args.filtered(OPT_libpath))
Rui Ueyamaf00df0a2015-06-19 22:39:48 +0000292 SearchPaths.push_back(Arg->getValue());
293 addLibSearchPaths();
294
Rui Ueyamaad660982015-06-07 00:20:32 +0000295 // Handle /out
David Blaikie6521ed92015-06-22 22:06:52 +0000296 if (auto *Arg = Args.getLastArg(OPT_out))
Rui Ueyamaad660982015-06-07 00:20:32 +0000297 Config->OutputFile = Arg->getValue();
298
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000299 // Handle /verbose
David Blaikie6521ed92015-06-22 22:06:52 +0000300 if (Args.hasArg(OPT_verbose))
Rui Ueyama411c63602015-05-28 19:09:30 +0000301 Config->Verbose = true;
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000302
Rui Ueyama95925fd2015-06-28 19:35:15 +0000303 // Handle /force or /force:unresolved
304 if (Args.hasArg(OPT_force) || Args.hasArg(OPT_force_unresolved))
305 Config->Force = true;
306
Rui Ueyama6600eb12015-07-04 23:37:32 +0000307 // Handle /debug
308 if (Args.hasArg(OPT_debug))
309 Config->Debug = true;
310
Rui Ueyamaa8b60452015-06-28 19:56:30 +0000311 // Handle /noentry
312 if (Args.hasArg(OPT_noentry)) {
313 if (!Args.hasArg(OPT_dll)) {
314 llvm::errs() << "/noentry must be specified with /dll\n";
315 return false;
316 }
317 Config->NoEntry = true;
318 }
319
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000320 // Handle /dll
David Blaikie6521ed92015-06-22 22:06:52 +0000321 if (Args.hasArg(OPT_dll)) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000322 Config->DLL = true;
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000323 Config->ManifestID = 2;
324 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000325
Rui Ueyama588e8322015-06-15 01:23:58 +0000326 // Handle /fixed
David Blaikie6521ed92015-06-22 22:06:52 +0000327 if (Args.hasArg(OPT_fixed)) {
328 if (Args.hasArg(OPT_dynamicbase)) {
Rui Ueyama6592ff82015-06-16 23:13:00 +0000329 llvm::errs() << "/fixed must not be specified with /dynamicbase\n";
330 return false;
331 }
Rui Ueyama588e8322015-06-15 01:23:58 +0000332 Config->Relocatable = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000333 Config->DynamicBase = false;
334 }
Rui Ueyama588e8322015-06-15 01:23:58 +0000335
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000336 // Handle /machine
Rui Ueyamae16a75d52015-07-08 18:14:51 +0000337 if (auto *Arg = Args.getLastArg(OPT_machine)) {
338 ErrorOr<MachineTypes> MTOrErr = getMachineType(Arg->getValue());
339 if (MTOrErr.getError())
340 return false;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000341 Config->Machine = MTOrErr.get();
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000342 }
Rui Ueyama3d3e6fb2015-05-29 16:06:00 +0000343
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000344 // Handle /nodefaultlib:<filename>
David Blaikie6521ed92015-06-22 22:06:52 +0000345 for (auto *Arg : Args.filtered(OPT_nodefaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000346 Config->NoDefaultLibs.insert(doFindLib(Arg->getValue()));
347
348 // Handle /nodefaultlib
David Blaikie6521ed92015-06-22 22:06:52 +0000349 if (Args.hasArg(OPT_nodefaultlib_all))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000350 Config->NoDefaultLibAll = true;
351
Rui Ueyama804a8b62015-05-29 16:18:15 +0000352 // Handle /base
David Blaikie6521ed92015-06-22 22:06:52 +0000353 if (auto *Arg = Args.getLastArg(OPT_base)) {
Rui Ueyama804a8b62015-05-29 16:18:15 +0000354 if (auto EC = parseNumbers(Arg->getValue(), &Config->ImageBase)) {
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000355 llvm::errs() << "/base: " << EC.message() << "\n";
356 return false;
357 }
358 }
359
360 // Handle /stack
David Blaikie6521ed92015-06-22 22:06:52 +0000361 if (auto *Arg = Args.getLastArg(OPT_stack)) {
Rui Ueyamab41b7e52015-05-29 16:21:11 +0000362 if (auto EC = parseNumbers(Arg->getValue(), &Config->StackReserve,
363 &Config->StackCommit)) {
364 llvm::errs() << "/stack: " << EC.message() << "\n";
Rui Ueyama804a8b62015-05-29 16:18:15 +0000365 return false;
366 }
367 }
368
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000369 // Handle /heap
David Blaikie6521ed92015-06-22 22:06:52 +0000370 if (auto *Arg = Args.getLastArg(OPT_heap)) {
Rui Ueyamac377e9a2015-05-29 16:23:40 +0000371 if (auto EC = parseNumbers(Arg->getValue(), &Config->HeapReserve,
372 &Config->HeapCommit)) {
373 llvm::errs() << "/heap: " << EC.message() << "\n";
374 return false;
375 }
376 }
377
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000378 // Handle /version
David Blaikie6521ed92015-06-22 22:06:52 +0000379 if (auto *Arg = Args.getLastArg(OPT_version)) {
Rui Ueyamab9dcdb52015-05-29 16:28:29 +0000380 if (auto EC = parseVersion(Arg->getValue(), &Config->MajorImageVersion,
381 &Config->MinorImageVersion)) {
382 llvm::errs() << "/version: " << EC.message() << "\n";
383 return false;
384 }
385 }
386
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000387 // Handle /subsystem
David Blaikie6521ed92015-06-22 22:06:52 +0000388 if (auto *Arg = Args.getLastArg(OPT_subsystem)) {
Rui Ueyama15cc47e2015-05-29 16:34:31 +0000389 if (auto EC = parseSubsystem(Arg->getValue(), &Config->Subsystem,
390 &Config->MajorOSVersion,
391 &Config->MinorOSVersion)) {
392 llvm::errs() << "/subsystem: " << EC.message() << "\n";
393 return false;
394 }
395 }
396
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000397 // Handle /alternatename
David Blaikie6521ed92015-06-22 22:06:52 +0000398 for (auto *Arg : Args.filtered(OPT_alternatename))
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000399 if (parseAlternateName(Arg->getValue()))
400 return false;
401
Rui Ueyama08d5e182015-06-18 23:20:11 +0000402 // Handle /include
David Blaikie6521ed92015-06-22 22:06:52 +0000403 for (auto *Arg : Args.filtered(OPT_incl))
Rui Ueyama32f8e1c2015-06-26 03:44:00 +0000404 addUndefined(Arg->getValue());
Rui Ueyama08d5e182015-06-18 23:20:11 +0000405
Rui Ueyamab95188c2015-06-18 20:27:09 +0000406 // Handle /implib
David Blaikie6521ed92015-06-22 22:06:52 +0000407 if (auto *Arg = Args.getLastArg(OPT_implib))
Rui Ueyamab95188c2015-06-18 20:27:09 +0000408 Config->Implib = Arg->getValue();
409
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000410 // Handle /opt
David Blaikie6521ed92015-06-22 22:06:52 +0000411 for (auto *Arg : Args.filtered(OPT_opt)) {
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000412 std::string S = StringRef(Arg->getValue()).lower();
413 if (S == "noref") {
414 Config->DoGC = false;
415 continue;
416 }
Rui Ueyamaf799ede2015-06-25 23:26:58 +0000417 if (S == "lldicf") {
Rui Ueyamaddf71fc2015-06-24 04:36:52 +0000418 Config->ICF = true;
419 continue;
420 }
Rui Ueyamae2cbfea2015-06-07 03:17:42 +0000421 if (S != "ref" && S != "icf" && S != "noicf" &&
422 S != "lbr" && S != "nolbr" &&
423 !StringRef(S).startswith("icf=")) {
424 llvm::errs() << "/opt: unknown option: " << S << "\n";
425 return false;
426 }
427 }
428
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000429 // Handle /failifmismatch
David Blaikie6521ed92015-06-22 22:06:52 +0000430 for (auto *Arg : Args.filtered(OPT_failifmismatch))
Rui Ueyama75b098b2015-06-18 21:23:34 +0000431 if (checkFailIfMismatch(Arg->getValue()))
432 return false;
Rui Ueyama8854d8a2015-06-04 19:21:24 +0000433
Rui Ueyama6600eb12015-07-04 23:37:32 +0000434 // Handle /merge
435 for (auto *Arg : Args.filtered(OPT_merge))
436 if (parseMerge(Arg->getValue()))
437 return false;
438
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000439 // Handle /manifest
David Blaikie6521ed92015-06-22 22:06:52 +0000440 if (auto *Arg = Args.getLastArg(OPT_manifest_colon)) {
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000441 if (auto EC = parseManifest(Arg->getValue())) {
442 llvm::errs() << "/manifest: " << EC.message() << "\n";
443 return false;
444 }
445 }
446
447 // Handle /manifestuac
David Blaikie6521ed92015-06-22 22:06:52 +0000448 if (auto *Arg = Args.getLastArg(OPT_manifestuac)) {
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000449 if (auto EC = parseManifestUAC(Arg->getValue())) {
450 llvm::errs() << "/manifestuac: " << EC.message() << "\n";
451 return false;
452 }
453 }
454
455 // Handle /manifestdependency
David Blaikie6521ed92015-06-22 22:06:52 +0000456 if (auto *Arg = Args.getLastArg(OPT_manifestdependency))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000457 Config->ManifestDependency = Arg->getValue();
458
459 // Handle /manifestfile
David Blaikie6521ed92015-06-22 22:06:52 +0000460 if (auto *Arg = Args.getLastArg(OPT_manifestfile))
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000461 Config->ManifestFile = Arg->getValue();
462
Rui Ueyama6592ff82015-06-16 23:13:00 +0000463 // Handle miscellaneous boolean flags.
David Blaikie6521ed92015-06-22 22:06:52 +0000464 if (Args.hasArg(OPT_allowbind_no))
465 Config->AllowBind = false;
466 if (Args.hasArg(OPT_allowisolation_no))
467 Config->AllowIsolation = false;
468 if (Args.hasArg(OPT_dynamicbase_no))
469 Config->DynamicBase = false;
David Blaikie6521ed92015-06-22 22:06:52 +0000470 if (Args.hasArg(OPT_nxcompat_no))
471 Config->NxCompat = false;
472 if (Args.hasArg(OPT_tsaware_no))
473 Config->TerminalServerAware = false;
Rui Ueyama6592ff82015-06-16 23:13:00 +0000474
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000475 // Create a list of input files. Files can be given as arguments
476 // for /defaultlib option.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000477 std::vector<StringRef> Paths;
478 std::vector<MemoryBufferRef> MBs;
David Blaikie6521ed92015-06-22 22:06:52 +0000479 for (auto *Arg : Args.filtered(OPT_INPUT))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000480 if (Optional<StringRef> Path = findFile(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000481 Paths.push_back(*Path);
David Blaikie6521ed92015-06-22 22:06:52 +0000482 for (auto *Arg : Args.filtered(OPT_defaultlib))
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000483 if (Optional<StringRef> Path = findLib(Arg->getValue()))
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000484 Paths.push_back(*Path);
485 for (StringRef Path : Paths) {
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000486 ErrorOr<MemoryBufferRef> MBOrErr = openFile(Path);
487 if (auto EC = MBOrErr.getError()) {
488 llvm::errs() << "cannot open " << Path << ": " << EC.message() << "\n";
489 return false;
490 }
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000491 MBs.push_back(MBOrErr.get());
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000492 }
Rui Ueyamad21b00b2015-05-31 19:17:14 +0000493
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000494 // Windows specific -- Create a resource file containing a manifest file.
495 if (Config->Manifest == Configuration::Embed) {
496 auto MBOrErr = createManifestRes();
497 if (MBOrErr.getError())
498 return false;
499 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000500 MBs.push_back(MB->getMemBufferRef());
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000501 OwningMBs.push_back(std::move(MB)); // take ownership
502 }
503
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000504 // Windows specific -- Input files can be Windows resource files (.res files).
505 // We invoke cvtres.exe to convert resource files to a regular COFF file
506 // then link the result file normally.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000507 std::vector<MemoryBufferRef> Resources;
Rui Ueyama77731b42015-06-26 23:59:13 +0000508 auto NotResource = [](MemoryBufferRef MB) {
509 return identify_magic(MB.getBuffer()) != file_magic::windows_resource;
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000510 };
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000511 auto It = std::stable_partition(MBs.begin(), MBs.end(), NotResource);
512 if (It != MBs.end()) {
513 Resources.insert(Resources.end(), It, MBs.end());
514 MBs.erase(It, MBs.end());
Rui Ueyama2bf6a122015-06-14 21:50:50 +0000515 }
516
Rui Ueyama85225b02015-07-02 03:15:15 +0000517 // Read all input files given via the command line. Note that step()
518 // doesn't read files that are specified by directive sections.
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000519 for (MemoryBufferRef MB : MBs)
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000520 Symtab.addFile(createFile(MB));
Rui Ueyama85225b02015-07-02 03:15:15 +0000521 if (auto EC = Symtab.step()) {
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000522 llvm::errs() << EC.message() << "\n";
523 return false;
Rui Ueyama411c63602015-05-28 19:09:30 +0000524 }
Rui Ueyama5cff6852015-05-31 03:34:08 +0000525
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000526 // Determine machine type and check if all object files are
527 // for the same CPU type. Note that this needs to be done before
528 // any call to mangle().
529 for (std::unique_ptr<InputFile> &File : Symtab.getFiles()) {
530 MachineTypes MT = File->getMachineType();
531 if (MT == IMAGE_FILE_MACHINE_UNKNOWN)
532 continue;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000533 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
534 Config->Machine = MT;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000535 continue;
536 }
Rui Ueyama5e706b32015-07-25 21:54:50 +0000537 if (Config->Machine != MT) {
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000538 llvm::errs() << File->getShortName() << ": machine type "
Rui Ueyama5e706b32015-07-25 21:54:50 +0000539 << machineToStr(MT) << " conflicts with "
540 << machineToStr(Config->Machine) << "\n";
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000541 return false;
542 }
543 }
Rui Ueyama5e706b32015-07-25 21:54:50 +0000544 if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000545 llvm::errs() << "warning: /machine is not specified. x64 is assumed.\n";
Rui Ueyama5e706b32015-07-25 21:54:50 +0000546 Config->Machine = AMD64;
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000547 }
548
549 // Windows specific -- Convert Windows resource files to a COFF file.
550 if (!Resources.empty()) {
551 auto MBOrErr = convertResToCOFF(Resources);
552 if (MBOrErr.getError())
553 return false;
554 std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
555 Symtab.addFile(createFile(MB->getMemBufferRef()));
556 OwningMBs.push_back(std::move(MB)); // take ownership
557 }
558
Rui Ueyama4d545342015-07-28 03:12:00 +0000559 // Handle /largeaddressaware
560 if (Config->is64() || Args.hasArg(OPT_largeaddressaware))
561 Config->LargeAddressAware = true;
562
Rui Ueyamad68e2112015-07-28 03:15:57 +0000563 // Handle /highentropyva
564 if (Config->is64() && !Args.hasArg(OPT_highentropyva_no))
565 Config->HighEntropyVA = true;
566
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000567 // Handle /entry and /dll
568 if (auto *Arg = Args.getLastArg(OPT_entry)) {
569 Config->Entry = addUndefined(mangle(Arg->getValue()));
570 } else if (Args.hasArg(OPT_dll) && !Config->NoEntry) {
Rui Ueyama5e706b32015-07-25 21:54:50 +0000571 StringRef S = (Config->Machine == I386) ? "__DllMainCRTStartup@12"
572 : "_DllMainCRTStartup";
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000573 Config->Entry = addUndefined(S);
574 } else if (!Config->NoEntry) {
575 // Windows specific -- If entry point name is not given, we need to
576 // infer that from user-defined entry name.
Rui Ueyama45044f42015-06-29 01:03:53 +0000577 StringRef S = findDefaultEntry();
578 if (S.empty()) {
579 llvm::errs() << "entry point must be defined\n";
580 return false;
581 }
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000582 Config->Entry = addUndefined(S);
Rui Ueyama85225b02015-07-02 03:15:15 +0000583 if (Config->Verbose)
584 llvm::outs() << "Entry name inferred: " << S << "\n";
Rui Ueyama45044f42015-06-29 01:03:53 +0000585 }
586
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000587 // Handle /export
588 for (auto *Arg : Args.filtered(OPT_export)) {
589 ErrorOr<Export> E = parseExport(Arg->getValue());
590 if (E.getError())
591 return false;
Rui Ueyama5e706b32015-07-25 21:54:50 +0000592 if (Config->Machine == I386 && !E->Name.startswith("_@?"))
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000593 E->Name = mangle(E->Name);
594 Config->Exports.push_back(E.get());
595 }
596
597 // Handle /def
598 if (auto *Arg = Args.getLastArg(OPT_deffile)) {
599 ErrorOr<MemoryBufferRef> MBOrErr = openFile(Arg->getValue());
600 if (auto EC = MBOrErr.getError()) {
601 llvm::errs() << "/def: " << EC.message() << "\n";
602 return false;
603 }
604 // parseModuleDefs mutates Config object.
605 if (parseModuleDefs(MBOrErr.get(), &Alloc))
606 return false;
607 }
608
Rui Ueyama6d249082015-07-13 22:31:45 +0000609 // Handle /delayload
610 for (auto *Arg : Args.filtered(OPT_delayload)) {
611 Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
Rui Ueyama5e706b32015-07-25 21:54:50 +0000612 if (Config->Machine == I386) {
Rui Ueyama6d249082015-07-13 22:31:45 +0000613 Config->DelayLoadHelper = addUndefined("___delayLoadHelper2@8");
Rui Ueyama35ccb0f2015-07-25 00:20:06 +0000614 } else {
615 Config->DelayLoadHelper = addUndefined("__delayLoadHelper2");
Rui Ueyama6d249082015-07-13 22:31:45 +0000616 }
617 }
618
Rui Ueyama5c437cd2015-07-25 21:42:33 +0000619 // Set default image base if /base is not given.
620 if (Config->ImageBase == uint64_t(-1))
621 Config->ImageBase = getDefaultImageBase();
622
Rui Ueyama3cb895c2015-07-24 22:58:44 +0000623 Symtab.addRelative(mangle("__ImageBase"), 0);
Rui Ueyama5e706b32015-07-25 21:54:50 +0000624 if (Config->Machine == I386) {
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000625 Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0);
626 Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0);
627 }
Rui Ueyama29f74c32015-07-29 16:30:31 +0000628 Config->LoadConfigUsed = mangle("_load_config_used");
Rui Ueyamabbdec4f2015-07-09 22:51:41 +0000629
Rui Ueyamaea533cd2015-07-09 19:54:13 +0000630 // Read as much files as we can from directives sections.
Rui Ueyama85225b02015-07-02 03:15:15 +0000631 if (auto EC = Symtab.run()) {
632 llvm::errs() << EC.message() << "\n";
633 return false;
634 }
635
636 // Resolve auxiliary symbols until we get a convergence.
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000637 // (Trying to resolve a symbol may trigger a Lazy symbol to load a new file.
638 // A new file may contain a directive section to add new command line options.
639 // That's why we have to repeat until converge.)
640 for (;;) {
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000641 // Windows specific -- if entry point is not found,
642 // search for its mangled names.
643 if (Config->Entry)
644 Symtab.mangleMaybe(Config->Entry);
645
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000646 // Windows specific -- Make sure we resolve all dllexported symbols.
Rui Ueyama6bf638e2015-07-02 00:04:14 +0000647 for (Export &E : Config->Exports) {
648 E.Sym = addUndefined(E.Name);
649 Symtab.mangleMaybe(E.Sym);
650 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000651
652 // Add weak aliases. Weak aliases is a mechanism to give remaining
653 // undefined symbols final chance to be resolved successfully.
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000654 for (auto Pair : Config->AlternateNames) {
655 StringRef From = Pair.first;
656 StringRef To = Pair.second;
Rui Ueyama458d7442015-07-02 03:59:04 +0000657 Symbol *Sym = Symtab.find(From);
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000658 if (!Sym)
659 continue;
Rui Ueyama183f53f2015-07-06 17:45:22 +0000660 if (auto *U = dyn_cast<Undefined>(Sym->Body))
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000661 if (!U->WeakAlias)
662 U->WeakAlias = Symtab.addUndefined(To);
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000663 }
Rui Ueyama573bf7d2015-06-19 21:12:48 +0000664
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000665 // Windows specific -- if __load_config_used can be resolved, resolve it.
Peter Collingbournee7107ec2015-07-31 05:33:34 +0000666 if (Symtab.find(Config->LoadConfigUsed))
667 addUndefined(Config->LoadConfigUsed);
Rui Ueyamacd3f99b2015-07-24 23:51:14 +0000668
Rui Ueyama3d4c69c2015-07-02 02:38:59 +0000669 if (Symtab.queueEmpty())
670 break;
Rui Ueyama0d2e9992015-06-23 23:56:39 +0000671 if (auto EC = Symtab.run()) {
672 llvm::errs() << EC.message() << "\n";
673 return false;
674 }
Rui Ueyama2edb35a2015-06-18 19:09:30 +0000675 }
676
Rui Ueyamaeb262ce2015-06-04 02:12:16 +0000677 // Do LTO by compiling bitcode input files to a native COFF file
678 // then link that file.
Peter Collingbourne60c16162015-06-01 20:10:10 +0000679 if (auto EC = Symtab.addCombinedLTOObject()) {
680 llvm::errs() << EC.message() << "\n";
681 return false;
682 }
683
Peter Collingbourne2612a322015-07-04 05:28:41 +0000684 // Make sure we have resolved all symbols.
685 if (Symtab.reportRemainingUndefines(/*Resolve=*/true))
686 return false;
687
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000688 // Windows specific -- if no /subsystem is given, we need to infer
689 // that from entry point name.
690 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000691 Config->Subsystem = inferSubsystem();
Rui Ueyama3ee0fe42015-05-31 03:55:46 +0000692 if (Config->Subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
693 llvm::errs() << "subsystem must be defined\n";
694 return false;
695 }
696 }
697
Rui Ueyamaff88d5a2015-07-29 20:25:40 +0000698 // Handle /safeseh.
699 if (Args.hasArg(OPT_safeseh)) {
700 for (ObjectFile *File : Symtab.ObjectFiles) {
701 if (File->SEHCompat)
702 continue;
703 llvm::errs() << "/safeseh: " << File->getName()
704 << " is not compatible with SEH\n";
705 return false;
706 }
707 }
708
Rui Ueyama151d8622015-06-17 20:40:43 +0000709 // Windows specific -- when we are creating a .dll file, we also
710 // need to create a .lib file.
Rui Ueyama8765fba2015-07-15 22:21:08 +0000711 if (!Config->Exports.empty()) {
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000712 if (fixupExports())
713 return false;
Rafael Espindola4280a962015-08-05 20:03:57 +0000714 if (writeImportLibrary())
715 return false;
Rui Ueyama8765fba2015-07-15 22:21:08 +0000716 assignExportOrdinals();
717 }
Rui Ueyama97dff9e2015-06-17 00:16:33 +0000718
Rui Ueyama24c5fd02015-06-18 00:12:42 +0000719 // Windows specific -- Create a side-by-side manifest file.
720 if (Config->Manifest == Configuration::SideBySide)
721 if (createSideBySideManifest())
722 return false;
723
Rui Ueyama0fc26d22015-06-29 14:27:12 +0000724 // Create a dummy PDB file to satisfy build sytem rules.
725 if (auto *Arg = Args.getLastArg(OPT_pdb))
726 touchFile(Arg->getValue());
727
Rui Ueyama411c63602015-05-28 19:09:30 +0000728 // Write the result.
Rui Ueyamacb8474ed2015-08-05 23:51:50 +0000729 if (auto EC = writeResult(&Symtab)) {
Rui Ueyama411c63602015-05-28 19:09:30 +0000730 llvm::errs() << EC.message() << "\n";
731 return false;
732 }
Peter Collingbournebe549552015-06-26 18:58:24 +0000733
Rui Ueyama016414f2015-06-28 20:07:08 +0000734 // Create a symbol map file containing symbol VAs and their names
735 // to help debugging.
Peter Collingbournebe549552015-06-26 18:58:24 +0000736 if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
737 std::error_code EC;
Peter Collingbournebaf5f872015-06-26 19:20:09 +0000738 llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text);
Peter Collingbournebe549552015-06-26 18:58:24 +0000739 if (EC) {
740 llvm::errs() << EC.message() << "\n";
741 return false;
742 }
743 Symtab.printMap(Out);
744 }
Rui Ueyamaa51ce712015-07-03 05:31:35 +0000745 // Call exit to avoid calling destructors.
746 exit(0);
Rui Ueyama411c63602015-05-28 19:09:30 +0000747}
748
Rui Ueyama411c63602015-05-28 19:09:30 +0000749} // namespace coff
750} // namespace lld