[lld] r203409 - [Mips] Create ELF object reader for MIPS target.
Simon Atanasyan
simon at atanasyan.com
Sun Mar 9 06:19:36 PDT 2014
Author: atanasyan
Date: Sun Mar 9 08:19:36 2014
New Revision: 203409
URL: http://llvm.org/viewvc/llvm-project?rev=203409&view=rev
Log:
[Mips] Create ELF object reader for MIPS target.
Added:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
Added: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=203409&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Sun Mar 9 08:19:36 2014
@@ -0,0 +1,64 @@
+//===- lib/ReaderWriter/ELF/MipsELFFile.h ---------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_FILE_H
+#define LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_FILE_H
+
+#include "ELFReader.h"
+#include "MipsLinkingContext.h"
+
+namespace lld {
+namespace elf {
+
+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,
+ error_code &ec)
+ : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
+
+ static ErrorOr<std::unique_ptr<MipsELFFile>>
+ create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
+ 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(), 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()))
+ return ec;
+
+ return std::move(file);
+ }
+};
+
+} // elf
+} // lld
+
+#endif
Added: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h?rev=203409&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h (added)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFReader.h Sun Mar 9 08:19:36 2014
@@ -0,0 +1,50 @@
+//===- lib/ReaderWriter/ELF/MipsELFReader.h -------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_READER_H
+#define LLD_READER_WRITER_ELF_MIPS_MIPS_ELF_READER_H
+
+#include "ELFReader.h"
+#include "MipsELFFile.h"
+
+namespace lld {
+namespace elf {
+
+struct MipsELFFileCreateTraits {
+ typedef llvm::ErrorOr<std::unique_ptr<lld::File>> result_type;
+
+ template <class ELFT>
+ static result_type create(std::unique_ptr<llvm::MemoryBuffer> mb,
+ bool atomizeStrings) {
+ return lld::elf::MipsELFFile<ELFT>::create(std::move(mb), atomizeStrings);
+ }
+};
+
+class MipsELFObjectReader : public ELFObjectReader {
+public:
+ MipsELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {}
+
+ virtual error_code
+ parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
+ std::vector<std::unique_ptr<File>> &result) const {
+ std::size_t maxAlignment =
+ 1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
+ auto f = createELF<MipsELFFileCreateTraits>(
+ llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
+ _atomizeStrings);
+ if (error_code ec = f.getError())
+ return ec;
+ result.push_back(std::move(*f));
+ return error_code::success();
+ }
+};
+
+} // namespace elf
+} // namespace lld
+
+#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h?rev=203409&r1=203408&r2=203409&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Sun Mar 9 08:19:36 2014
@@ -10,6 +10,7 @@
#define LLD_READER_WRITER_ELF_MIPS_MIPS_TARGET_HANDLER_H
#include "DefaultTargetHandler.h"
+#include "MipsELFReader.h"
#include "MipsLinkingContext.h"
#include "MipsRelocationHandler.h"
#include "MipsSectionChunks.h"
@@ -76,6 +77,10 @@ public:
return *_targetLayout;
}
+ std::unique_ptr<Reader> getObjReader(bool atomizeStrings) override {
+ return std::unique_ptr<Reader>(new MipsELFObjectReader(atomizeStrings));
+ }
+
const MipsTargetRelocationHandler &getRelocationHandler() const override {
return *_relocationHandler;
}
More information about the llvm-commits
mailing list