[lld] r181280 - [ELF] Initialize readers and writers on creation.
Michael J. Spencer
bigcheesegs at gmail.com
Mon May 6 17:28:07 PDT 2013
Author: mspencer
Date: Mon May 6 19:28:07 2013
New Revision: 181280
URL: http://llvm.org/viewvc/llvm-project?rev=181280&view=rev
Log:
[ELF] Initialize readers and writers on creation.
This makes the target handler a constructor argument because the constructor of
OutputELFWriter relies on it being initialized.
Modified:
lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h
Modified: lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h?rev=181280&r1=181279&r2=181280&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h Mon May 6 19:28:07 2013
@@ -112,7 +112,7 @@ public:
private:
ELFTargetInfo() LLVM_DELETED_FUNCTION;
protected:
- ELFTargetInfo(llvm::Triple);
+ ELFTargetInfo(llvm::Triple, std::unique_ptr<TargetHandlerBase>);
virtual Writer &writer() const;
@@ -128,10 +128,10 @@ protected:
bool _useShlibUndefines;
std::vector<StringRef> _inputSearchPaths;
llvm::BumpPtrAllocator _extraStrings;
- mutable std::unique_ptr<Reader> _elfReader;
- mutable std::unique_ptr<Reader> _yamlReader;
- mutable std::unique_ptr<Writer> _writer;
- mutable std::unique_ptr<Reader> _linkerScriptReader;
+ std::unique_ptr<Reader> _elfReader;
+ std::unique_ptr<Reader> _yamlReader;
+ std::unique_ptr<Writer> _writer;
+ std::unique_ptr<Reader> _linkerScriptReader;
};
} // end namespace lld
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp?rev=181280&r1=181279&r2=181280&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFTargetInfo.cpp Mon May 6 19:28:07 2013
@@ -12,6 +12,7 @@
#include "TargetHandler.h"
#include "Targets.h"
+#include "lld/Core/Instrumentation.h"
#include "lld/Passes/LayoutPass.h"
#include "lld/ReaderWriter/ReaderLinkerScript.h"
@@ -21,17 +22,17 @@
#include "llvm/Support/Path.h"
namespace lld {
-ELFTargetInfo::ELFTargetInfo(llvm::Triple triple)
- : _outputFileType(elf::ET_EXEC)
- , _triple(triple)
- , _baseAddress(0)
- , _isStaticExecutable(false)
- , _outputYAML(false)
- , _noInhibitExec(false)
- , _mergeCommonStrings(false)
- , _runLayoutPass(true)
- , _useShlibUndefines(false) {
-}
+ELFTargetInfo::ELFTargetInfo(llvm::Triple triple, std::unique_ptr<TargetHandlerBase> targetHandler)
+ : _outputFileType(elf::ET_EXEC),
+ _triple(triple),
+ _targetHandler(std::move(targetHandler))
+ , _baseAddress(0)
+ , _isStaticExecutable(false)
+ , _outputYAML(false)
+ , _noInhibitExec(false)
+ , _mergeCommonStrings(false)
+ , _runLayoutPass(true)
+ , _useShlibUndefines(false) {}
bool ELFTargetInfo::is64Bits() const {
return getTriple().isArch64Bit();
@@ -74,11 +75,14 @@ bool ELFTargetInfo::validate(raw_ostream
return true;
}
+ _elfReader = createReaderELF(*this);
+ _yamlReader = createReaderYAML(*this);
+ _linkerScriptReader.reset(new ReaderLinkerScript(*this));
+ _writer = _outputYAML ? createWriterYAML(*this) : createWriterELF(*this);
return false;
}
-
bool ELFTargetInfo::isDynamic() const {
switch (_outputFileType) {
case llvm::ELF::ET_EXEC:
@@ -94,34 +98,20 @@ bool ELFTargetInfo::isDynamic() const {
error_code ELFTargetInfo::parseFile(std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File>> &result) const {
- if (!_elfReader)
- _elfReader = createReaderELF(*this);
error_code ec = _elfReader->parseFile(mb, result);
if (ec) {
// Not an ELF file, check file extension to see if it might be yaml
StringRef path = mb->getBufferIdentifier();
- if ( path.endswith(".objtxt") ) {
- if (!_yamlReader)
- _yamlReader = createReaderYAML(*this);
+ if (path.endswith(".objtxt"))
ec = _yamlReader->parseFile(mb, result);
- }
- if (ec) {
+ if (ec)
// Not a yaml file, assume it is a linkerscript
- if (!_linkerScriptReader)
- _linkerScriptReader.reset(new ReaderLinkerScript(*this));
ec = _linkerScriptReader->parseFile(mb, result);
- }
}
return ec;
}
Writer &ELFTargetInfo::writer() const {
- if (!_writer) {
- if (_outputYAML)
- _writer = createWriterYAML(*this);
- else
- _writer = createWriterELF(*this);
- }
return *_writer;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h?rev=181280&r1=181279&r2=181280&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetInfo.h Mon May 6 19:28:07 2013
@@ -23,10 +23,7 @@ namespace elf {
class HexagonTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
HexagonTargetInfo(llvm::Triple triple)
- : ELFTargetInfo(triple) {
- _targetHandler = std::unique_ptr<TargetHandlerBase>(
- new HexagonTargetHandler(*this));
- }
+ : ELFTargetInfo(triple, std::unique_ptr<TargetHandlerBase>(new HexagonTargetHandler(*this))) {}
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
Modified: lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h?rev=181280&r1=181279&r2=181280&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/PPC/PPCTargetInfo.h Mon May 6 19:28:07 2013
@@ -22,10 +22,7 @@ namespace elf {
class PPCTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
PPCTargetInfo(llvm::Triple triple)
- : ELFTargetInfo(triple) {
- _targetHandler = std::unique_ptr<TargetHandlerBase>(
- new PPCTargetHandler(*this));
- }
+ : ELFTargetInfo(triple, std::unique_ptr<TargetHandlerBase>(new PPCTargetHandler(*this))) {}
virtual bool isLittleEndian() const { return false; }
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h?rev=181280&r1=181279&r2=181280&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86TargetInfo.h Mon May 6 19:28:07 2013
@@ -22,10 +22,7 @@ namespace elf {
class X86TargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
X86TargetInfo(llvm::Triple triple)
- : ELFTargetInfo(triple) {
- _targetHandler = std::unique_ptr<TargetHandlerBase>(
- new X86TargetHandler(*this));
- }
+ : ELFTargetInfo(triple, std::unique_ptr<TargetHandlerBase>(new X86TargetHandler(*this))) {}
virtual ErrorOr<Reference::Kind> relocKindFromString(StringRef str) const;
virtual ErrorOr<std::string> stringFromRelocKind(Reference::Kind kind) const;
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h?rev=181280&r1=181279&r2=181280&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64TargetInfo.h Mon May 6 19:28:07 2013
@@ -29,10 +29,7 @@ enum {
class X86_64TargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
X86_64TargetInfo(llvm::Triple triple)
- : ELFTargetInfo(triple) {
- _targetHandler =
- std::unique_ptr<TargetHandlerBase>(new X86_64TargetHandler(*this));
- }
+ : ELFTargetInfo(triple, std::unique_ptr<TargetHandlerBase>(new X86_64TargetHandler(*this))) {}
virtual void addPasses(PassManager &) const;
More information about the llvm-commits
mailing list