2015-05-29 03:09:30 +08:00
|
|
|
//===- Driver.h -----------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_COFF_DRIVER_H
|
|
|
|
#define LLD_COFF_DRIVER_H
|
|
|
|
|
|
|
|
#include "Memory.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-05-29 04:30:06 +08:00
|
|
|
#include "llvm/Object/COFF.h"
|
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
2015-05-29 03:09:30 +08:00
|
|
|
#include <memory>
|
2015-06-01 03:17:09 +08:00
|
|
|
#include <set>
|
2015-05-29 03:09:30 +08:00
|
|
|
#include <system_error>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace coff {
|
|
|
|
|
2015-06-01 03:17:09 +08:00
|
|
|
class LinkerDriver;
|
|
|
|
extern LinkerDriver *Driver;
|
|
|
|
|
2015-05-30 00:06:00 +08:00
|
|
|
using llvm::COFF::MachineTypes;
|
2015-05-30 00:34:31 +08:00
|
|
|
using llvm::COFF::WindowsSubsystem;
|
2015-05-29 03:09:30 +08:00
|
|
|
class InputFile;
|
|
|
|
|
2015-06-01 03:17:09 +08:00
|
|
|
// Entry point of the COFF linker.
|
|
|
|
bool link(int Argc, const char *Argv[]);
|
|
|
|
|
|
|
|
class LinkerDriver {
|
|
|
|
public:
|
2015-06-01 03:17:12 +08:00
|
|
|
LinkerDriver() : SearchPaths(getSearchPaths()) {}
|
2015-06-01 03:17:09 +08:00
|
|
|
bool link(int Argc, const char *Argv[]);
|
|
|
|
|
|
|
|
// Used by the resolver to parse .drectve section contents.
|
|
|
|
std::error_code
|
|
|
|
parseDirectives(StringRef S, std::vector<std::unique_ptr<InputFile>> *Res);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Returns false if a given file has already been read.
|
|
|
|
bool insertFile(StringRef Path);
|
|
|
|
|
2015-06-01 03:17:12 +08:00
|
|
|
// Searches a file from search paths.
|
|
|
|
StringRef findFile(StringRef Filename);
|
|
|
|
StringRef findLib(StringRef Filename);
|
|
|
|
StringRef addExtOpt(StringRef Filename, StringRef Ext);
|
|
|
|
|
|
|
|
// Parses LIB environment which contains a list of search paths.
|
|
|
|
// The returned list always contains "." as the first element.
|
|
|
|
std::vector<StringRef> getSearchPaths();
|
|
|
|
|
|
|
|
std::vector<StringRef> SearchPaths;
|
2015-06-01 03:17:09 +08:00
|
|
|
std::set<std::string> VisitedFiles;
|
|
|
|
StringAllocator Alloc;
|
|
|
|
};
|
|
|
|
|
2015-05-29 04:30:06 +08:00
|
|
|
ErrorOr<std::unique_ptr<llvm::opt::InputArgList>>
|
|
|
|
parseArgs(int Argc, const char *Argv[]);
|
|
|
|
|
|
|
|
// Functions below this line are defined in DriverUtils.cpp.
|
|
|
|
|
2015-05-30 00:11:52 +08:00
|
|
|
void printHelp(const char *Argv0);
|
|
|
|
|
2015-05-30 00:06:00 +08:00
|
|
|
// For /machine option.
|
|
|
|
ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args);
|
|
|
|
|
2015-05-30 00:18:15 +08:00
|
|
|
// Parses a string in the form of "<integer>[,<integer>]".
|
|
|
|
std::error_code parseNumbers(StringRef Arg, uint64_t *Addr,
|
|
|
|
uint64_t *Size = nullptr);
|
|
|
|
|
2015-05-30 00:28:29 +08:00
|
|
|
// Parses a string in the form of "<integer>[.<integer>]".
|
|
|
|
// Minor's default value is 0.
|
|
|
|
std::error_code parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor);
|
|
|
|
|
2015-05-30 00:34:31 +08:00
|
|
|
// Parses a string in the form of "<subsystem>[,<integer>[.<integer>]]".
|
|
|
|
std::error_code parseSubsystem(StringRef Arg, WindowsSubsystem *Sys,
|
|
|
|
uint32_t *Major, uint32_t *Minor);
|
|
|
|
|
2015-05-29 04:30:06 +08:00
|
|
|
// Create enum with OPT_xxx values for each option in Options.td
|
|
|
|
enum {
|
|
|
|
OPT_INVALID = 0,
|
|
|
|
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
|
|
|
|
#include "Options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
2015-05-29 03:09:30 +08:00
|
|
|
} // namespace coff
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|