Rui Ueyama 7bda84d25e ELF: Remove ELFT and LinkingContext template parameters from ELFReader.
Previously, ELFReader takes three template arguments: EFLT,
LinkingContextT and FileT. FileT is itself templated.
So it was a bit complicated. Maybe too much.

Most architectures don't actually need to be parameterized for ELFT.
For example, x86 is always ELF32LE and x86-64 is ELF64LE.
However, because ELFReader requires a ELFT argument, we needed
to parameterize a class even if not needed.

This patch removes the parameter from the class. So now we can
de-templatize such classes (I didn't do that in this patch, though).

This patch also removes ContextT parameter since it didn't have to be
passed as a template argument.

llvm-svn: 234853
2015-04-14 04:53:57 +00:00

49 lines
1.5 KiB
C++

//===- lib/ReaderWriter/ELF/FileCommon.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_FILE_COMMON_H
#define LLD_READER_WRITER_ELF_FILE_COMMON_H
#include "lld/ReaderWriter/ELFLinkingContext.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ELF.h"
namespace lld {
namespace elf {
template <class ELFT>
std::error_code checkCompatibility(unsigned char size, unsigned char endian);
template <typename ELFT>
std::error_code isCompatible(const MemoryBuffer &mb, ELFLinkingContext &ctx) {
typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
if (uintptr_t(mb.getBufferStart()) & 1)
return make_dynamic_error_code("invalid alignment");
auto *hdr = reinterpret_cast<const Elf_Ehdr *>(mb.getBuffer().data());
if (hdr->e_machine != ctx.getMachineType())
return make_dynamic_error_code("incompatible machine type");
unsigned char size;
unsigned char endian;
std::tie(size, endian) = llvm::object::getElfArchType(mb.getBuffer());
if (std::error_code ec = checkCompatibility<ELFT>(size, endian))
return ec;
if (auto ec = ctx.mergeHeaderFlags(hdr->getFileClass(), hdr->e_flags))
return ec;
return std::error_code();
}
} // end namespace elf
} // end namespace lld
#endif