summaryrefslogtreecommitdiffstats
path: root/lld/include
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2012-05-31 22:34:00 +0000
committerNick Kledzik <kledzik@apple.com>2012-05-31 22:34:00 +0000
commitabb6981f68a0cf631b6d7d36e67127bb1af50713 (patch)
tree63d6fd7aeef209f7528fecf1a151df50f61f7fa9 /lld/include
parent5168a72b2628288c5ba3143745554e2eadbb67b0 (diff)
downloadbcm5719-llvm-abb6981f68a0cf631b6d7d36e67127bb1af50713.tar.gz
bcm5719-llvm-abb6981f68a0cf631b6d7d36e67127bb1af50713.zip
Major refactoring: Remove Platform concept. In its place there are
now Reader and Writer subclasses for each file format. Each Reader and Writer subclass defines an "options" class which controls how that Reader or Writer operates. llvm-svn: 157774
Diffstat (limited to 'lld/include')
-rw-r--r--lld/include/lld/Core/AliasAtom.h56
-rw-r--r--lld/include/lld/Core/ArchiveLibraryFile.h5
-rw-r--r--lld/include/lld/Core/DefinedAtom.h2
-rw-r--r--lld/include/lld/Core/InputFiles.h6
-rw-r--r--lld/include/lld/Core/LLVM.h2
-rw-r--r--lld/include/lld/Core/NativeReader.h40
-rw-r--r--lld/include/lld/Core/NativeWriter.h34
-rw-r--r--lld/include/lld/Core/Pass.h76
-rw-r--r--lld/include/lld/Core/Platform.h99
-rw-r--r--lld/include/lld/Core/SharedLibraryFile.h6
-rw-r--r--lld/include/lld/Core/YamlReader.h50
-rw-r--r--lld/include/lld/Core/YamlWriter.h31
-rw-r--r--lld/include/lld/Reader/Reader.h29
-rw-r--r--lld/include/lld/ReaderWriter/Reader.h74
-rw-r--r--lld/include/lld/ReaderWriter/ReaderELF.h65
-rw-r--r--lld/include/lld/ReaderWriter/ReaderMachO.h68
-rw-r--r--lld/include/lld/ReaderWriter/ReaderNative.h63
-rw-r--r--lld/include/lld/ReaderWriter/ReaderPECOFF.h64
-rw-r--r--lld/include/lld/ReaderWriter/ReaderYAML.h73
-rw-r--r--lld/include/lld/ReaderWriter/Writer.h86
-rw-r--r--lld/include/lld/ReaderWriter/WriterELF.h64
-rw-r--r--lld/include/lld/ReaderWriter/WriterMachO.h109
-rw-r--r--lld/include/lld/ReaderWriter/WriterNative.h63
-rw-r--r--lld/include/lld/ReaderWriter/WriterPECOFF.h63
-rw-r--r--lld/include/lld/ReaderWriter/WriterYAML.h82
25 files changed, 948 insertions, 362 deletions
diff --git a/lld/include/lld/Core/AliasAtom.h b/lld/include/lld/Core/AliasAtom.h
deleted file mode 100644
index 22dfca162ec..00000000000
--- a/lld/include/lld/Core/AliasAtom.h
+++ /dev/null
@@ -1,56 +0,0 @@
-//===- Core/AliasAtom.h - Alias to another Atom ---------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_CORE_ALIAS_ATOM_H_
-#define LLD_CORE_ALIAS_ATOM_H_
-
-#include "lld/Core/Atom.h"
-
-#include "llvm/ADT/StringRef.h"
-
-namespace lld {
-
-class AliasAtom : public Atom {
-public:
- AliasAtom(StringRef nm, const Atom &target, Atom::Scope scope)
- : Atom( target.definition()
- , Atom::combineNever
- , scope
- , target.contentType()
- , target.sectionChoice()
- , target.userVisibleName()
- , target.deadStrip()
- , target.isThumb()
- , true
- , target.alignment()
- )
- , _name(nm)
- , _aliasOf(target) {}
-
- // overrides of Atom
- virtual const File *file() const {
- return _aliasOf.file();
- }
-
- virtual bool translationUnitSource(StringRef &path) const {
- return _aliasOf.translationUnitSource(path);
- }
-
- virtual StringRef name() const {
- return _name;
- }
-
-private:
- const StringRef _name;
- const Atom &_aliasOf;
-};
-
-} // namespace lld
-
-#endif // LLD_CORE_ALIAS_ATOM_H_
diff --git a/lld/include/lld/Core/ArchiveLibraryFile.h b/lld/include/lld/Core/ArchiveLibraryFile.h
index f80b11a5221..fbeb2964838 100644
--- a/lld/include/lld/Core/ArchiveLibraryFile.h
+++ b/lld/include/lld/Core/ArchiveLibraryFile.h
@@ -26,8 +26,6 @@ namespace lld {
///
class ArchiveLibraryFile : public File {
public:
- ArchiveLibraryFile(StringRef path) : File(path) {
- }
virtual ~ArchiveLibraryFile() {
}
@@ -47,6 +45,9 @@ public:
/// specified name and return the File object for that member, or nullptr.
virtual const File *find(StringRef name, bool dataSymbolOnly) const = 0;
+protected:
+ /// only subclasses of ArchiveLibraryFile can be instantiated
+ ArchiveLibraryFile(StringRef path) : File(path) { }
};
} // namespace lld
diff --git a/lld/include/lld/Core/DefinedAtom.h b/lld/include/lld/Core/DefinedAtom.h
index 05bbf15e780..b7e269f3559 100644
--- a/lld/include/lld/Core/DefinedAtom.h
+++ b/lld/include/lld/Core/DefinedAtom.h
@@ -1,4 +1,4 @@
-//===- Core/DefinedAtom.h - The Fundamental Unit of Linking ---------------===//
+//===- Core/DefinedAtom.h - An Atom with content --------------------------===//
//
// The LLVM Linker
//
diff --git a/lld/include/lld/Core/InputFiles.h b/lld/include/lld/Core/InputFiles.h
index f3111f8d16a..c98f0d4d613 100644
--- a/lld/include/lld/Core/InputFiles.h
+++ b/lld/include/lld/Core/InputFiles.h
@@ -37,12 +37,14 @@ public:
InputFiles();
virtual ~InputFiles();
- /// Used by platforms to insert platform specific files.
+ /// Used by Writers to insert writer specific files.
virtual void prependFile(const File&);
- /// Used by platforms to insert platform specific files.
+ /// Used by Writers to insert writer specific files.
virtual void appendFile(const File&);
+ /// Transfers ownership of a vector of Files to this InputFile object.
+ virtual void appendFiles(std::vector<std::unique_ptr<File>> &files);
/// @brief iterates all atoms in initial files
virtual void forEachInitialAtom(Handler &) const;
diff --git a/lld/include/lld/Core/LLVM.h b/lld/include/lld/Core/LLVM.h
index 873dce80ffb..25bd3702ccb 100644
--- a/lld/include/lld/Core/LLVM.h
+++ b/lld/include/lld/Core/LLVM.h
@@ -23,6 +23,7 @@ namespace llvm {
// ADT's.
class StringRef;
class Twine;
+ class MemoryBuffer;
template<typename T> class ArrayRef;
template<class T> class OwningPtr;
template<unsigned InternalLen> class SmallString;
@@ -55,6 +56,7 @@ namespace lld {
// ADT's.
using llvm::StringRef;
using llvm::Twine;
+ using llvm::MemoryBuffer;
using llvm::ArrayRef;
using llvm::OwningPtr;
using llvm::SmallString;
diff --git a/lld/include/lld/Core/NativeReader.h b/lld/include/lld/Core/NativeReader.h
deleted file mode 100644
index 1f17d07d0ef..00000000000
--- a/lld/include/lld/Core/NativeReader.h
+++ /dev/null
@@ -1,40 +0,0 @@
-//===- Core/NativeReader.h - Reads llvm native object files ---------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_CORE_NATIVE_READER_H_
-#define LLD_CORE_NATIVE_READER_H_
-
-#include "lld/Core/File.h"
-
-#include "llvm/Support/system_error.h"
-
-#include <memory>
-#include <vector>
-
-namespace llvm {
- class MemoryBuffer;
- class StringRef;
-}
-
-namespace lld {
- /// parseNativeObjectFileOrSTDIN - Open the specified native object file (use
- /// stdin if the path is "-") and instantiate into an lld::File object.
- error_code parseNativeObjectFileOrSTDIN( StringRef path
- , std::unique_ptr<File> &result);
-
-
- /// parseNativeObjectFile - Parse the specified native object file
- /// (in a buffer) and instantiate into an lld::File object.
- error_code parseNativeObjectFile( std::unique_ptr<llvm::MemoryBuffer> &mb
- , StringRef path
- , std::unique_ptr<File> &result);
-
-} // namespace lld
-
-#endif // LLD_CORE_NATIVE_READER_H_
diff --git a/lld/include/lld/Core/NativeWriter.h b/lld/include/lld/Core/NativeWriter.h
deleted file mode 100644
index 80c9fe2aaa2..00000000000
--- a/lld/include/lld/Core/NativeWriter.h
+++ /dev/null
@@ -1,34 +0,0 @@
-//===- Core/NativeWriter.h - Writes native object file --------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_CORE_NATIVE_WRITER_H_
-#define LLD_CORE_NATIVE_WRITER_H_
-
-#include "lld/Core/File.h"
-
-#include "llvm/Support/raw_ostream.h"
-
-namespace llvm {
- class StringRef;
-}
-
-
-namespace lld {
-
- /// writeNativeObjectFile - writes the lld::File object in native object
- /// file format to the specified file path.
- int writeNativeObjectFile(const lld::File &, StringRef path);
-
- /// writeNativeObjectFile - writes the lld::File object in native object
- /// file format to the specified stream.
- int writeNativeObjectFile(const lld::File &, raw_ostream &);
-
-} // namespace lld
-
-#endif // LLD_CORE_NATIVE_WRITER_H_
diff --git a/lld/include/lld/Core/Pass.h b/lld/include/lld/Core/Pass.h
index de72b7d1be9..28859f0d3c1 100644
--- a/lld/include/lld/Core/Pass.h
+++ b/lld/include/lld/Core/Pass.h
@@ -11,11 +11,12 @@
#define LLD_CORE_PASS_H_
#include "lld/Core/Atom.h"
-#include "lld/Core/Platform.h"
+#include "lld/Core/Reference.h"
#include <vector>
namespace lld {
+class DefinedAtom;
///
@@ -34,43 +35,88 @@ namespace lld {
class Pass {
public:
/// Do the actual work of the Pass.
- virtual void perform() = 0;
+ virtual void perform(File& mergedFile) = 0;
protected:
// Only subclassess can be instantiated.
- Pass(File& f, Platform& p) : _file(f), _platform(p) {}
-
-
- File& _file;
- Platform& _platform;
+ Pass() { }
};
///
/// Pass for adding stubs (PLT entries) for calls to functions
-/// outside the linkage unit.
+/// outside the linkage unit. This class is subclassed by each
+/// file format Writer which implements the pure virtual methods.
///
class StubsPass : public Pass {
public:
- StubsPass(File& f, Platform& p) : Pass(f, p) {}
+ StubsPass() : Pass() {}
/// Scans all Atoms looking for call-site uses of SharedLibraryAtoms
- /// and transfroms the call-site to call a stub instead.
- virtual void perform();
+ /// and transfroms the call-site to call a stub instead using the
+ /// helper methods below.
+ virtual void perform(File& mergedFile);
+
+ /// If true, the pass should use stubs for references
+ /// to shared library symbols. If false, the pass
+ /// will generate relocations on the text segment which the
+ /// runtime loader will use to patch the program at runtime.
+ virtual bool noTextRelocs() = 0;
+
+ /// Returns whether the Reference kind is for a call site. The pass
+ /// uses this to find calls that need to be indirected through a stub.
+ virtual bool isCallSite(Reference::Kind) = 0;
+
+ /// Returns a file format specific atom for a stub/PLT entry which contains
+ /// instructions which jump to the specified atom. May be called multiple
+ /// times for the same target atom, in which case this method should return
+ /// the same stub atom.
+ virtual const DefinedAtom* getStub(const Atom &target) = 0;
+
+ /// After the default implementation of perform() is done calling getStub(),
+ /// it will call this method to add all the stub (and support) atoms to the
+ /// master file object.
+ virtual void addStubAtoms(File &masterFile) = 0;
};
+
///
/// Pass for adding GOT entries for pointers to functions/data
-/// outside the linkage unit.
+/// outside the linkage unit. This class is subclassed by each
+/// file format Writer which implements the pure virtual methods.
///
class GOTPass : public Pass {
public:
- GOTPass(File& f, Platform& p) : Pass(f, p) {}
+ GOTPass() : Pass() {}
/// Scans all Atoms looking for pointer to SharedLibraryAtoms
- /// and transfroms them to a pointer to a GOT entry.
- virtual void perform();
+ /// and transfroms them to a pointer to a GOT entry using the
+ /// helper methods below.
+ virtual void perform(File& mergedFile);
+
+ /// If true, the pass will use GOT entries for references
+ /// to shared library symbols. If false, the pass
+ /// will generate relocations on the text segment which the
+ /// runtime loader will use to patch the program at runtime.
+ virtual bool noTextRelocs() = 0;
+
+ /// Returns whether the Reference kind is a pre-instantiated GOT access.
+ /// The default implementation of perform() uses this to figure out
+ /// what GOT entries to instantiate.
+ virtual bool isGOTAccess(Reference::Kind, bool& canBypassGOT) = 0;
+
+ /// The file format Writer needs to alter the reference kind from a
+ /// pre-instantiated GOT access to an actual access. If targetIsNowGOT is
+ /// true, the pass has instantiated a GOT atom and altered the reference's
+ /// target to point to that atom. If targetIsNowGOT is false, the pass
+ /// determined a GOT entry is not needed because the reference site can
+ /// directly access the target.
+ virtual void updateReferenceToGOT(const Reference*, bool targetIsNowGOT) = 0;
+
+ /// Returns a file format specific atom for a GOT entry targeting
+ /// the specified atom.
+ virtual const DefinedAtom* makeGOTEntry(const Atom& target) = 0;
};
diff --git a/lld/include/lld/Core/Platform.h b/lld/include/lld/Core/Platform.h
deleted file mode 100644
index 2b2c8e8b5a2..00000000000
--- a/lld/include/lld/Core/Platform.h
+++ /dev/null
@@ -1,99 +0,0 @@
-//===- Core/Platform.h - Platform Interface -------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_CORE_PLATFORM_H_
-#define LLD_CORE_PLATFORM_H_
-
-#include "lld/Core/Reference.h"
-#include "lld/Core/LLVM.h"
-#include <vector>
-
-namespace lld {
-class Atom;
-class DefinedAtom;
-class UndefinedAtom;
-class SharedLibraryAtom;
-class File;
-class InputFiles;
-
-
-/// The Platform class encapsulated plaform specific linking knowledge.
-///
-/// Much of what it does is driving by platform specific linker options.
-class Platform {
-public:
- virtual ~Platform();
-
- virtual void addFiles(InputFiles&) = 0;
-
- /// Converts a reference kind string to a in-memory numeric value.
- /// For use with parsing YAML encoded object files.
- virtual Reference::Kind kindFromString(StringRef) = 0;
-
- /// Converts an in-memory reference kind value to a string.
- /// For use with writing YAML encoded object files.
- virtual StringRef kindToString(Reference::Kind) = 0;
-
- /// If true, the linker will use stubs and GOT entries for
- /// references to shared library symbols. If false, the linker
- /// will generate relocations on the text segment which the
- /// runtime loader will use to patch the program at runtime.
- virtual bool noTextRelocs() = 0;
-
- /// Returns if the Reference kind is for a call site. The "stubs" Pass uses
- /// this to find calls that need to be indirected through a stub.
- virtual bool isCallSite(Reference::Kind) = 0;
-
- /// Returns if the Reference kind is a pre-instantiated GOT access.
- /// The "got" Pass uses this to figure out what GOT entries to instantiate.
- virtual bool isGOTAccess(Reference::Kind, bool& canBypassGOT) = 0;
-
- /// The platform needs to alter the reference kind from a pre-instantiated
- /// GOT access to an actual access. If targetIsNowGOT is true, the "got"
- /// Pass has instantiated a GOT atom and altered the reference's target
- /// to point to that atom. If targetIsNowGOT is false, the "got" Pass
- /// determined a GOT entry is not needed because the reference site can
- /// directly access the target.
- virtual void updateReferenceToGOT(const Reference*, bool targetIsNowGOT) = 0;
-
- /// Returns a platform specific atom for a stub/PLT entry which will
- /// jump to the specified atom. May be called multiple times for the same
- /// target atom, in which case this method should return the same stub
- /// atom. The platform needs to maintain a list of all stubs (and
- /// associated atoms) it has created for use by addStubAtoms().
- virtual const DefinedAtom* getStub(const Atom &target, File&) = 0;
-
- /// After the stubs Pass is done calling getStub(), the Pass will call
- /// this method to add all the stub (and support) atoms to the master
- /// file object.
- virtual void addStubAtoms(File &file) = 0;
-
- /// Create a platform specific GOT atom.
- virtual const DefinedAtom* makeGOTEntry(const Atom&, File&) = 0;
-
- /// Write an executable file from the supplied file object to the
- /// supplied stream.
- virtual void writeExecutable(const lld::File &, raw_ostream &out) = 0;
-
-protected:
- Platform();
-};
-
-
-
-///
-/// Creates a platform object for linking as done on Darwin (iOS/OSX).
-///
-extern Platform *createDarwinPlatform();
-
-
-
-} // namespace lld
-
-#endif // LLD_CORE_PLATFORM_H_
diff --git a/lld/include/lld/Core/SharedLibraryFile.h b/lld/include/lld/Core/SharedLibraryFile.h
index b3cb00c94c7..9d08b0f00c5 100644
--- a/lld/include/lld/Core/SharedLibraryFile.h
+++ b/lld/include/lld/Core/SharedLibraryFile.h
@@ -22,8 +22,6 @@ namespace lld {
///
class SharedLibraryFile : public File {
public:
- SharedLibraryFile(StringRef path) : File(path) {
- }
virtual ~SharedLibraryFile() {
}
@@ -44,7 +42,9 @@ public:
/// symbol. Otherwise return nullptr.
virtual const SharedLibraryAtom *exports(StringRef name,
bool dataSymbolOnly) const;
-
+protected:
+ /// only subclasses of SharedLibraryFile can be instantiated
+ SharedLibraryFile(StringRef path) : File(path) { }
};
} // namespace lld
diff --git a/lld/include/lld/Core/YamlReader.h b/lld/include/lld/Core/YamlReader.h
deleted file mode 100644
index 5a6328c23d5..00000000000
--- a/lld/include/lld/Core/YamlReader.h
+++ /dev/null
@@ -1,50 +0,0 @@
-//===- Core/YamlReader.h - Reads YAML -------------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_CORE_YAML_READER_H_
-#define LLD_CORE_YAML_READER_H_
-
-#include "lld/Core/LLVM.h"
-
-#include "llvm/Support/system_error.h"
-
-#include <memory>
-#include <vector>
-
-namespace llvm {
-class MemoryBuffer;
-class StringRef;
-}
-
-namespace lld {
-
-class Platform;
-class File;
-
-namespace yaml {
-
- /// parseObjectTextFileOrSTDIN - Open the specified YAML file (use stdin if
- /// the path is "-") and parse into lld::File object(s) and append each to
- /// the specified vector<File*>.
- error_code parseObjectTextFileOrSTDIN( StringRef path
- , Platform&
- , std::vector<
- std::unique_ptr<const File>>&);
-
-
- /// parseObjectText - Parse the specified YAML formatted MemoryBuffer
- /// into lld::File object(s) and append each to the specified vector<File*>.
- error_code parseObjectText( llvm::MemoryBuffer *mb
- , Platform&
- , std::vector<std::unique_ptr<const File>>&);
-
-} // namespace yaml
-} // namespace lld
-
-#endif // LLD_CORE_YAML_READER_H_
diff --git a/lld/include/lld/Core/YamlWriter.h b/lld/include/lld/Core/YamlWriter.h
deleted file mode 100644
index 949e11a19da..00000000000
--- a/lld/include/lld/Core/YamlWriter.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- Core/YamlWriter.h - Writes YAML formatted object files -------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_CORE_YAML_WRITER_H_
-#define LLD_CORE_YAML_WRITER_H_
-
-#include "lld/Core/LLVM.h"
-
-#include "llvm/Support/raw_ostream.h"
-
-namespace lld {
-
-class Platform;
-class File;
-
-namespace yaml {
-
- /// writeObjectText - writes the lld::File object as in YAML
- /// format to the specified stream.
- void writeObjectText(const lld::File &, Platform &, raw_ostream &);
-
-} // namespace yaml
-} // namespace lld
-
-#endif // LLD_CORE_YAML_WRITER_H_
diff --git a/lld/include/lld/Reader/Reader.h b/lld/include/lld/Reader/Reader.h
deleted file mode 100644
index c74615b0bfe..00000000000
--- a/lld/include/lld/Reader/Reader.h
+++ /dev/null
@@ -1,29 +0,0 @@
-//===- Reader.h - Create object file readers ------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_READER_H_
-#define LLD_READER_READER_H_
-
-#include "llvm/ADT/OwningPtr.h"
-
-#include <memory>
-
-namespace llvm {
- class error_code;
- class MemoryBuffer;
-}
-
-namespace lld {
- class File;
-
- llvm::error_code parseCOFFObjectFile(std::unique_ptr<llvm::MemoryBuffer> MB,
- std::unique_ptr<File> &Result);
-}
-
-#endif
diff --git a/lld/include/lld/ReaderWriter/Reader.h b/lld/include/lld/ReaderWriter/Reader.h
new file mode 100644
index 00000000000..8f590bc333b
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/Reader.h
@@ -0,0 +1,74 @@
+//===- ReaderWriter/Reader.h - Abstract File Format Reading Interface -----===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_READER_H_
+#define LLD_READERWRITER_READER_H_
+
+#include "lld/Core/LLVM.h"
+#include <memory>
+#include <vector>
+
+namespace lld {
+class File;
+
+///
+/// The Reader is an abstract class for reading object files,
+/// library files, and executable files. Each file format
+/// (e.g. ELF, mach-o, PECOFF, native, etc) have a concrete subclass
+/// of Reader.
+///
+class Reader {
+public:
+ virtual ~Reader();
+
+
+ /// Parse a file given its file system path and create a File object.
+ virtual error_code readFile(StringRef path,
+ std::vector<std::unique_ptr<File>> &result);
+
+ /// Parse a supplied buffer (already filled with the contents of a file)
+ /// and create a File object.
+ /// On success, the resulting File object takes ownership of
+ /// the MemoryBuffer.
+ virtual error_code parseFile(std::unique_ptr<MemoryBuffer> mb,
+ std::vector<std::unique_ptr<File>> &result) = 0;
+
+protected:
+ // only concrete subclasses can be instantiated
+ Reader();
+};
+
+
+
+///
+/// The ReaderOptions encapsulates the options used by all Readers.
+/// Each file format defines a subclass of ReaderOptions
+/// to hold file format specific options. The option objects are the only
+/// way to control the behaviour of Readers.
+///
+class ReaderOptions {
+public:
+ // Any options common to all file format Readers will go here.
+
+protected:
+ // only concrete subclasses can be instantiated
+ ReaderOptions();
+};
+
+
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_READER_H_
+
+
+
+
diff --git a/lld/include/lld/ReaderWriter/ReaderELF.h b/lld/include/lld/ReaderWriter/ReaderELF.h
new file mode 100644
index 00000000000..5644b81fa25
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/ReaderELF.h
@@ -0,0 +1,65 @@
+//===- ReaderWriter/ReaderELF.h - ELF File Format Reading Interface -------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_READER_ELF_H_
+#define LLD_READERWRITER_READER_ELF_H_
+
+#include "lld/ReaderWriter/Reader.h"
+#include "lld/Core/LLVM.h"
+
+
+namespace lld {
+
+///
+/// The ReaderOptionsELF class encapsulates options needed
+/// to process mach-o files. You can create an ReaderOptionsELF
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class ReaderOptionsELF : public ReaderOptions {
+public:
+ virtual ~ReaderOptionsELF();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ ReaderOptionsELF(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ ReaderOptionsELF();
+
+
+
+protected:
+};
+
+
+
+
+///
+/// The only way to instantiate a ReaderELF object
+/// is via this createReaderELF function. The is no public
+/// ReaderELF class that you might be tempted to subclass.
+/// Support for all variants must be represented in the ReaderOptionsELF
+/// object.
+/// The Reader object created retains a reference to the
+/// ReaderOptionsELF object supplied, so the objects object must not be
+/// destroyed before the Reader object.
+///
+Reader* createReaderELF(const ReaderOptionsELF &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_READER_ELF_H_
diff --git a/lld/include/lld/ReaderWriter/ReaderMachO.h b/lld/include/lld/ReaderWriter/ReaderMachO.h
new file mode 100644
index 00000000000..669a199b7ab
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/ReaderMachO.h
@@ -0,0 +1,68 @@
+//===- ReaderWriter/ReaderMachO.h - MachO File Format Reading Interface ---===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READER_WRITER_READER_MACHO_H_
+#define LLD_READER_WRITER_READER_MACHO_H_
+
+#include "lld/ReaderWriter/Reader.h"
+#include "lld/Core/LLVM.h"
+#include "llvm/ADT/StringRef.h"
+
+
+namespace lld {
+
+///
+/// The ReaderOptionsMachO class encapsulates options needed
+/// to process mach-o files. You can create an ReaderOptionsMachO
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class ReaderOptionsMachO : public ReaderOptions {
+public:
+ virtual ~ReaderOptionsMachO() { }
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ ReaderOptionsMachO(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ ReaderOptionsMachO();
+
+
+ StringRef archName() const { return _archName; }
+
+protected:
+ StringRef _archName;
+};
+
+
+
+
+///
+/// The only way to instantiate a ReaderMachO object
+/// is via this createReaderMachO function. The is no public
+/// ReaderMachO class that you might be tempted to subclass.
+/// Support for all variants must be represented in the ReaderOptionsMachO
+/// object.
+/// The Reader object created retains a reference to the
+/// ReaderOptionsMachO object supplied, so the objects object must not be
+/// destroyed before the Reader object.
+///
+Reader* createReaderMachO(const ReaderOptionsMachO &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READER_WRITER_READER_MACHO_H_
diff --git a/lld/include/lld/ReaderWriter/ReaderNative.h b/lld/include/lld/ReaderWriter/ReaderNative.h
new file mode 100644
index 00000000000..21f4415536d
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/ReaderNative.h
@@ -0,0 +1,63 @@
+//===- ReaderWriter/ReaderNative.h - Native File Format Reading Interface ---===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_READER_NATIVE_H_
+#define LLD_READERWRITER_READER_NATIVE_H_
+
+#include "lld/ReaderWriter/Reader.h"
+#include "lld/Core/LLVM.h"
+
+
+namespace lld {
+
+///
+/// The ReaderOptionsNative class encapsulates options needed
+/// to process mach-o files. You can create an ReaderOptionsNative
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class ReaderOptionsNative : public ReaderOptions {
+public:
+ virtual ~ReaderOptionsNative();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ ReaderOptionsNative(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ ReaderOptionsNative();
+
+protected:
+};
+
+
+
+
+///
+/// The only way to instantiate a ReaderNative object
+/// is via this createReaderNative function. The is no public
+/// ReaderNative class that you might be tempted to subclass.
+/// Support for all variants must be represented in the ReaderOptionsNative
+/// object.
+/// The Reader object created retains a reference to the
+/// ReaderOptionsNative object supplied, so the objects object must not be
+/// destroyed before the Reader object.
+///
+Reader* createReaderNative(const ReaderOptionsNative &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_READER_NATIVE_H_
diff --git a/lld/include/lld/ReaderWriter/ReaderPECOFF.h b/lld/include/lld/ReaderWriter/ReaderPECOFF.h
new file mode 100644
index 00000000000..cb1dc375491
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/ReaderPECOFF.h
@@ -0,0 +1,64 @@
+//===- ReaderWriter/ReaderPECOFF.h - PECOFF File Format Reading Interface ---===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_READER_PECOFF_H_
+#define LLD_READERWRITER_READER_PECOFF_H_
+
+#include "lld/ReaderWriter/Reader.h"
+#include "lld/Core/LLVM.h"
+
+
+namespace lld {
+
+///
+/// The ReaderOptionsPECOFF class encapsulates options needed
+/// to process mach-o files. You can create an ReaderOptionsPECOFF
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class ReaderOptionsPECOFF : public ReaderOptions {
+public:
+ virtual ~ReaderOptionsPECOFF();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ ReaderOptionsPECOFF(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ ReaderOptionsPECOFF();
+
+
+protected:
+};
+
+
+
+
+///
+/// The only way to instantiate a ReaderPECOFF object
+/// is via this createReaderPECOFF function. The is no public
+/// ReaderPECOFF class that you might be tempted to subclass.
+/// Support for all variants must be represented in the ReaderOptionsPECOFF
+/// object.
+/// The Reader object created retains a reference to the
+/// ReaderOptionsPECOFF object supplied, so the objects object must not be
+/// destroyed before the Reader object.
+///
+Reader* createReaderPECOFF(const ReaderOptionsPECOFF &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_READER_PECOFF_H_
diff --git a/lld/include/lld/ReaderWriter/ReaderYAML.h b/lld/include/lld/ReaderWriter/ReaderYAML.h
new file mode 100644
index 00000000000..c49711f5b7b
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/ReaderYAML.h
@@ -0,0 +1,73 @@
+//===- ReaderWriter/ReaderYAML.h - YAML File Format Reading Interface -----===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_READER_YAML_H_
+#define LLD_READERWRITER_READER_YAML_H_
+
+#include "lld/ReaderWriter/Reader.h"
+#include "lld/Core/LLVM.h"
+#include "lld/Core/Reference.h"
+#include "llvm/ADT/StringRef.h"
+
+
+namespace lld {
+
+///
+/// The ReaderOptionsYAML class encapsulates options needed
+/// to process mach-o files. You can create an ReaderOptionsYAML
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class ReaderOptionsYAML : public ReaderOptions {
+public:
+ virtual ~ReaderOptionsYAML();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ ReaderOptionsYAML(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ ReaderOptionsYAML();
+
+
+ /// Converts a reference kind string to a in-memory numeric value.
+ /// Used when parsing YAML encoded object files.
+ virtual Reference::Kind kindFromString(StringRef) const = 0;
+
+
+protected:
+};
+
+
+
+
+///
+/// The only way to instantiate a ReaderYAML object
+/// is via this createReaderYAML function. The is no public
+/// ReaderYAML class that you might be tempted to subclass.
+/// Support for all variants must be represented in the ReaderOptionsYAML
+/// object.
+/// The Reader object created retains a reference to the
+/// ReaderOptionsYAML object supplied, so the objects object must not be
+/// destroyed before the Reader object.
+///
+Reader* createReaderYAML(const ReaderOptionsYAML &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_READER_YAML_H_
+
+
diff --git a/lld/include/lld/ReaderWriter/Writer.h b/lld/include/lld/ReaderWriter/Writer.h
new file mode 100644
index 00000000000..7165fb6abde
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/Writer.h
@@ -0,0 +1,86 @@
+//===- ReaderWriter/Writer.h - Abstract File Format Interface -------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_WRITER_H_
+#define LLD_READERWRITER_WRITER_H_
+
+#include "lld/Core/LLVM.h"
+#include <memory>
+#include <vector>
+
+namespace lld {
+class File;
+class InputFiles;
+class StubsPass;
+class GOTPass;
+
+
+///
+/// The Writer is an abstract class for writing object files,
+/// shared library files, and executable files. Each file format
+/// (e.g. ELF, mach-o, PECOFF, native, etc) have a concrete subclass
+/// of Writer.
+///
+class Writer {
+public:
+ virtual ~Writer();
+
+ /// Write a file from the supplied File object
+ virtual error_code writeFile(const lld::File &linkedFile, StringRef path) = 0;
+
+ /// Return a Pass object for creating stubs/PLT entries
+ virtual StubsPass *stubPass() {
+ return nullptr;
+ }
+
+ /// Return a Pass object for creating GOT entries
+ virtual GOTPass *gotPass() {
+ return nullptr;
+ }
+
+ /// This method is called by Core Linking to give the Writer a chance to
+ /// add file format specific "files" to set of files to be linked.
+ /// This is how file format specific atoms can be added to the link.
+ virtual void addFiles(InputFiles&) {
+ }
+
+
+protected:
+ // only concrete subclasses can be instantiated
+ Writer();
+};
+
+
+
+///
+/// The WriterOptions encapsulates the options used by Writers.
+/// Each file format defines a subclass of WriterOptions
+/// to hold file format specific options. The option objects are the only
+/// way to control the behaviour of Writers.
+///
+class WriterOptions {
+public:
+ // Any options common to all file formats will go here.
+
+protected:
+ // only concrete subclasses can be instantiated
+ WriterOptions();
+};
+
+
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_WRITER_H_
+
+
+
+
diff --git a/lld/include/lld/ReaderWriter/WriterELF.h b/lld/include/lld/ReaderWriter/WriterELF.h
new file mode 100644
index 00000000000..6a182de4912
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/WriterELF.h
@@ -0,0 +1,64 @@
+//===- ReaderWriter/WriterELF.h - ELF File Format Writing Interface -------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_WRITER_ELF_H_
+#define LLD_READERWRITER_WRITER_ELF_H_
+
+#include "lld/ReaderWriter/Writer.h"
+#include "lld/Core/LLVM.h"
+#include "llvm/ADT/StringRef.h"
+
+
+namespace lld {
+
+///
+/// The WriterOptionsELF class encapsulates options needed
+/// to process mach-o files. You can create an WriterOptionsELF
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class WriterOptionsELF : public WriterOptions {
+public:
+ virtual ~WriterOptionsELF();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ WriterOptionsELF(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ WriterOptionsELF();
+
+protected:
+};
+
+
+
+
+///
+/// The only way to instantiate a WriterELF object
+/// is via this createWriterELF function. The is no public
+/// WriterELF class that you might be tempted to subclass.
+/// Support for all variants must be represented in the WriterOptionsELF
+/// object.
+/// The Writer object created retains a reference to the
+/// WriterOptionsELF object supplied, so it must not be destroyed
+/// before the Writer object.
+///
+Writer* createWriterELF(const WriterOptionsELF &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_WRITER_ELF_H_
diff --git a/lld/include/lld/ReaderWriter/WriterMachO.h b/lld/include/lld/ReaderWriter/WriterMachO.h
new file mode 100644
index 00000000000..b1a84137c5a
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/WriterMachO.h
@@ -0,0 +1,109 @@
+//===- ReaderWriter/WriterMachO.h - MachO File Format Reading Interface ---===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_WRITER_MACHO_H_
+#define LLD_READERWRITER_WRITER_MACHO_H_
+
+#include "lld/ReaderWriter/Writer.h"
+#include "lld/Core/LLVM.h"
+#include "llvm/ADT/StringRef.h"
+
+
+namespace lld {
+
+///
+/// The WriterOptionsMachO class encapsulates options needed
+/// to process mach-o files. You can create an WriterOptionsMachO
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class WriterOptionsMachO : public WriterOptions {
+public:
+ virtual ~WriterOptionsMachO();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ WriterOptionsMachO(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ WriterOptionsMachO();
+
+
+
+ enum OutputKind {
+ outputDynamicExecutable,
+ outputDylib,
+ outputBundle,
+ outputObjectFile
+ };
+
+ enum Architecture {
+ arch_x86_64,
+ arch_x86,
+ arch_arm,
+ };
+
+ OutputKind outputKind() const { return _outputkind; }
+ Architecture architecture() const { return _architecture; }
+ StringRef archName() const { return _archName; }
+ uint64_t pageZeroSize() const { return _pageZeroSize; }
+ uint32_t cpuType() const { return _cpuType; }
+ uint32_t cpuSubtype() const { return _cpuSubtype; }
+ bool noTextRelocations() const { return _noTextRelocations; }
+
+protected:
+ OutputKind _outputkind;
+ StringRef _archName;
+ Architecture _architecture;
+ uint64_t _pageZeroSize;
+ uint32_t _cpuType;
+ uint32_t _cpuSubtype;
+ bool _noTextRelocations;
+};
+
+
+
+
+///
+/// The only way to instantiate a WriterMachO object
+/// is via this createWriterMachO function. The is no public
+/// WriterMachO class that you might be tempted to subclass.
+/// Support for all variants must be represented in the
+/// WriterOptionsMachO object.
+/// The Writer object created retains a reference to the
+/// WriterOptionsMachO object supplied, so it must not be destroyed
+/// before the Writer object.
+///
+Writer* createWriterMachO(const WriterOptionsMachO &options);
+
+
+///
+/// Returns an options object that can be used with the
+/// WriterYAML to write mach-o object files as YAML.
+///
+const class WriterOptionsYAML& writerOptionsMachOAsYAML();
+
+
+///
+/// Returns an options object that can be used with the
+/// ReaderYAML to reader YAML encoded mach-o files.
+///
+const class ReaderOptionsYAML& readerOptionsMachOAsYAML();
+
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_WRITER_MACHO_H_
diff --git a/lld/include/lld/ReaderWriter/WriterNative.h b/lld/include/lld/ReaderWriter/WriterNative.h
new file mode 100644
index 00000000000..fdc99cf28a5
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/WriterNative.h
@@ -0,0 +1,63 @@
+//===- ReaderWriter/WriterNative.h - Native File Format Reading Interface ---===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_WRITER_NATIVE_H_
+#define LLD_READERWRITER_WRITER_NATIVE_H_
+
+#include "lld/ReaderWriter/Writer.h"
+#include "lld/Core/LLVM.h"
+
+
+namespace lld {
+
+///
+/// The WriterOptionsNative class encapsulates options needed
+/// to process mach-o files. You can create an WriterOptionsNative
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class WriterOptionsNative : public WriterOptions {
+public:
+ virtual ~WriterOptionsNative();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ WriterOptionsNative(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ WriterOptionsNative();
+
+protected:
+};
+
+
+
+
+///
+/// The only way to instantiate a WriterNative object
+/// is via this createWriterNative function. The is no public
+/// WriterNative class that you might be tempted to subclass.
+/// Support for all variants must be represented in the WriterOptionsNative
+/// object.
+/// The Writer object created retains a reference to the
+/// WriterOptionsNative object supplied, so it must not be destroyed
+/// before the Writer object.
+///
+Writer* createWriterNative(const WriterOptionsNative &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_WRITER_NATIVE_H_
diff --git a/lld/include/lld/ReaderWriter/WriterPECOFF.h b/lld/include/lld/ReaderWriter/WriterPECOFF.h
new file mode 100644
index 00000000000..740190729e0
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/WriterPECOFF.h
@@ -0,0 +1,63 @@
+//===- ReaderWriter/WriterPECOFF.h - PECOFF File Format Writing Interface -===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_WRITER_PECOFF_H_
+#define LLD_READERWRITER_WRITER_PECOFF_H_
+
+#include "lld/ReaderWriter/Writer.h"
+#include "lld/Core/LLVM.h"
+#include "llvm/ADT/StringRef.h"
+
+
+namespace lld {
+
+///
+/// The WriterOptionsPECOFF class encapsulates options needed
+/// to process mach-o files. You can create an WriterOptionsPECOFF
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class WriterOptionsPECOFF : public WriterOptions {
+public:
+ virtual ~WriterOptionsPECOFF();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ WriterOptionsPECOFF(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ WriterOptionsPECOFF();
+
+protected:
+};
+
+
+
+///
+/// The only way to instantiate a WriterPECOFF object
+/// is via this createWriterPECOFF function. The is no public
+/// WriterPECOFF class that you might be tempted to subclass.
+/// Support for all variants must be represented in the WriterOptionsPECOFF
+/// object.
+/// The Writer object created retains a reference to the
+/// WriterOptionsPECOFF object supplied, so it must not be destroyed
+/// before the Writer object.
+///
+Writer* createWriterPECOFF(const WriterOptionsPECOFF &options);
+
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_WRITER_PECOFF_H_
diff --git a/lld/include/lld/ReaderWriter/WriterYAML.h b/lld/include/lld/ReaderWriter/WriterYAML.h
new file mode 100644
index 00000000000..26dfbb852c5
--- /dev/null
+++ b/lld/include/lld/ReaderWriter/WriterYAML.h
@@ -0,0 +1,82 @@
+//===- ReaderWriter/WriterYAML.h - YAML File Format Writing Interface -----===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READERWRITER_WRITER_YAML_H_
+#define LLD_READERWRITER_WRITER_YAML_H_
+
+#include "lld/ReaderWriter/Writer.h"
+
+#include "lld/Core/LLVM.h"
+#include "lld/Core/Reference.h"
+#include "lld/Core/Pass.h"
+
+#include "llvm/ADT/StringRef.h"
+
+
+namespace lld {
+
+///
+/// The WriterOptionsYAML class encapsulates options needed
+/// to process mach-o files. You can create an WriterOptionsYAML
+/// instance from command line arguments or by subclassing and setting the
+/// instance variables in the subclass's constructor.
+///
+class WriterOptionsYAML : public WriterOptions {
+public:
+ virtual ~WriterOptionsYAML();
+
+ ///
+ /// Creates a Options object from darwin linker command line arguments.
+ /// FIXME: to be replaced with new option processing mechanism.
+ ///
+ WriterOptionsYAML(int argc, const char* argv[]);
+
+ ///
+ /// Creates a Options object with default settings. For use when
+ /// programmatically constructing options.
+ ///
+ WriterOptionsYAML();
+
+
+ /// Converts an in-memory reference kind value to a string.
+ /// Used when writing YAML encoded object files.
+ virtual StringRef kindToString(Reference::Kind) const = 0;
+
+
+ /// Enable Stubs pass to be run
+ virtual StubsPass *stubPass() const {
+ return nullptr;
+ }
+
+ /// Enable GOT pass to be run
+ virtual GOTPass *gotPass() const {
+ return nullptr;
+ }
+
+};
+
+
+
+
+///
+/// The only way to instantiate a WriterYAML object
+/// is via this createWriterYAML function. The is no public
+/// WriterYAML class that you might be tempted to subclass.
+/// Support for all variants must be represented in the WriterOptionsYAML
+/// object.
+/// The Writer object created retains a reference to the
+/// WriterOptionsYAML object supplied, so it must not be destroyed
+/// before the Writer object.
+///
+Writer* createWriterYAML(const WriterOptionsYAML &options);
+
+
+} // namespace lld
+
+#endif // LLD_READERWRITER_WRITER_YAML_H_
OpenPOWER on IntegriCloud