blob: 70cdb58ff2740e15f4274d8c7333fd671a0bb436 [file] [log] [blame]
Rafael Espindolabeee25e2015-08-14 14:12:54 +00001//===- Driver.h -------------------------------------------------*- C++ -*-===//
Michael J. Spencer84487f12015-07-24 21:03:07 +00002//
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
Rui Ueyama983ed2b2015-10-01 15:23:09 +000013#include "SymbolTable.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000014#include "lld/Core/LLVM.h"
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000015#include "llvm/ADT/StringRef.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000016#include "llvm/Option/ArgList.h"
17
18namespace lld {
19namespace elf2 {
20
Rui Ueyama983ed2b2015-10-01 15:23:09 +000021extern class LinkerDriver *Driver;
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000022
Michael J. Spencer84487f12015-07-24 21:03:07 +000023// Entry point of the ELF linker.
24void link(ArrayRef<const char *> Args);
25
Michael J. Spencer84487f12015-07-24 21:03:07 +000026class ArgParser {
27public:
28 // Parses command line options.
29 llvm::opt::InputArgList parse(ArrayRef<const char *> Args);
Rui Ueyamaeeb22f82015-09-25 15:37:33 +000030
31private:
32 llvm::BumpPtrAllocator Alloc;
Michael J. Spencer84487f12015-07-24 21:03:07 +000033};
34
35class LinkerDriver {
36public:
37 void link(ArrayRef<const char *> Args);
Rui Ueyama983ed2b2015-10-01 15:23:09 +000038 void addFile(StringRef Path);
Michael J. Spencer84487f12015-07-24 21:03:07 +000039
40private:
Denis Protivensky1ef7b3f2015-10-07 09:13:03 +000041 template <template <class> class T>
42 std::unique_ptr<ELFFileBase> createELFInputFile(MemoryBufferRef MB);
43
Rui Ueyama983ed2b2015-10-01 15:23:09 +000044 SymbolTable Symtab;
Michael J. Spencer84487f12015-07-24 21:03:07 +000045 ArgParser Parser;
Rui Ueyama983ed2b2015-10-01 15:23:09 +000046 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
Michael J. Spencer84487f12015-07-24 21:03:07 +000047};
48
49// Create enum with OPT_xxx values for each option in Options.td
50enum {
51 OPT_INVALID = 0,
52#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
53#include "Options.inc"
54#undef OPTION
55};
56
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000057// Parses a linker script. Calling this function updates the Symtab and Config.
Rui Ueyama983ed2b2015-10-01 15:23:09 +000058void readLinkerScript(MemoryBufferRef MB);
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000059
Michael J. Spencer84487f12015-07-24 21:03:07 +000060} // namespace elf2
61} // namespace lld
62
63#endif