[Mips] Create ELF object reader for MIPS target.

llvm-svn: 203409
This commit is contained in:
Simon Atanasyan 2014-03-09 13:19:36 +00:00
parent 3af8664858
commit cfffe940a8
3 changed files with 119 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}