blob: 3a238272a44abe7c7cafbab40b742ef08d485209 [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"
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000017#include "llvm/ADT/StringSet.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000018#include "llvm/Option/ArgList.h"
Rui Ueyamab6940112016-02-02 22:49:32 +000019#include "llvm/Support/raw_ostream.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000020
21namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000022namespace elf {
Michael J. Spencer84487f12015-07-24 21:03:07 +000023
Rui Ueyama983ed2b2015-10-01 15:23:09 +000024extern class LinkerDriver *Driver;
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000025
Michael J. Spencer84487f12015-07-24 21:03:07 +000026class LinkerDriver {
27public:
Rui Ueyama3ce825e2015-10-09 21:07:25 +000028 void main(ArrayRef<const char *> Args);
Rui Ueyama983ed2b2015-10-01 15:23:09 +000029 void addFile(StringRef Path);
Rui Ueyama21eecb42016-02-02 21:13:09 +000030 void addLibrary(StringRef Name);
Rafael Espindola156f4ee2016-04-28 19:30:41 +000031 llvm::LLVMContext Context;
Michael J. Spencer84487f12015-07-24 21:03:07 +000032
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000033 // for --reproduce
34 std::unique_ptr<llvm::raw_fd_ostream> ReproduceArchive;
35 llvm::StringSet<> IncludedFiles;
36
Michael J. Spencer84487f12015-07-24 21:03:07 +000037private:
Peter Collingbourned418b1d2016-03-31 23:12:18 +000038 std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB);
Adhemerval Zanella9df07202016-04-13 18:51:11 +000039 llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
Rui Ueyamad441d752016-01-07 17:54:21 +000040 void readConfigs(llvm::opt::InputArgList &Args);
41 void createFiles(llvm::opt::InputArgList &Args);
42 template <class ELFT> void link(llvm::opt::InputArgList &Args);
Denis Protivensky1ef7b3f2015-10-07 09:13:03 +000043
Rui Ueyamaf8baa662016-04-07 19:24:51 +000044 // True if we are in --whole-archive and --no-whole-archive.
Rui Ueyama3ce825e2015-10-09 21:07:25 +000045 bool WholeArchive = false;
Rui Ueyamaf8baa662016-04-07 19:24:51 +000046
47 // True if we are in --start-lib and --end-lib.
48 bool InLib = false;
49
50 llvm::BumpPtrAllocator Alloc;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000051 std::vector<std::unique_ptr<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);
60
61private:
62 llvm::BumpPtrAllocator Alloc;
63};
Rui Ueyamac6e1b972015-10-11 18:19:01 +000064
Michael J. Spencer84487f12015-07-24 21:03:07 +000065// Create enum with OPT_xxx values for each option in Options.td
66enum {
67 OPT_INVALID = 0,
68#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
69#include "Options.inc"
70#undef OPTION
71};
72
Rui Ueyama1eb9f442016-02-28 03:18:09 +000073void printHelp(const char *Argv0);
Rui Ueyama1abcf372016-02-28 03:18:07 +000074void printVersion();
75
Rui Ueyama9aea9572016-04-30 22:23:29 +000076void createResponseFile(const llvm::opt::InputArgList &Args);
Rafael Espindola1dd2b3d2016-05-03 17:30:44 +000077void maybeCopyInputFile(StringRef Path, StringRef Buffer);
Rui Ueyama9aea9572016-04-30 22:23:29 +000078
Rui Ueyama52a15092015-10-11 03:28:42 +000079std::string findFromSearchPaths(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000080std::string searchLibrary(StringRef Path);
81std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
82
Rafael Espindolae0df00b2016-02-28 00:25:54 +000083} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +000084} // namespace lld
85
86#endif