blob: a8c6e9c4228cecae2fbd1f043f92383c0e63814a [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"
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000015#include "llvm/ADT/StringRef.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000016#include "llvm/Option/ArgList.h"
Rui Ueyamab6940112016-02-02 22:49:32 +000017#include "llvm/Support/raw_ostream.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000018
19namespace lld {
20namespace elf2 {
21
Rui Ueyama983ed2b2015-10-01 15:23:09 +000022extern class LinkerDriver *Driver;
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000023
Rui Ueyama64cfffd2016-01-28 18:40:06 +000024// Entry point of the ELF linker. Returns true on success.
Rui Ueyamab6940112016-02-02 22:49:32 +000025bool link(ArrayRef<const char *> Args, llvm::raw_ostream &Error = llvm::errs());
Michael J. Spencer84487f12015-07-24 21:03:07 +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);
Michael J. Spencer84487f12015-07-24 21:03:07 +000032
33private:
Rui Ueyamad441d752016-01-07 17:54:21 +000034 void readConfigs(llvm::opt::InputArgList &Args);
35 void createFiles(llvm::opt::InputArgList &Args);
36 template <class ELFT> void link(llvm::opt::InputArgList &Args);
Denis Protivensky1ef7b3f2015-10-07 09:13:03 +000037
Rui Ueyamaa47ee682015-10-11 01:53:04 +000038 llvm::BumpPtrAllocator Alloc;
Rui Ueyama3ce825e2015-10-09 21:07:25 +000039 bool WholeArchive = false;
40 std::vector<std::unique_ptr<InputFile>> Files;
Rui Ueyama983ed2b2015-10-01 15:23:09 +000041 std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
Michael J. Spencer84487f12015-07-24 21:03:07 +000042};
43
Rui Ueyamac6e1b972015-10-11 18:19:01 +000044// Parses command line options.
45llvm::opt::InputArgList parseArgs(llvm::BumpPtrAllocator *A,
46 ArrayRef<const char *> Args);
47
Michael J. Spencer84487f12015-07-24 21:03:07 +000048// Create enum with OPT_xxx values for each option in Options.td
49enum {
50 OPT_INVALID = 0,
51#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
52#include "Options.inc"
53#undef OPTION
54};
55
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000056// Parses a linker script. Calling this function updates the Symtab and Config.
Rui Ueyamaa47ee682015-10-11 01:53:04 +000057void readLinkerScript(llvm::BumpPtrAllocator *A, MemoryBufferRef MB);
Rui Ueyamaf5c4aca2015-09-30 17:06:09 +000058
Rui Ueyama52a15092015-10-11 03:28:42 +000059std::string findFromSearchPaths(StringRef Path);
Rui Ueyama4b02ca92015-10-11 03:28:39 +000060std::string searchLibrary(StringRef Path);
61std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
62
Michael J. Spencer84487f12015-07-24 21:03:07 +000063} // namespace elf2
64} // namespace lld
65
66#endif