]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Driver.h
Merge ^/head r303250 through r308226.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / Driver.h
1 //===- Driver.h -------------------------------------------------*- C++ -*-===//
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 #ifndef LLD_ELF_DRIVER_H
11 #define LLD_ELF_DRIVER_H
12
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"
20
21 namespace lld {
22 namespace elf {
23
24 extern class LinkerDriver *Driver;
25
26 class CpioFile;
27
28 class LinkerDriver {
29 public:
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
35
36 private:
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);
42
43   // True if we are in --whole-archive and --no-whole-archive.
44   bool WholeArchive = false;
45
46   // True if we are in --start-lib and --end-lib.
47   bool InLib = false;
48
49   llvm::BumpPtrAllocator Alloc;
50   std::vector<std::unique_ptr<InputFile>> Files;
51   std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
52 };
53
54 // Parses command line options.
55 class ELFOptTable : public llvm::opt::OptTable {
56 public:
57   ELFOptTable();
58   llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
59
60 private:
61   llvm::BumpPtrAllocator Alloc;
62 };
63
64 // Create enum with OPT_xxx values for each option in Options.td
65 enum {
66   OPT_INVALID = 0,
67 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
68 #include "ELF/Options.inc"
69 #undef OPTION
70 };
71
72 // This is the class to create a .cpio file for --reproduce.
73 //
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.
78 //
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.
84 class CpioFile {
85 public:
86   static CpioFile *create(StringRef OutputPath);
87   void append(StringRef Path, StringRef Data);
88
89 private:
90   CpioFile(std::unique_ptr<llvm::raw_fd_ostream> OS, StringRef Basename);
91
92   std::unique_ptr<llvm::raw_fd_ostream> OS;
93   llvm::StringSet<> Seen;
94   std::string Basename;
95 };
96
97 void printHelp(const char *Argv0);
98 std::string getVersionString();
99 std::vector<uint8_t> parseHexstring(StringRef S);
100
101 std::string createResponseFile(const llvm::opt::InputArgList &Args);
102 std::string relativeToRoot(StringRef Path);
103
104 std::string findFromSearchPaths(StringRef Path);
105 std::string searchLibrary(StringRef Path);
106 std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
107
108 } // namespace elf
109 } // namespace lld
110
111 #endif