xref: /freebsd/contrib/llvm-project/lld/ELF/Driver.h (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
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 "lld/Common/LLVM.h"
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Option/ArgList.h"
17 
18 namespace lld {
19 namespace elf {
20 class InputFile;
21 class Symbol;
22 
23 extern std::unique_ptr<class LinkerDriver> driver;
24 
25 class LinkerDriver {
26 public:
27   void linkerMain(ArrayRef<const char *> args);
28   void addFile(StringRef path, bool withLOption);
29   void addLibrary(StringRef name);
30 
31 private:
32   void createFiles(llvm::opt::InputArgList &args);
33   void inferMachineType();
34   void link(llvm::opt::InputArgList &args);
35   template <class ELFT> void compileBitcodeFiles(bool skipLinkedOutput);
36 
37   // True if we are in --whole-archive and --no-whole-archive.
38   bool inWholeArchive = false;
39 
40   // True if we are in --start-lib and --end-lib.
41   bool inLib = false;
42 
43   // For LTO.
44   std::unique_ptr<BitcodeCompiler> lto;
45 
46   std::vector<InputFile *> files;
47 
48 public:
49   SmallVector<std::pair<StringRef, unsigned>, 0> archiveFiles;
50 };
51 
52 // Parses command line options.
53 class ELFOptTable : public llvm::opt::OptTable {
54 public:
55   ELFOptTable();
56   llvm::opt::InputArgList parse(ArrayRef<const char *> argv);
57 };
58 
59 // Create enum with OPT_xxx values for each option in Options.td
60 enum {
61   OPT_INVALID = 0,
62 #define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
63 #include "Options.inc"
64 #undef OPTION
65 };
66 
67 void printHelp();
68 std::string createResponseFile(const llvm::opt::InputArgList &args);
69 
70 llvm::Optional<std::string> findFromSearchPaths(StringRef path);
71 llvm::Optional<std::string> searchScript(StringRef path);
72 llvm::Optional<std::string> searchLibraryBaseName(StringRef path);
73 llvm::Optional<std::string> searchLibrary(StringRef path);
74 
75 } // namespace elf
76 } // namespace lld
77 
78 #endif
79