xref: /freebsd/contrib/llvm-project/lld/ELF/Driver.h (revision 716fd348)
1 //===- Driver.h -------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_ELF_DRIVER_H
10 #define LLD_ELF_DRIVER_H
11 
12 #include "LTO.h"
13 #include "SymbolTable.h"
14 #include "lld/Common/LLVM.h"
15 #include "lld/Common/Reproduce.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/StringSet.h"
19 #include "llvm/Option/ArgList.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 namespace lld {
23 namespace elf {
24 
25 extern std::unique_ptr<class LinkerDriver> driver;
26 
27 class LinkerDriver {
28 public:
29   void linkerMain(ArrayRef<const char *> args);
30   void addFile(StringRef path, bool withLOption);
31   void addLibrary(StringRef name);
32 
33 private:
34   void createFiles(llvm::opt::InputArgList &args);
35   void inferMachineType();
36   void link(llvm::opt::InputArgList &args);
37   template <class ELFT> void compileBitcodeFiles(bool skipLinkedOutput);
38 
39   // True if we are in --whole-archive and --no-whole-archive.
40   bool inWholeArchive = false;
41 
42   // True if we are in --start-lib and --end-lib.
43   bool inLib = false;
44 
45   // For LTO.
46   std::unique_ptr<BitcodeCompiler> lto;
47 
48   std::vector<InputFile *> files;
49 };
50 
51 // Parses command line options.
52 class ELFOptTable : public llvm::opt::OptTable {
53 public:
54   ELFOptTable();
55   llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
56 };
57 
58 // Create enum with OPT_xxx values for each option in Options.td
59 enum {
60   OPT_INVALID = 0,
61 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
62 #include "Options.inc"
63 #undef OPTION
64 };
65 
66 void printHelp();
67 std::string createResponseFile(const llvm::opt::InputArgList &args);
68 
69 llvm::Optional<std::string> findFromSearchPaths(StringRef path);
70 llvm::Optional<std::string> searchScript(StringRef path);
71 llvm::Optional<std::string> searchLibraryBaseName(StringRef path);
72 llvm::Optional<std::string> searchLibrary(StringRef path);
73 
74 } // namespace elf
75 } // namespace lld
76 
77 #endif
78