blob: 9726430f2f415a22a57aa3b6fd5e03d16a72dc29 [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"
Peter Collingbournefeee2102016-07-26 02:00:42 +000015#include "lld/Core/Reproduce.h"
Rafael Espindolaab14c882016-04-13 19:07:40 +000016#include "llvm/ADT/Optional.h"
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000017#include "llvm/ADT/StringRef.h"
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000018#include "llvm/ADT/StringSet.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000019#include "llvm/Option/ArgList.h"
Rui Ueyamab6940112016-02-02 22:49:32 +000020#include "llvm/Support/raw_ostream.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000021
22namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000023namespace elf {
Michael J. Spencer84487f12015-07-24 21:03:07 +000024
Rui Ueyama983ed2b2015-10-01 15:23:09 +000025extern class LinkerDriver *Driver;
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000026
Michael J. Spencer84487f12015-07-24 21:03:07 +000027class LinkerDriver {
28public:
Rui Ueyama3ce825e2015-10-09 21:07:25 +000029 void main(ArrayRef<const char *> Args);
Rui Ueyama983ed2b2015-10-01 15:23:09 +000030 void addFile(StringRef Path);
Rui Ueyama21eecb42016-02-02 21:13:09 +000031 void addLibrary(StringRef Name);
Rui Ueyamafe658772016-05-15 17:10:23 +000032 llvm::LLVMContext Context; // to parse bitcode ifles
33 std::unique_ptr<CpioFile> Cpio; // for reproduce
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000034
Michael J. Spencer84487f12015-07-24 21:03:07 +000035private:
Peter Collingbourned418b1d2016-03-31 23:12:18 +000036 std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
Adhemerval Zanella9df07202016-04-13 18:51:11 +000037 llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
Rui Ueyamad441d752016-01-07 17:54:21 +000038 void readConfigs(llvm::opt::InputArgList &Args);
39 void createFiles(llvm::opt::InputArgList &Args);
40 template <class ELFT> void link(llvm::opt::InputArgList &Args);
Denis Protivensky1ef7b3f2015-10-07 09:13:03 +000041
Rui Ueyamaf8baa662016-04-07 19:24:51 +000042 // True if we are in --whole-archive and --no-whole-archive.
Rui Ueyama3ce825e2015-10-09 21:07:25 +000043 bool WholeArchive = false;
Rui Ueyamaf8baa662016-04-07 19:24:51 +000044
45 // True if we are in --start-lib and --end-lib.
46 bool InLib = false;
47
48 llvm::BumpPtrAllocator Alloc;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000049 std::vector<std::unique_ptr<InputFile>> Files;
Rui Ueyama983ed2b2015-10-01 15:23:09 +000050 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
Michael J. Spencer84487f12015-07-24 21:03:07 +000051};
52
Rui Ueyamac6e1b972015-10-11 18:19:01 +000053// Parses command line options.
Rui Ueyama15fa0352016-03-15 18:20:50 +000054class ELFOptTable : public llvm::opt::OptTable {
55public:
56 ELFOptTable();
57 llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
58
59private:
60 llvm::BumpPtrAllocator Alloc;
61};
Rui Ueyamac6e1b972015-10-11 18:19:01 +000062
Michael J. Spencer84487f12015-07-24 21:03:07 +000063// Create enum with OPT_xxx values for each option in Options.td
64enum {
65 OPT_INVALID = 0,
66#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
67#include "Options.inc"
68#undef OPTION
69};
70
Rui Ueyama1eb9f442016-02-28 03:18:09 +000071void printHelp(const char *Argv0);
Rui Ueyama4ffda7a2016-06-06 15:34:37 +000072std::string getVersionString();
Rui Ueyama9194db72016-05-13 21:55:56 +000073std::vector<uint8_t> parseHexstring(StringRef S);
Rui Ueyama1abcf372016-02-28 03:18:07 +000074
Rui Ueyamafe658772016-05-15 17:10:23 +000075std::string createResponseFile(const llvm::opt::InputArgList &Args);
Rui Ueyama9aea9572016-04-30 22:23:29 +000076
Rui Ueyama52a15092015-10-11 03:28:42 +000077std::string findFromSearchPaths(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000078std::string searchLibrary(StringRef Path);
79std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
80
Rafael Espindolae0df00b2016-02-28 00:25:54 +000081} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +000082} // namespace lld
83
84#endif