blob: 3e4e1308532470e14c27d0f761d14a15679b327a [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"
Rui Ueyama3f851702017-10-02 21:00:41 +000014#include "lld/Common/LLVM.h"
15#include "lld/Common/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 Ueyama7c9ad292018-02-16 23:41:48 +000029 void main(ArrayRef<const char *> Args);
Evgeniy Stepanova76349b2017-04-12 00:13:48 +000030 void addFile(StringRef Path, bool WithLOption);
Rui Ueyama21eecb42016-02-02 21:13:09 +000031 void addLibrary(StringRef Name);
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000032
Michael J. Spencer84487f12015-07-24 21:03:07 +000033private:
Rui Ueyamad441d752016-01-07 17:54:21 +000034 void readConfigs(llvm::opt::InputArgList &Args);
35 void createFiles(llvm::opt::InputArgList &Args);
Rui Ueyamac185c012016-10-20 04:47:47 +000036 void inferMachineType();
Rui Ueyamad441d752016-01-07 17:54:21 +000037 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 Ueyamac773c9f2016-10-26 04:01:07 +000040 bool InWholeArchive = 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
Rui Ueyamac3d15122016-10-20 05:12:29 +000045 // True if we are in -format=binary and -format=elf.
46 bool InBinary = false;
47
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000048 std::vector<InputFile *> Files;
Michael J. Spencer84487f12015-07-24 21:03:07 +000049};
50
Rui Ueyamac6e1b972015-10-11 18:19:01 +000051// Parses command line options.
Rui Ueyama15fa0352016-03-15 18:20:50 +000052class ELFOptTable : public llvm::opt::OptTable {
53public:
54 ELFOptTable();
55 llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
Rui Ueyama15fa0352016-03-15 18:20:50 +000056};
Rui Ueyamac6e1b972015-10-11 18:19:01 +000057
Michael J. Spencer84487f12015-07-24 21:03:07 +000058// Create enum with OPT_xxx values for each option in Options.td
59enum {
60 OPT_INVALID = 0,
Yuka Takahashiba5d4af2017-06-20 16:31:31 +000061#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
Michael J. Spencer84487f12015-07-24 21:03:07 +000062#include "Options.inc"
63#undef OPTION
64};
65
Rafael Espindola64626b32018-02-06 22:37:05 +000066void printHelp();
Rui Ueyamafe658772016-05-15 17:10:23 +000067std::string createResponseFile(const llvm::opt::InputArgList &Args);
Rui Ueyama9aea9572016-04-30 22:23:29 +000068
Rui Ueyama061f9282016-11-19 19:23:58 +000069llvm::Optional<std::string> findFromSearchPaths(StringRef Path);
Alexander Richardson1de78472017-11-20 15:43:20 +000070llvm::Optional<std::string> searchLinkerScript(StringRef Path);
Rui Ueyama061f9282016-11-19 19:23:58 +000071llvm::Optional<std::string> searchLibrary(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000072
Rafael Espindolae0df00b2016-02-28 00:25:54 +000073} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +000074} // namespace lld
75
76#endif