diff options
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h | 37 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/ELFFile.h | 36 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h | 37 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h | 50 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/X86/X86ELFFile.h | 37 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h | 37 |
6 files changed, 52 insertions, 182 deletions
diff --git a/lld/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h b/lld/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h index 62496800257..09da41d99e8 100644 --- a/lld/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/AArch64/AArch64ELFFile.h @@ -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); } }; diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h index c5526665723..b1fc8861943 100644 --- a/lld/lib/ReaderWriter/ELF/ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/ELFFile.h @@ -115,8 +115,14 @@ template <class ELFT> class ELFFile : public File { 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() { diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h index 6d93ed4a800..e892a206297 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonELFFile.h @@ -114,44 +114,15 @@ template <class ELFT> class HexagonELFFile : public ELFFile<ELFT> { 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); } diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h index dfd8501e183..6526b0307ad 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsELFFile.h @@ -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; diff --git a/lld/lib/ReaderWriter/ELF/X86/X86ELFFile.h b/lld/lib/ReaderWriter/ELF/X86/X86ELFFile.h index 9e2ecca43e7..516e9a204ad 100644 --- a/lld/lib/ReaderWriter/ELF/X86/X86ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/X86/X86ELFFile.h @@ -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); } }; diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h index e397b740fcf..24854e58046 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64ELFFile.h @@ -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); } }; |

