2015-08-14 22:12:54 +08:00
|
|
|
//===- Driver.h -------------------------------------------------*- C++ -*-===//
|
2015-07-25 05:03:07 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_DRIVER_H
|
|
|
|
#define LLD_ELF_DRIVER_H
|
|
|
|
|
2015-10-01 23:23:09 +08:00
|
|
|
#include "SymbolTable.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
2016-04-14 03:07:40 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2015-10-01 01:06:09 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-05-04 01:30:44 +08:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "llvm/Option/ArgList.h"
|
2016-02-03 06:49:32 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
namespace lld {
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-10-01 23:23:09 +08:00
|
|
|
extern class LinkerDriver *Driver;
|
2015-10-01 01:06:09 +08:00
|
|
|
|
2016-05-16 01:10:23 +08:00
|
|
|
class CpioFile;
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
class LinkerDriver {
|
|
|
|
public:
|
2015-10-10 05:07:25 +08:00
|
|
|
void main(ArrayRef<const char *> Args);
|
2015-10-01 23:23:09 +08:00
|
|
|
void addFile(StringRef Path);
|
2016-02-03 05:13:09 +08:00
|
|
|
void addLibrary(StringRef Name);
|
2016-05-16 01:10:23 +08:00
|
|
|
llvm::LLVMContext Context; // to parse bitcode ifles
|
|
|
|
std::unique_ptr<CpioFile> Cpio; // for reproduce
|
2016-05-04 01:30:44 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
private:
|
2016-04-01 07:12:18 +08:00
|
|
|
std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
|
2016-04-14 02:51:11 +08:00
|
|
|
llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
|
2016-01-08 01:54:21 +08:00
|
|
|
void readConfigs(llvm::opt::InputArgList &Args);
|
|
|
|
void createFiles(llvm::opt::InputArgList &Args);
|
|
|
|
template <class ELFT> void link(llvm::opt::InputArgList &Args);
|
2015-10-07 17:13:03 +08:00
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
// True if we are in --whole-archive and --no-whole-archive.
|
2015-10-10 05:07:25 +08:00
|
|
|
bool WholeArchive = false;
|
2016-04-08 03:24:51 +08:00
|
|
|
|
|
|
|
// True if we are in --start-lib and --end-lib.
|
|
|
|
bool InLib = false;
|
|
|
|
|
|
|
|
llvm::BumpPtrAllocator Alloc;
|
2015-10-10 05:07:25 +08:00
|
|
|
std::vector<std::unique_ptr<InputFile>> Files;
|
2015-10-01 23:23:09 +08:00
|
|
|
std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2015-10-12 02:19:01 +08:00
|
|
|
// Parses command line options.
|
2016-03-16 02:20:50 +08:00
|
|
|
class ELFOptTable : public llvm::opt::OptTable {
|
|
|
|
public:
|
|
|
|
ELFOptTable();
|
|
|
|
llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
|
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::BumpPtrAllocator Alloc;
|
|
|
|
};
|
2015-10-12 02:19:01 +08:00
|
|
|
|
2015-07-25 05:03:07 +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
|
|
|
|
};
|
|
|
|
|
2016-05-16 01:10:23 +08:00
|
|
|
// This is the class to create a .cpio file for --reproduce.
|
|
|
|
//
|
|
|
|
// If "--reproduce foo" is given, we create a file "foo.cpio" and
|
|
|
|
// copy all input files to the archive, along with a response file
|
|
|
|
// to re-run the same command with the same inputs.
|
|
|
|
// It is useful for reporting issues to LLD developers.
|
|
|
|
//
|
|
|
|
// Cpio as a file format is a deliberate choice. It's standardized in
|
|
|
|
// POSIX and very easy to create. cpio command is available virtually
|
|
|
|
// on all Unix systems. See
|
|
|
|
// http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_07
|
|
|
|
// for the format details.
|
|
|
|
class CpioFile {
|
|
|
|
public:
|
|
|
|
static CpioFile *create(StringRef OutputPath);
|
|
|
|
void append(StringRef Path, StringRef Data);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CpioFile(std::unique_ptr<llvm::raw_fd_ostream> OS, StringRef Basename);
|
|
|
|
|
|
|
|
std::unique_ptr<llvm::raw_fd_ostream> OS;
|
|
|
|
llvm::StringSet<> Seen;
|
|
|
|
std::string Basename;
|
|
|
|
};
|
|
|
|
|
2016-02-28 11:18:09 +08:00
|
|
|
void printHelp(const char *Argv0);
|
2016-06-06 23:34:37 +08:00
|
|
|
std::string getVersionString();
|
2016-05-14 05:55:56 +08:00
|
|
|
std::vector<uint8_t> parseHexstring(StringRef S);
|
2016-02-28 11:18:07 +08:00
|
|
|
|
2016-05-16 01:10:23 +08:00
|
|
|
std::string createResponseFile(const llvm::opt::InputArgList &Args);
|
|
|
|
std::string relativeToRoot(StringRef Path);
|
2016-05-01 06:23:29 +08:00
|
|
|
|
2015-10-11 11:28:42 +08:00
|
|
|
std::string findFromSearchPaths(StringRef Path);
|
2015-10-11 11:28:39 +08:00
|
|
|
std::string searchLibrary(StringRef Path);
|
|
|
|
std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|