2015-08-14 22:12:54 +08:00
|
|
|
//===- Driver.h -------------------------------------------------*- C++ -*-===//
|
2015-07-25 05:03:07 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_DRIVER_H
|
|
|
|
#define LLD_ELF_DRIVER_H
|
|
|
|
|
2015-10-01 23:23:09 +08:00
|
|
|
#include "SymbolTable.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
2015-10-01 01:06:09 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf2 {
|
|
|
|
|
2015-10-01 23:23:09 +08:00
|
|
|
extern class LinkerDriver *Driver;
|
2015-10-01 01:06:09 +08:00
|
|
|
|
ELF: Rename error -> fatal and redefine error as a non-noreturn function.
In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.
In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.
This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.
In this patch, I rename error to fatal, and introduce another version of
error which doesn't call exit. That function instead sets HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.
I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.
http://reviews.llvm.org/D16641
llvm-svn: 259069
2016-01-29 02:40:06 +08:00
|
|
|
// Entry point of the ELF linker. Returns true on success.
|
|
|
|
bool link(ArrayRef<const char *> Args);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
class LinkerDriver {
|
|
|
|
public:
|
2015-10-10 05:07:25 +08:00
|
|
|
void main(ArrayRef<const char *> Args);
|
2015-10-01 23:23:09 +08:00
|
|
|
void addFile(StringRef Path);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
private:
|
2016-01-08 01:54:21 +08:00
|
|
|
void readConfigs(llvm::opt::InputArgList &Args);
|
|
|
|
void createFiles(llvm::opt::InputArgList &Args);
|
|
|
|
template <class ELFT> void link(llvm::opt::InputArgList &Args);
|
2015-10-07 17:13:03 +08:00
|
|
|
|
2015-10-11 09:53:04 +08:00
|
|
|
llvm::BumpPtrAllocator Alloc;
|
2015-10-10 05:07:25 +08:00
|
|
|
bool WholeArchive = false;
|
|
|
|
std::vector<std::unique_ptr<InputFile>> Files;
|
2015-10-01 23:23:09 +08:00
|
|
|
std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2015-10-12 02:19:01 +08:00
|
|
|
// Parses command line options.
|
|
|
|
llvm::opt::InputArgList parseArgs(llvm::BumpPtrAllocator *A,
|
|
|
|
ArrayRef<const char *> Args);
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// Create enum with OPT_xxx values for each option in Options.td
|
|
|
|
enum {
|
|
|
|
OPT_INVALID = 0,
|
|
|
|
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11) OPT_##ID,
|
|
|
|
#include "Options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
2015-10-01 01:06:09 +08:00
|
|
|
// Parses a linker script. Calling this function updates the Symtab and Config.
|
2015-10-11 09:53:04 +08:00
|
|
|
void readLinkerScript(llvm::BumpPtrAllocator *A, MemoryBufferRef MB);
|
2015-10-01 01:06:09 +08:00
|
|
|
|
2015-10-11 11:28:42 +08:00
|
|
|
std::string findFromSearchPaths(StringRef Path);
|
2015-10-11 11:28:39 +08:00
|
|
|
std::string searchLibrary(StringRef Path);
|
|
|
|
std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace elf2
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|