2013-05-29 02:13:31 +08:00
|
|
|
//===- lib/Driver/WinLinkDriver.cpp ---------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// Concrete instance of the Driver for Windows link.exe.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-05-31 14:30:10 +08:00
|
|
|
#include <cstdlib>
|
2013-07-19 13:06:20 +08:00
|
|
|
#include <sstream>
|
2013-07-25 09:23:50 +08:00
|
|
|
#include <map>
|
2013-05-31 14:30:10 +08:00
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
#include "lld/Driver/Driver.h"
|
|
|
|
#include "lld/Driver/WinLinkInputGraph.h"
|
|
|
|
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
|
|
|
|
|
2013-07-19 05:38:44 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2013-05-29 13:07:49 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2013-05-29 02:13:31 +08:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/Option.h"
|
2013-06-12 06:17:04 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2013-05-29 02:13:31 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Create enum with OPT_xxx values for each option in WinLinkOptions.td
|
2013-09-06 04:21:24 +08:00
|
|
|
enum {
|
2013-05-29 02:13:31 +08:00
|
|
|
OPT_INVALID = 0,
|
2013-08-01 07:17:41 +08:00
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELP, META) \
|
2013-05-29 02:13:31 +08:00
|
|
|
OPT_##ID,
|
|
|
|
#include "WinLinkOptions.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create prefix string literals used in WinLinkOptions.td
|
|
|
|
#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
|
|
|
|
#include "WinLinkOptions.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
|
|
|
// Create table mapping all options defined in WinLinkOptions.td
|
|
|
|
static const llvm::opt::OptTable::Info infoTable[] = {
|
2013-08-01 07:17:41 +08:00
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
2013-05-29 02:13:31 +08:00
|
|
|
HELPTEXT, METAVAR) \
|
|
|
|
{ PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, llvm::opt::Option::KIND##Class, \
|
2013-08-01 07:17:41 +08:00
|
|
|
PARAM, FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
|
2013-05-29 02:13:31 +08:00
|
|
|
#include "WinLinkOptions.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create OptTable class for parsing actual command line arguments
|
|
|
|
class WinLinkOptTable : public llvm::opt::OptTable {
|
|
|
|
public:
|
2013-08-29 04:27:41 +08:00
|
|
|
// link.exe's command line options are case insensitive, unlike
|
|
|
|
// other driver's options for Unix.
|
|
|
|
WinLinkOptTable()
|
|
|
|
: OptTable(infoTable, llvm::array_lengthof(infoTable),
|
|
|
|
/* ignoreCase */ true) {}
|
2013-05-29 02:13:31 +08:00
|
|
|
};
|
|
|
|
|
2013-07-19 13:06:20 +08:00
|
|
|
// Split the given string with spaces.
|
|
|
|
std::vector<std::string> splitArgList(std::string str) {
|
|
|
|
std::stringstream stream(str);
|
|
|
|
std::istream_iterator<std::string> begin(stream);
|
|
|
|
std::istream_iterator<std::string> end;
|
|
|
|
return std::vector<std::string>(begin, end);
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:27:03 +08:00
|
|
|
// Split the given string with the path separator.
|
|
|
|
std::vector<StringRef> splitPathList(StringRef str) {
|
|
|
|
std::vector<StringRef> ret;
|
|
|
|
while (!str.empty()) {
|
|
|
|
StringRef path;
|
|
|
|
llvm::tie(path, str) = str.split(';');
|
|
|
|
ret.push_back(path);
|
|
|
|
}
|
|
|
|
return std::move(ret);
|
|
|
|
}
|
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
// Parse an argument for /base, /stack or /heap. The expected string
|
|
|
|
// is "<integer>[,<integer>]".
|
|
|
|
bool parseMemoryOption(StringRef arg, uint64_t &reserve, uint64_t &commit) {
|
|
|
|
StringRef reserveStr, commitStr;
|
|
|
|
llvm::tie(reserveStr, commitStr) = arg.split(',');
|
|
|
|
if (reserveStr.getAsInteger(0, reserve))
|
|
|
|
return true;
|
|
|
|
if (!commitStr.empty() && (commitStr.getAsInteger(0, commit)))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns subsystem type for the given string.
|
|
|
|
llvm::COFF::WindowsSubsystem stringToWinSubsystem(StringRef str) {
|
|
|
|
return llvm::StringSwitch<llvm::COFF::WindowsSubsystem>(str.lower())
|
|
|
|
.Case("windows", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI)
|
|
|
|
.Case("console", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
2013-08-25 04:14:54 +08:00
|
|
|
.Case("boot_application",
|
|
|
|
llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)
|
|
|
|
.Case("efi_application", llvm::COFF::IMAGE_SUBSYSTEM_EFI_APPLICATION)
|
|
|
|
.Case("efi_boot_service_driver",
|
|
|
|
llvm::COFF::IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)
|
|
|
|
.Case("efi_rom", llvm::COFF::IMAGE_SUBSYSTEM_EFI_ROM)
|
|
|
|
.Case("efi_runtime_driver",
|
|
|
|
llvm::COFF::IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)
|
|
|
|
.Case("native", llvm::COFF::IMAGE_SUBSYSTEM_NATIVE)
|
|
|
|
.Case("posix", llvm::COFF::IMAGE_SUBSYSTEM_POSIX_CUI)
|
2013-08-22 06:57:10 +08:00
|
|
|
.Default(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
2013-07-25 09:23:50 +08:00
|
|
|
// Handle /failifmatch option.
|
|
|
|
bool handleFailIfMismatchOption(StringRef option,
|
|
|
|
std::map<StringRef, StringRef> &mustMatch,
|
|
|
|
raw_ostream &diagnostics) {
|
|
|
|
StringRef key, value;
|
|
|
|
llvm::tie(key, value) = option.split('=');
|
|
|
|
if (key.empty() || value.empty()) {
|
|
|
|
diagnostics << "error: malformed /failifmatch option: " << option << "\n";
|
2013-08-22 06:57:10 +08:00
|
|
|
return true;
|
2013-07-25 09:23:50 +08:00
|
|
|
}
|
|
|
|
auto it = mustMatch.find(key);
|
|
|
|
if (it != mustMatch.end() && it->second != value) {
|
|
|
|
diagnostics << "error: mismatch detected: '" << it->second << "' and '"
|
|
|
|
<< value << "' for key '" << key << "'\n";
|
2013-08-22 06:57:10 +08:00
|
|
|
return true;
|
2013-07-25 09:23:50 +08:00
|
|
|
}
|
|
|
|
mustMatch[key] = value;
|
2013-08-22 06:57:10 +08:00
|
|
|
return false;
|
2013-07-27 06:22:26 +08:00
|
|
|
}
|
|
|
|
|
2013-07-19 13:06:20 +08:00
|
|
|
// Process "LINK" environment variable. If defined, the value of the variable
|
|
|
|
// should be processed as command line arguments.
|
2013-08-07 06:31:59 +08:00
|
|
|
std::vector<const char *> processLinkEnv(PECOFFLinkingContext &context,
|
2013-07-19 13:06:20 +08:00
|
|
|
int argc, const char **argv) {
|
|
|
|
std::vector<const char *> ret;
|
|
|
|
// The first argument is the name of the command. This should stay at the head
|
|
|
|
// of the argument list.
|
|
|
|
assert(argc > 0);
|
|
|
|
ret.push_back(argv[0]);
|
|
|
|
|
|
|
|
// Add arguments specified by the LINK environment variable.
|
|
|
|
if (char *envp = ::getenv("LINK"))
|
|
|
|
for (std::string &arg : splitArgList(envp))
|
2013-08-07 06:31:59 +08:00
|
|
|
ret.push_back(context.allocateString(arg).data());
|
2013-07-19 13:06:20 +08:00
|
|
|
|
|
|
|
// Add the rest of arguments passed via the command line.
|
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
ret.push_back(argv[i]);
|
|
|
|
ret.push_back(nullptr);
|
|
|
|
return std::move(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process "LIB" environment variable. The variable contains a list of search
|
|
|
|
// paths separated by semicolons.
|
2013-08-07 06:31:59 +08:00
|
|
|
void processLibEnv(PECOFFLinkingContext &context) {
|
2013-07-19 11:27:03 +08:00
|
|
|
if (char *envp = ::getenv("LIB"))
|
|
|
|
for (StringRef path : splitPathList(envp))
|
2013-08-07 06:31:59 +08:00
|
|
|
context.appendInputSearchPath(context.allocateString(path));
|
2013-07-19 11:27:03 +08:00
|
|
|
}
|
|
|
|
|
2013-09-06 09:48:19 +08:00
|
|
|
// Returns a default entry point symbol name depending on context image type and
|
2013-08-27 03:55:09 +08:00
|
|
|
// subsystem. These default names are MS CRT compliant.
|
2013-09-06 09:48:19 +08:00
|
|
|
StringRef getDefaultEntrySymbolName(PECOFFLinkingContext &context) {
|
|
|
|
if (context.getImageType() == PECOFFLinkingContext::ImageType::IMAGE_DLL)
|
|
|
|
return "__DllMainCRTStartup";
|
|
|
|
llvm::COFF::WindowsSubsystem subsystem = context.getSubsystem();
|
|
|
|
if (subsystem == llvm::COFF::WindowsSubsystem::IMAGE_SUBSYSTEM_WINDOWS_GUI)
|
|
|
|
return "_WinMainCRTStartup";
|
|
|
|
if (subsystem == llvm::COFF::WindowsSubsystem::IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
|
|
|
return "_mainCRTStartup";
|
|
|
|
return "";
|
2013-08-27 03:55:09 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:33:08 +08:00
|
|
|
// Parses the given command line options and returns the result. Returns NULL if
|
|
|
|
// there's an error in the options.
|
2013-09-04 08:51:51 +08:00
|
|
|
std::unique_ptr<llvm::opt::InputArgList>
|
|
|
|
parseArgs(int argc, const char *argv[], raw_ostream &diagnostics,
|
|
|
|
bool isDirective) {
|
2013-07-26 06:33:08 +08:00
|
|
|
// Parse command line options using WinLinkOptions.td
|
|
|
|
std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
|
|
|
|
WinLinkOptTable table;
|
|
|
|
unsigned missingIndex;
|
|
|
|
unsigned missingCount;
|
2013-09-04 08:51:51 +08:00
|
|
|
parsedArgs.reset(table.ParseArgs(&argv[1], &argv[argc],
|
|
|
|
missingIndex, missingCount));
|
2013-07-26 06:33:08 +08:00
|
|
|
if (missingCount) {
|
|
|
|
diagnostics << "error: missing arg value for '"
|
|
|
|
<< parsedArgs->getArgString(missingIndex) << "' expected "
|
|
|
|
<< missingCount << " argument(s).\n";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-09-04 08:51:51 +08:00
|
|
|
// Show warning for unknown arguments. In .drectve section, unknown options
|
|
|
|
// starting with "-?" are silently ignored. This is a COFF's feature to embed a
|
|
|
|
// new linker option to an object file while keeping backward compatibility.
|
2013-07-26 06:33:08 +08:00
|
|
|
for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
|
|
|
|
ie = parsedArgs->filtered_end(); it != ie; ++it) {
|
2013-09-04 08:51:51 +08:00
|
|
|
StringRef arg = (*it)->getAsString(*parsedArgs);
|
|
|
|
if (isDirective && arg.startswith("-?"))
|
|
|
|
continue;
|
|
|
|
diagnostics << "warning: ignoring unknown argument: " << arg << "\n";
|
2013-07-26 06:33:08 +08:00
|
|
|
}
|
|
|
|
return parsedArgs;
|
|
|
|
}
|
|
|
|
|
2013-05-29 02:13:31 +08:00
|
|
|
} // namespace
|
|
|
|
|
2013-09-04 06:44:37 +08:00
|
|
|
llvm::ErrorOr<StringRef> PECOFFFileNode::path(const LinkingContext &) const {
|
2013-08-22 06:57:10 +08:00
|
|
|
if (_path.endswith(".lib"))
|
|
|
|
return _ctx.searchLibraryFile(_path);
|
|
|
|
if (llvm::sys::path::extension(_path).empty())
|
2013-08-22 23:37:09 +08:00
|
|
|
return (_ctx.allocateString(_path.str() + ".obj"));
|
2013-08-22 06:57:10 +08:00
|
|
|
return _path;
|
|
|
|
}
|
|
|
|
|
2013-09-04 06:44:37 +08:00
|
|
|
llvm::ErrorOr<StringRef> PECOFFLibraryNode::path(const LinkingContext &) const {
|
2013-08-22 06:57:10 +08:00
|
|
|
if (!_path.endswith(".lib"))
|
2013-08-23 01:59:03 +08:00
|
|
|
return _ctx.searchLibraryFile(_ctx.allocateString(_path.str() + ".lib"));
|
2013-08-22 06:57:10 +08:00
|
|
|
return _ctx.searchLibraryFile(_path);
|
|
|
|
}
|
2013-05-29 02:13:31 +08:00
|
|
|
|
2013-07-16 07:55:07 +08:00
|
|
|
bool WinLinkDriver::linkPECOFF(int argc, const char *argv[],
|
|
|
|
raw_ostream &diagnostics) {
|
2013-08-07 06:31:59 +08:00
|
|
|
PECOFFLinkingContext context;
|
|
|
|
std::vector<const char *> newargv = processLinkEnv(context, argc, argv);
|
|
|
|
processLibEnv(context);
|
|
|
|
if (parse(newargv.size() - 1, &newargv[0], context, diagnostics))
|
2013-05-29 02:13:31 +08:00
|
|
|
return true;
|
2013-08-07 06:31:59 +08:00
|
|
|
return link(context, diagnostics);
|
2013-05-29 02:13:31 +08:00
|
|
|
}
|
|
|
|
|
2013-09-04 08:51:51 +08:00
|
|
|
bool WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx,
|
|
|
|
raw_ostream &diagnostics, bool isDirective) {
|
2013-08-22 06:57:10 +08:00
|
|
|
std::map<StringRef, StringRef> failIfMismatchMap;
|
2013-07-26 06:33:08 +08:00
|
|
|
// Parse the options.
|
|
|
|
std::unique_ptr<llvm::opt::InputArgList> parsedArgs = parseArgs(
|
2013-09-04 08:51:51 +08:00
|
|
|
argc, argv, diagnostics, isDirective);
|
2013-07-26 06:33:08 +08:00
|
|
|
if (!parsedArgs)
|
2013-05-29 02:13:31 +08:00
|
|
|
return true;
|
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
if (!ctx.hasInputGraph())
|
|
|
|
ctx.setInputGraph(std::unique_ptr<InputGraph>(new InputGraph()));
|
|
|
|
|
|
|
|
InputGraph &inputGraph = ctx.inputGraph();
|
|
|
|
|
2013-07-25 07:18:02 +08:00
|
|
|
// handle /help
|
2013-05-29 02:13:31 +08:00
|
|
|
if (parsedArgs->getLastArg(OPT_help)) {
|
2013-07-26 06:33:08 +08:00
|
|
|
WinLinkOptTable table;
|
2013-05-29 02:13:31 +08:00
|
|
|
table.PrintHelp(llvm::outs(), argv[0], "LLVM Linker", false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-25 07:18:02 +08:00
|
|
|
// handle /defaultlib
|
2013-07-19 12:11:37 +08:00
|
|
|
std::vector<StringRef> defaultLibs;
|
|
|
|
for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_defaultlib),
|
|
|
|
ie = parsedArgs->filtered_end();
|
|
|
|
it != ie; ++it) {
|
2013-08-01 06:13:15 +08:00
|
|
|
defaultLibs.push_back((*it)->getValue());
|
2013-07-19 12:11:37 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
// Process all the arguments and create Input Elements
|
|
|
|
for (auto inputArg : *parsedArgs) {
|
|
|
|
switch (inputArg->getOption().getID()) {
|
|
|
|
case OPT_mllvm:
|
|
|
|
ctx.appendLLVMOption(inputArg->getValue());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_base:
|
|
|
|
// Parse /base command line option. The argument for the parameter is in
|
|
|
|
// the
|
|
|
|
// form of "<address>[:<size>]".
|
|
|
|
uint64_t addr, size;
|
|
|
|
// Size should be set to SizeOfImage field in the COFF header, and if
|
|
|
|
// it's smaller than the actual size, the linker should warn about that.
|
|
|
|
// Currently we just ignore the value of size parameter.
|
|
|
|
if (parseMemoryOption(inputArg->getValue(), addr, size))
|
|
|
|
return true;
|
|
|
|
ctx.setBaseAddress(addr);
|
|
|
|
break;
|
|
|
|
case OPT_stack: {
|
|
|
|
// Parse /stack command line option
|
|
|
|
uint64_t reserve;
|
|
|
|
uint64_t commit = ctx.getStackCommit();
|
|
|
|
if (parseMemoryOption(inputArg->getValue(), reserve, commit))
|
|
|
|
return true;
|
|
|
|
ctx.setStackReserve(reserve);
|
|
|
|
ctx.setStackCommit(commit);
|
2013-09-03 09:25:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-08-22 06:57:10 +08:00
|
|
|
case OPT_heap: {
|
|
|
|
// Parse /heap command line option
|
|
|
|
uint64_t reserve;
|
|
|
|
uint64_t commit = ctx.getHeapCommit();
|
|
|
|
if (parseMemoryOption(inputArg->getValue(), reserve, commit))
|
|
|
|
return true;
|
|
|
|
ctx.setHeapReserve(reserve);
|
|
|
|
ctx.setHeapCommit(commit);
|
2013-09-03 09:25:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-09-06 12:17:07 +08:00
|
|
|
case OPT_machine: {
|
|
|
|
StringRef platform = inputArg->getValue();
|
|
|
|
if (!platform.equals_lower("x64")) {
|
|
|
|
diagnostics << "error: LLD does not support non-x64 platform, "
|
|
|
|
<< "but got /machine:" << platform << "\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-08-22 06:57:10 +08:00
|
|
|
case OPT_subsystem: {
|
|
|
|
// Parse /subsystem command line option. The form of /subsystem is
|
|
|
|
// "subsystem_name[,majorOSVersion[.minorOSVersion]]".
|
|
|
|
StringRef subsystemStr, osVersion;
|
|
|
|
llvm::tie(subsystemStr, osVersion) =
|
|
|
|
StringRef(inputArg->getValue()).split(',');
|
|
|
|
if (!osVersion.empty()) {
|
|
|
|
StringRef majorVersion, minorVersion;
|
|
|
|
llvm::tie(majorVersion, minorVersion) = osVersion.split('.');
|
|
|
|
if (minorVersion.empty())
|
|
|
|
minorVersion = "0";
|
|
|
|
int32_t major, minor;
|
|
|
|
if (majorVersion.getAsInteger(0, major))
|
|
|
|
return true;
|
|
|
|
if (minorVersion.getAsInteger(0, minor))
|
|
|
|
return true;
|
|
|
|
ctx.setMinOSVersion(PECOFFLinkingContext::OSVersion(major, minor));
|
|
|
|
}
|
|
|
|
// Parse subsystem name.
|
|
|
|
llvm::COFF::WindowsSubsystem subsystem =
|
|
|
|
stringToWinSubsystem(subsystemStr);
|
|
|
|
if (subsystem == llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN) {
|
|
|
|
diagnostics << "error: unknown subsystem name: " << subsystemStr
|
|
|
|
<< "\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ctx.setSubsystem(subsystem);
|
2013-09-03 09:25:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-08-22 06:57:10 +08:00
|
|
|
|
|
|
|
case OPT_failifmismatch:
|
|
|
|
if (handleFailIfMismatchOption(inputArg->getValue(), failIfMismatchMap,
|
|
|
|
diagnostics))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_entry:
|
|
|
|
// handle /entry
|
2013-09-04 07:14:30 +08:00
|
|
|
ctx.setEntrySymbolName(inputArg->getValue());
|
2013-08-22 06:57:10 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_libpath:
|
|
|
|
// handle /libpath
|
2013-09-04 07:14:30 +08:00
|
|
|
ctx.appendInputSearchPath(inputArg->getValue());
|
2013-08-22 06:57:10 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_force:
|
2013-08-30 05:46:47 +08:00
|
|
|
case OPT_force_unresolved:
|
|
|
|
// handle /force or /force:unresolved. We do not currently support
|
|
|
|
// /force:multiple.
|
2013-08-22 06:57:10 +08:00
|
|
|
ctx.setAllowRemainingUndefines(true);
|
|
|
|
break;
|
|
|
|
|
2013-08-27 11:38:18 +08:00
|
|
|
case OPT_no_ref:
|
|
|
|
// Handle /opt:noref
|
|
|
|
ctx.setDeadStripping(false);
|
|
|
|
break;
|
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
case OPT_no_nxcompat:
|
|
|
|
// handle /nxcompat:no
|
|
|
|
ctx.setNxCompat(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_largeaddressaware:
|
|
|
|
// handle /largeaddressaware
|
|
|
|
ctx.setLargeAddressAware(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_fixed:
|
|
|
|
// handle /fixed
|
2013-08-24 08:39:10 +08:00
|
|
|
|
|
|
|
// make sure /dynamicbase wasn't specified
|
|
|
|
if (parsedArgs->getLastArg(OPT_dynamicbase)) {
|
|
|
|
diagnostics << "/dynamicbase must not be specified with /fixed\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
ctx.setBaseRelocationEnabled(false);
|
2013-08-24 08:39:10 +08:00
|
|
|
ctx.setDynamicBaseEnabled(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_no_dynamicbase:
|
|
|
|
// handle /dynamicbase:no
|
|
|
|
ctx.setDynamicBaseEnabled(false);
|
2013-08-22 06:57:10 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_tsaware:
|
|
|
|
// handle /tsaware
|
|
|
|
ctx.setTerminalServerAware(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_no_tsaware:
|
|
|
|
// handle /tsaware:no
|
|
|
|
ctx.setTerminalServerAware(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_incl:
|
|
|
|
// handle /incl
|
2013-09-04 07:14:30 +08:00
|
|
|
ctx.addInitialUndefinedSymbol(inputArg->getValue());
|
2013-08-22 06:57:10 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPT_out:
|
|
|
|
// handle /out
|
2013-09-04 07:14:30 +08:00
|
|
|
ctx.setOutputPath(inputArg->getValue());
|
2013-08-22 06:57:10 +08:00
|
|
|
break;
|
|
|
|
|
2013-09-03 09:25:21 +08:00
|
|
|
case OPT_INPUT:
|
2013-08-22 06:57:10 +08:00
|
|
|
inputGraph.addInputElement(std::unique_ptr<InputElement>(
|
|
|
|
new PECOFFFileNode(ctx, inputArg->getValue())));
|
2013-09-03 09:25:21 +08:00
|
|
|
break;
|
2013-08-22 06:57:10 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-05-29 02:13:31 +08:00
|
|
|
}
|
|
|
|
|
2013-08-27 03:55:09 +08:00
|
|
|
// Use the default entry name if /entry option is not given.
|
2013-08-27 11:18:11 +08:00
|
|
|
if (ctx.entrySymbolName().empty())
|
2013-09-06 09:48:19 +08:00
|
|
|
ctx.setEntrySymbolName(getDefaultEntrySymbolName(ctx));
|
2013-08-27 03:55:09 +08:00
|
|
|
|
2013-08-27 11:38:18 +08:00
|
|
|
// Specifying both /opt:ref and /opt:noref is an error.
|
|
|
|
if (parsedArgs->getLastArg(OPT_ref) && parsedArgs->getLastArg(OPT_no_ref)) {
|
|
|
|
diagnostics << "/opt:ref must not be specified with /opt:noref\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-27 13:15:20 +08:00
|
|
|
// If dead-stripping is enabled, we need to add the entry symbol and
|
|
|
|
// symbols given by /include to the dead strip root set, so that it
|
|
|
|
// won't be removed from the output.
|
|
|
|
if (ctx.deadStrip()) {
|
|
|
|
ctx.addDeadStripRoot(ctx.entrySymbolName());
|
|
|
|
for (const StringRef symbolName : ctx.initialUndefinedSymbols())
|
|
|
|
ctx.addDeadStripRoot(symbolName);
|
|
|
|
}
|
|
|
|
|
2013-08-14 05:44:44 +08:00
|
|
|
// Arguments after "--" are interpreted as filenames even if they
|
|
|
|
// start with a hypen or a slash. This is not compatible with link.exe
|
|
|
|
// but useful for us to test lld on Unix.
|
|
|
|
if (llvm::opt::Arg *dashdash = parsedArgs->getLastArg(OPT_DASH_DASH)) {
|
|
|
|
for (const StringRef value : dashdash->getValues())
|
2013-08-22 06:57:10 +08:00
|
|
|
inputGraph.addInputElement(
|
|
|
|
std::unique_ptr<InputElement>(new PECOFFFileNode(ctx, value)));
|
2013-08-14 05:44:44 +08:00
|
|
|
}
|
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
// Add ".lib" extension if the path does not already have the extension to
|
|
|
|
// mimic link.exe behavior.
|
|
|
|
for (auto defaultLibPath : defaultLibs)
|
|
|
|
inputGraph.addInputElement(std::unique_ptr<InputElement>(
|
|
|
|
new PECOFFLibraryNode(ctx, defaultLibPath)));
|
2013-05-30 14:00:10 +08:00
|
|
|
|
2013-08-22 06:57:10 +08:00
|
|
|
if (!inputGraph.numFiles()) {
|
|
|
|
diagnostics << "No input files\n";
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-19 12:11:37 +08:00
|
|
|
|
2013-08-31 13:27:38 +08:00
|
|
|
// A list of undefined symbols will be added to the input
|
|
|
|
// file list to force the core linker to try to resolve
|
|
|
|
// the undefined symbols.
|
|
|
|
inputGraph.addInternalFile(ctx.createInternalFiles());
|
|
|
|
|
2013-07-25 07:18:02 +08:00
|
|
|
// If /out option was not specified, the default output file name is
|
2013-07-19 10:18:25 +08:00
|
|
|
// constructed by replacing an extension of the first input file
|
|
|
|
// with ".exe".
|
2013-08-22 06:57:10 +08:00
|
|
|
if (ctx.outputPath().empty()) {
|
|
|
|
SmallString<128> firstInputFilePath =
|
2013-09-06 11:16:28 +08:00
|
|
|
*llvm::dyn_cast<FileNode>(&inputGraph[0])->path(ctx);
|
|
|
|
llvm::sys::path::replace_extension(firstInputFilePath, ".exe");
|
2013-08-24 06:06:29 +08:00
|
|
|
ctx.setOutputPath(ctx.allocateString(firstInputFilePath.str()));
|
2013-08-22 06:57:10 +08:00
|
|
|
}
|
2013-05-29 02:13:31 +08:00
|
|
|
|
|
|
|
// Validate the combination of options used.
|
2013-08-22 06:57:10 +08:00
|
|
|
return ctx.validate(diagnostics);
|
2013-05-29 02:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace lld
|