[lld] r224001 - [ELF] Remove duplicate constructor code.
Rui Ueyama
ruiu at google.com
Wed Dec 10 22:22:45 PST 2014
Author: ruiu
Date: Thu Dec 11 00:22:45 2014
New Revision: 224001
URL: http://llvm.org/viewvc/llvm-project?rev=224001&view=rev
Log:
[ELF] Remove duplicate constructor code.
This piece of code was copied multiple times to each archs.
Modified:
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFFile.h
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h?rev=224001&r1=224000&r2=224001&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h Thu Dec 11 00:22:45 2014
@@ -19,44 +19,15 @@ class AArch64LinkingContext;
template <class ELFT> class AArch64ELFFile : public ELFFile<ELFT> {
public:
- AArch64ELFFile(StringRef name, bool atomizeStrings)
- : ELFFile<ELFT>(name, atomizeStrings) {}
-
- AArch64ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
- std::error_code &ec)
- : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
+ AArch64ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings)
+ : ELFFile<ELFT>(std::move(mb), atomizeStrings) {}
static ErrorOr<std::unique_ptr<AArch64ELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- std::error_code ec;
std::unique_ptr<AArch64ELFFile<ELFT>> file(
- new AArch64ELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
-
- file->_objFile.reset(
- new llvm::object::ELFFile<ELFT>(mb.release()->getBuffer(), ec));
-
- if (ec)
- return ec;
-
- // Read input sections from the input file that need to be converted to
- // atoms
- if ((ec = file->createAtomizableSections()))
- return ec;
-
- // For mergeable strings, we would need to split the section into various
- // atoms
- if ((ec = file->createMergeableAtoms()))
- return ec;
-
- // Create the necessary symbols that are part of the section that we
- // created in createAtomizableSections function
- if ((ec = file->createSymbolsFromAtomizableSections()))
+ new AArch64ELFFile<ELFT>(std::move(mb), atomizeStrings));
+ if (std::error_code ec = file->parse())
return ec;
-
- // Create the appropriate atoms from the file
- if ((ec = file->createAtoms()))
- return ec;
-
return std::move(file);
}
};
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=224001&r1=224000&r2=224001&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Thu Dec 11 00:22:45 2014
@@ -115,8 +115,14 @@ template <class ELFT> class ELFFile : pu
typedef typename MergedSectionMapT::iterator MergedSectionMapIterT;
public:
- ELFFile(StringRef name, bool atomizeStrings = false)
- : File(name, kindObject), _ordinal(0), _doStringsMerge(atomizeStrings) {}
+ ELFFile(StringRef name)
+ : File(name, kindObject), _ordinal(0), _doStringsMerge(false) {}
+
+ ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings = false)
+ : File(mb->getBufferIdentifier(), kindObject), _mb(std::move(mb)),
+ _ordinal(0), _doStringsMerge(atomizeStrings) {}
+
+ virtual std::error_code parse();
static ErrorOr<std::unique_ptr<ELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings);
@@ -354,6 +360,7 @@ protected:
/// \brief Sections that have merge string property
std::vector<const Elf_Shdr *> _mergeStringSections;
+ std::unique_ptr<MemoryBuffer> _mb;
int64_t _ordinal;
/// \brief the cached options relevant while reading the ELF File
@@ -412,34 +419,39 @@ ErrorOr<std::unique_ptr<ELFFile<ELFT>>>
ELFFile<ELFT>::create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
std::error_code ec;
std::unique_ptr<ELFFile<ELFT>> file(
- new ELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
-
- file->_objFile.reset(
- new llvm::object::ELFFile<ELFT>(mb.release()->getBuffer(), ec));
+ new ELFFile<ELFT>(std::move(mb), atomizeStrings));
+ if (std::error_code ec = file->parse())
+ return ec;
+ return std::move(file);
+}
+template <class ELFT>
+std::error_code ELFFile<ELFT>::parse() {
+ std::error_code ec;
+ _objFile.reset(
+ new llvm::object::ELFFile<ELFT>(_mb.release()->getBuffer(), ec));
if (ec)
return ec;
// Read input sections from the input file that need to be converted to
// atoms
- if ((ec = file->createAtomizableSections()))
+ if ((ec = createAtomizableSections()))
return ec;
// For mergeable strings, we would need to split the section into various
// atoms
- if ((ec = file->createMergeableAtoms()))
+ if ((ec = createMergeableAtoms()))
return ec;
// Create the necessary symbols that are part of the section that we
// created in createAtomizableSections function
- if ((ec = file->createSymbolsFromAtomizableSections()))
+ if ((ec = createSymbolsFromAtomizableSections()))
return ec;
// Create the appropriate atoms from the file
- if ((ec = file->createAtoms()))
+ if ((ec = createAtoms()))
return ec;
-
- return std::move(file);
+ return std::error_code();
}
template <class ELFT> Reference::KindArch ELFFile<ELFT>::kindArch() {
Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h?rev=224001&r1=224000&r2=224001&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h Thu Dec 11 00:22:45 2014
@@ -114,44 +114,15 @@ template <class ELFT> class HexagonELFFi
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
public:
- HexagonELFFile(StringRef name, bool atomizeStrings)
- : ELFFile<ELFT>(name, atomizeStrings) {}
-
- HexagonELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
- std::error_code &ec)
- : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
+ HexagonELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings)
+ : ELFFile<ELFT>(std::move(mb), atomizeStrings) {}
static ErrorOr<std::unique_ptr<HexagonELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- std::error_code ec;
std::unique_ptr<HexagonELFFile<ELFT>> file(
- new HexagonELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
-
- file->_objFile.reset(
- new llvm::object::ELFFile<ELFT>(mb.release()->getBuffer(), ec));
-
- if (ec)
- return ec;
-
- // Read input sections from the input file that need to be converted to
- // atoms
- if ((ec = file->createAtomizableSections()))
- return ec;
-
- // For mergeable strings, we would need to split the section into various
- // atoms
- if ((ec = file->createMergeableAtoms()))
- return ec;
-
- // Create the necessary symbols that are part of the section that we
- // created in createAtomizableSections function
- if ((ec = file->createSymbolsFromAtomizableSections()))
+ new HexagonELFFile<ELFT>(std::move(mb), atomizeStrings));
+ if (std::error_code ec = file->parse())
return ec;
-
- // Create the appropriate atoms from the file
- if ((ec = file->createAtoms()))
- return ec;
-
return std::move(file);
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=224001&r1=224000&r2=224001&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Thu Dec 11 00:22:45 2014
@@ -80,49 +80,15 @@ public:
template <class ELFT> class MipsELFFile : public ELFFile<ELFT> {
public:
- MipsELFFile(StringRef name, bool atomizeStrings)
- : ELFFile<ELFT>(name, atomizeStrings) {}
-
- MipsELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
- std::error_code &ec)
- : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
+ MipsELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings)
+ : ELFFile<ELFT>(std::move(mb), atomizeStrings) {}
static ErrorOr<std::unique_ptr<MipsELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- std::error_code ec;
std::unique_ptr<MipsELFFile<ELFT>> file(
- new MipsELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
-
- file->_objFile.reset(
- new llvm::object::ELFFile<ELFT>(mb.release()->getBuffer(), ec));
-
- if (ec)
- return ec;
-
- // Read input sections from the input file that need to be converted to
- // atoms
- if ((ec = file->createAtomizableSections()))
- return ec;
-
- // For mergeable strings, we would need to split the section into various
- // atoms
- if ((ec = file->createMergeableAtoms()))
- return ec;
-
- // Create the necessary symbols that are part of the section that we
- // created in createAtomizableSections function
- if ((ec = file->createSymbolsFromAtomizableSections()))
- return ec;
-
- // Create the appropriate atoms from the file
- if ((ec = file->createAtoms()))
+ new MipsELFFile<ELFT>(std::move(mb), atomizeStrings));
+ if (std::error_code ec = file->parse())
return ec;
-
- // Retrieve some auxiliary data like GP value, TLS section address etc
- // from the object file.
- if ((ec = file->readAuxData()))
- return ec;
-
return std::move(file);
}
@@ -137,6 +103,14 @@ public:
uint64_t getTPOffset() const { return *_tpOff; }
uint64_t getDTPOffset() const { return *_dtpOff; }
+ std::error_code parse() override {
+ if (std::error_code ec = ELFFile<ELFT>::parse())
+ return ec;
+ // Retrieve some auxiliary data like GP value, TLS section address etc
+ // from the object file.
+ return readAuxData();
+ }
+
private:
typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
Modified: lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFFile.h?rev=224001&r1=224000&r2=224001&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86/X86ELFFile.h Thu Dec 11 00:22:45 2014
@@ -19,44 +19,15 @@ class X86LinkingContext;
template <class ELFT> class X86ELFFile : public ELFFile<ELFT> {
public:
- X86ELFFile(StringRef name, bool atomizeStrings)
- : ELFFile<ELFT>(name, atomizeStrings) {}
-
- X86ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
- std::error_code &ec)
- : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
+ X86ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings)
+ : ELFFile<ELFT>(std::move(mb), atomizeStrings) {}
static ErrorOr<std::unique_ptr<X86ELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- std::error_code ec;
std::unique_ptr<X86ELFFile<ELFT>> file(
- new X86ELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
-
- file->_objFile.reset(
- new llvm::object::ELFFile<ELFT>(mb.release()->getBuffer(), ec));
-
- if (ec)
- return ec;
-
- // Read input sections from the input file that need to be converted to
- // atoms
- if ((ec = file->createAtomizableSections()))
- return ec;
-
- // For mergeable strings, we would need to split the section into various
- // atoms
- if ((ec = file->createMergeableAtoms()))
- return ec;
-
- // Create the necessary symbols that are part of the section that we
- // created in createAtomizableSections function
- if ((ec = file->createSymbolsFromAtomizableSections()))
+ new X86ELFFile<ELFT>(std::move(mb), atomizeStrings));
+ if (std::error_code ec = file->parse())
return ec;
-
- // Create the appropriate atoms from the file
- if ((ec = file->createAtoms()))
- return ec;
-
return std::move(file);
}
};
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h?rev=224001&r1=224000&r2=224001&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h Thu Dec 11 00:22:45 2014
@@ -19,44 +19,15 @@ class X86_64LinkingContext;
template <class ELFT> class X86_64ELFFile : public ELFFile<ELFT> {
public:
- X86_64ELFFile(StringRef name, bool atomizeStrings)
- : ELFFile<ELFT>(name, atomizeStrings) {}
-
- X86_64ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
- std::error_code &ec)
- : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
+ X86_64ELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings)
+ : ELFFile<ELFT>(std::move(mb), atomizeStrings) {}
static ErrorOr<std::unique_ptr<X86_64ELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- std::error_code ec;
std::unique_ptr<X86_64ELFFile<ELFT>> file(
- new X86_64ELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
-
- file->_objFile.reset(
- new llvm::object::ELFFile<ELFT>(mb.release()->getBuffer(), ec));
-
- if (ec)
- return ec;
-
- // Read input sections from the input file that need to be converted to
- // atoms
- if ((ec = file->createAtomizableSections()))
- return ec;
-
- // For mergeable strings, we would need to split the section into various
- // atoms
- if ((ec = file->createMergeableAtoms()))
- return ec;
-
- // Create the necessary symbols that are part of the section that we
- // created in createAtomizableSections function
- if ((ec = file->createSymbolsFromAtomizableSections()))
+ new X86_64ELFFile<ELFT>(std::move(mb), atomizeStrings));
+ if (std::error_code ec = file->parse())
return ec;
-
- // Create the appropriate atoms from the file
- if ((ec = file->createAtoms()))
- return ec;
-
return std::move(file);
}
};
More information about the llvm-commits
mailing list