1 //===- Driver.h -------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_ELF_DRIVER_H
11 #define LLD_ELF_DRIVER_H
13 #include "SymbolTable.h"
14 #include "lld/Core/LLVM.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/StringSet.h"
18 #include "llvm/Option/ArgList.h"
19 #include "llvm/Support/raw_ostream.h"
24 extern class LinkerDriver *Driver;
30 void main(ArrayRef<const char *> Args);
31 void addFile(StringRef Path);
32 void addLibrary(StringRef Name);
33 llvm::LLVMContext Context; // to parse bitcode ifles
34 std::unique_ptr<CpioFile> Cpio; // for reproduce
37 std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
38 llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
39 void readConfigs(llvm::opt::InputArgList &Args);
40 void createFiles(llvm::opt::InputArgList &Args);
41 template <class ELFT> void link(llvm::opt::InputArgList &Args);
43 // True if we are in --whole-archive and --no-whole-archive.
44 bool WholeArchive = false;
46 // True if we are in --start-lib and --end-lib.
49 llvm::BumpPtrAllocator Alloc;
50 std::vector<std::unique_ptr<InputFile>> Files;
51 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
54 // Parses command line options.
55 class ELFOptTable : public llvm::opt::OptTable {
58 llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
61 llvm::BumpPtrAllocator Alloc;
64 // Create enum with OPT_xxx values for each option in Options.td
67 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
68 #include "ELF/Options.inc"
72 // This is the class to create a .cpio file for --reproduce.
74 // If "--reproduce foo" is given, we create a file "foo.cpio" and
75 // copy all input files to the archive, along with a response file
76 // to re-run the same command with the same inputs.
77 // It is useful for reporting issues to LLD developers.
79 // Cpio as a file format is a deliberate choice. It's standardized in
80 // POSIX and very easy to create. cpio command is available virtually
81 // on all Unix systems. See
82 // http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_07
83 // for the format details.
86 static CpioFile *create(StringRef OutputPath);
87 void append(StringRef Path, StringRef Data);
90 CpioFile(std::unique_ptr<llvm::raw_fd_ostream> OS, StringRef Basename);
92 std::unique_ptr<llvm::raw_fd_ostream> OS;
93 llvm::StringSet<> Seen;
97 void printHelp(const char *Argv0);
98 std::string getVersionString();
99 std::vector<uint8_t> parseHexstring(StringRef S);
101 std::string createResponseFile(const llvm::opt::InputArgList &Args);
102 std::string relativeToRoot(StringRef Path);
104 std::string findFromSearchPaths(StringRef Path);
105 std::string searchLibrary(StringRef Path);
106 std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);