blob: 2f72838edae438268036c28bfaa1828f15e47da5 [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:
Rafael Espindolacb09daa2016-10-26 18:59:00 +000029 void main(ArrayRef<const char *> Args, bool CanExitEarly);
Rui Ueyamad6877632016-10-20 05:03:49 +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 std::unique_ptr<CpioFile> Cpio; // for reproduce
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000033
Michael J. Spencer84487f12015-07-24 21:03:07 +000034private:
Peter Collingbourned418b1d2016-03-31 23:12:18 +000035 std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
Adhemerval Zanella9df07202016-04-13 18:51:11 +000036 llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
Rui Ueyamad441d752016-01-07 17:54:21 +000037 void readConfigs(llvm::opt::InputArgList &Args);
38 void createFiles(llvm::opt::InputArgList &Args);
Rui Ueyamac185c012016-10-20 04:47:47 +000039 void inferMachineType();
Rui Ueyamad441d752016-01-07 17:54:21 +000040 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 Ueyamac773c9f2016-10-26 04:01:07 +000043 bool InWholeArchive = 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
Rui Ueyamac3d15122016-10-20 05:12:29 +000048 // True if we are in -format=binary and -format=elf.
49 bool InBinary = false;
50
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000051 std::vector<InputFile *> Files;
Rui Ueyama983ed2b2015-10-01 15:23:09 +000052 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
Michael J. Spencer84487f12015-07-24 21:03:07 +000053};
54
Rui Ueyamac6e1b972015-10-11 18:19:01 +000055// Parses command line options.
Rui Ueyama15fa0352016-03-15 18:20:50 +000056class ELFOptTable : public llvm::opt::OptTable {
57public:
58 ELFOptTable();
59 llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
Rui Ueyama15fa0352016-03-15 18:20:50 +000060};
Rui Ueyamac6e1b972015-10-11 18:19:01 +000061
Michael J. Spencer84487f12015-07-24 21:03:07 +000062// Create enum with OPT_xxx values for each option in Options.td
63enum {
64 OPT_INVALID = 0,
65#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
66#include "Options.inc"
67#undef OPTION
68};
69
Rui Ueyama1eb9f442016-02-28 03:18:09 +000070void printHelp(const char *Argv0);
Rui Ueyama9194db72016-05-13 21:55:56 +000071std::vector<uint8_t> parseHexstring(StringRef S);
Rui Ueyama1abcf372016-02-28 03:18:07 +000072
Rui Ueyamafe658772016-05-15 17:10:23 +000073std::string createResponseFile(const llvm::opt::InputArgList &Args);
Rui Ueyama9aea9572016-04-30 22:23:29 +000074
Rui Ueyama52a15092015-10-11 03:28:42 +000075std::string findFromSearchPaths(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000076std::string searchLibrary(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000077
Rafael Espindolae0df00b2016-02-28 00:25:54 +000078} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +000079} // namespace lld
80
81#endif