blob: 6756fab97a01a8e095de7e7af2e4fb4fce6e9c1d [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"
Rafael Espindolaab14c882016-04-13 19:07:40 +000015#include "llvm/ADT/Optional.h"
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000016#include "llvm/ADT/StringRef.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000017#include "llvm/Option/ArgList.h"
Rui Ueyamab6940112016-02-02 22:49:32 +000018#include "llvm/Support/raw_ostream.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000019
20namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000021namespace elf {
Michael J. Spencer84487f12015-07-24 21:03:07 +000022
Rui Ueyama983ed2b2015-10-01 15:23:09 +000023extern class LinkerDriver *Driver;
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000024
Michael J. Spencer84487f12015-07-24 21:03:07 +000025class LinkerDriver {
26public:
Rui Ueyama3ce825e2015-10-09 21:07:25 +000027 void main(ArrayRef<const char *> Args);
Rui Ueyama983ed2b2015-10-01 15:23:09 +000028 void addFile(StringRef Path);
Rui Ueyama21eecb42016-02-02 21:13:09 +000029 void addLibrary(StringRef Name);
Michael J. Spencer84487f12015-07-24 21:03:07 +000030
31private:
Peter Collingbourned418b1d2016-03-31 23:12:18 +000032 std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
Adhemerval Zanella9df07202016-04-13 18:51:11 +000033 llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
Rui Ueyamad441d752016-01-07 17:54:21 +000034 void readConfigs(llvm::opt::InputArgList &Args);
Adhemerval Zanella9df07202016-04-13 18:51:11 +000035 void readDynamicList(StringRef Path);
Rui Ueyamad441d752016-01-07 17:54:21 +000036 void createFiles(llvm::opt::InputArgList &Args);
37 template <class ELFT> void link(llvm::opt::InputArgList &Args);
Denis Protivensky1ef7b3f2015-10-07 09:13:03 +000038
Rui Ueyamaf8baa662016-04-07 19:24:51 +000039 // True if we are in --whole-archive and --no-whole-archive.
Rui Ueyama3ce825e2015-10-09 21:07:25 +000040 bool WholeArchive = false;
Rui Ueyamaf8baa662016-04-07 19:24:51 +000041
42 // True if we are in --start-lib and --end-lib.
43 bool InLib = false;
44
45 llvm::BumpPtrAllocator Alloc;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000046 std::vector<std::unique_ptr<InputFile>> Files;
Rui Ueyama983ed2b2015-10-01 15:23:09 +000047 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
Michael J. Spencer84487f12015-07-24 21:03:07 +000048};
49
Rui Ueyamac6e1b972015-10-11 18:19:01 +000050// Parses command line options.
Rui Ueyama15fa0352016-03-15 18:20:50 +000051class ELFOptTable : public llvm::opt::OptTable {
52public:
53 ELFOptTable();
54 llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
55
56private:
57 llvm::BumpPtrAllocator Alloc;
58};
Rui Ueyamac6e1b972015-10-11 18:19:01 +000059
Michael J. Spencer84487f12015-07-24 21:03:07 +000060// Create enum with OPT_xxx values for each option in Options.td
61enum {
62 OPT_INVALID = 0,
63#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
64#include "Options.inc"
65#undef OPTION
66};
67
Rui Ueyama1eb9f442016-02-28 03:18:09 +000068void printHelp(const char *Argv0);
Rui Ueyama1abcf372016-02-28 03:18:07 +000069void printVersion();
70
Rui Ueyama52a15092015-10-11 03:28:42 +000071std::string findFromSearchPaths(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000072std::string searchLibrary(StringRef Path);
73std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
74
Rafael Espindolae0df00b2016-02-28 00:25:54 +000075} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +000076} // namespace lld
77
78#endif