blob: 0e9aaa9d6f4c8e405499643b70bcdd6e523a6f96 [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"
Rui Ueyamab6940112016-02-02 22:49:32 +000017#include "llvm/Support/raw_ostream.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000018
19namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000020namespace elf {
Michael J. Spencer84487f12015-07-24 21:03:07 +000021
Rui Ueyama983ed2b2015-10-01 15:23:09 +000022extern class LinkerDriver *Driver;
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000023
Michael J. Spencer84487f12015-07-24 21:03:07 +000024class LinkerDriver {
25public:
Rui Ueyama3ce825e2015-10-09 21:07:25 +000026 void main(ArrayRef<const char *> Args);
Rui Ueyama983ed2b2015-10-01 15:23:09 +000027 void addFile(StringRef Path);
Rui Ueyama21eecb42016-02-02 21:13:09 +000028 void addLibrary(StringRef Name);
Michael J. Spencer84487f12015-07-24 21:03:07 +000029
30private:
Peter Collingbourned418b1d2016-03-31 23:12:18 +000031 std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
Rui Ueyamad441d752016-01-07 17:54:21 +000032 void readConfigs(llvm::opt::InputArgList &Args);
33 void createFiles(llvm::opt::InputArgList &Args);
34 template <class ELFT> void link(llvm::opt::InputArgList &Args);
Denis Protivensky1ef7b3f2015-10-07 09:13:03 +000035
Rui Ueyamaa47ee682015-10-11 01:53:04 +000036 llvm::BumpPtrAllocator Alloc;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000037 bool WholeArchive = false;
38 std::vector<std::unique_ptr<InputFile>> Files;
Rui Ueyama983ed2b2015-10-01 15:23:09 +000039 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
Michael J. Spencer84487f12015-07-24 21:03:07 +000040};
41
Rui Ueyamac6e1b972015-10-11 18:19:01 +000042// Parses command line options.
Rui Ueyama15fa0352016-03-15 18:20:50 +000043class ELFOptTable : public llvm::opt::OptTable {
44public:
45 ELFOptTable();
46 llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
47
48private:
49 llvm::BumpPtrAllocator Alloc;
50};
Rui Ueyamac6e1b972015-10-11 18:19:01 +000051
Michael J. Spencer84487f12015-07-24 21:03:07 +000052// Create enum with OPT_xxx values for each option in Options.td
53enum {
54 OPT_INVALID = 0,
55#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
56#include "Options.inc"
57#undef OPTION
58};
59
Rui Ueyama1eb9f442016-02-28 03:18:09 +000060void printHelp(const char *Argv0);
Rui Ueyama1abcf372016-02-28 03:18:07 +000061void printVersion();
62
Rui Ueyama52a15092015-10-11 03:28:42 +000063std::string findFromSearchPaths(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000064std::string searchLibrary(StringRef Path);
65std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
66
Rafael Espindolae0df00b2016-02-28 00:25:54 +000067} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +000068} // namespace lld
69
70#endif