aboutsummaryrefslogtreecommitdiff
path: root/ELF/Driver.h
blob: 8bb2093e86caef90c9622044d3a1ca36bb5f9d42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//===- Driver.h -------------------------------------------------*- C++ -*-===//
//
//                             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

#include "SymbolTable.h"
#include "lld/Core/LLVM.h"
#include "lld/Core/Reproduce.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/raw_ostream.h"

namespace lld {
namespace elf {

extern class LinkerDriver *Driver;

class LinkerDriver {
public:
  void main(ArrayRef<const char *> Args, bool CanExitEarly);
  void addFile(StringRef Path);
  void addLibrary(StringRef Name);

private:
  std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
  void readConfigs(llvm::opt::InputArgList &Args);
  void createFiles(llvm::opt::InputArgList &Args);
  void inferMachineType();
  template <class ELFT> void link(llvm::opt::InputArgList &Args);

  // True if we are in --whole-archive and --no-whole-archive.
  bool InWholeArchive = false;

  // True if we are in --start-lib and --end-lib.
  bool InLib = false;

  // True if we are in -format=binary and -format=elf.
  bool InBinary = false;

  std::vector<InputFile *> Files;
};

// Parses command line options.
class ELFOptTable : public llvm::opt::OptTable {
public:
  ELFOptTable();
  llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
};

// 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
};

void printHelp(const char *Argv0);
std::vector<uint8_t> parseHexstring(StringRef S);

std::string createResponseFile(const llvm::opt::InputArgList &Args);

llvm::Optional<std::string> findFromSearchPaths(StringRef Path);
llvm::Optional<std::string> searchLibrary(StringRef Path);

} // namespace elf
} // namespace lld

#endif