[lld] r234540 - ELF: Move CreateELF() from its own file to ELFReader.h.
Rui Ueyama
ruiu at google.com
Thu Apr 9 14:55:47 PDT 2015
Author: ruiu
Date: Thu Apr 9 16:55:47 2015
New Revision: 234540
URL: http://llvm.org/viewvc/llvm-project?rev=234540&view=rev
Log:
ELF: Move CreateELF() from its own file to ELFReader.h.
CreateELF.h was included only by ELFReader.h, and it was used only
by ELFReader class. By making the function a member of the class,
we can remove template parameters.
Removed:
lld/trunk/lib/ReaderWriter/ELF/CreateELF.h
Modified:
lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
Removed: lld/trunk/lib/ReaderWriter/ELF/CreateELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/CreateELF.h?rev=234539&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/CreateELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/CreateELF.h (removed)
@@ -1,65 +0,0 @@
-//===- lib/ReaderWriter/ELF/CreateELF.h -----------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file provides a simple way to create an object templated on
-/// ELFType depending on the runtime type needed.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_READER_WRITER_ELF_CREATE_ELF_H
-#define LLD_READER_WRITER_ELF_CREATE_ELF_H
-
-#include "lld/Core/File.h"
-#include "llvm/Object/ELF.h"
-#include "llvm/ADT/STLExtras.h"
-
-namespace {
-
-/// \func createELF
-/// \brief Create an object depending on the runtime attributes and alignment
-/// of an ELF file.
-///
-/// \param Traits
-/// Traits::create must be a template function which takes an ELFType and
-/// returns an ErrorOr<std::unique_ptr<lld::File>>.
-///
-/// \param ident pair of EI_CLASS and EI_DATA.
-/// \param maxAlignment the maximum alignment of the file.
-/// \param args arguments forwarded to CreateELFTraits<T>::create.
-template <template <typename ELFT> class FileT, class... Args>
-llvm::ErrorOr<std::unique_ptr<lld::File>>
-createELF(std::pair<unsigned char, unsigned char> ident,
- std::size_t maxAlignment, Args &&... args) {
- using namespace llvm::ELF;
- using namespace llvm::support;
- using llvm::object::ELFType;
- if (maxAlignment < 2)
- llvm_unreachable("Invalid alignment for ELF file!");
-
- lld::File *file = nullptr;
- unsigned char size = ident.first;
- unsigned char endian = ident.second;
- if (size == ELFCLASS32 && endian == ELFDATA2LSB) {
- file = new FileT<ELFType<little, 2, false>>(std::forward<Args>(args)...);
- } else if (size == ELFCLASS32 && endian == ELFDATA2MSB) {
- file = new FileT<ELFType<big, 2, false>>(std::forward<Args>(args)...);
- } else if (size == ELFCLASS64 && endian == ELFDATA2LSB) {
- file = new FileT<ELFType<little, 2, true>>(std::forward<Args>(args)...);
- } else if (size == ELFCLASS64 && endian == ELFDATA2MSB) {
- file = new FileT<ELFType<big, 2, true>>(std::forward<Args>(args)...);
- }
- if (!file)
- llvm_unreachable("Invalid ELF type!");
- return std::unique_ptr<lld::File>(file);
-}
-
-} // end anon namespace
-
-#endif
Modified: lld/trunk/lib/ReaderWriter/ELF/ELFReader.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFReader.h?rev=234540&r1=234539&r2=234540&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFReader.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFReader.h Thu Apr 9 16:55:47 2015
@@ -10,10 +10,12 @@
#ifndef LLD_READER_WRITER_ELF_READER_H
#define LLD_READER_WRITER_ELF_READER_H
-#include "CreateELF.h"
#include "DynamicFile.h"
#include "ELFFile.h"
+#include "lld/Core/File.h"
#include "lld/Core/Reader.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Object/ELF.h"
namespace lld {
namespace elf {
@@ -36,18 +38,42 @@ public:
const Elf_Ehdr *hdr = elfHeader(*mb);
if (auto ec = _ctx.mergeHeaderFlags(hdr->getFileClass(), hdr->e_flags))
return ec;
-
std::size_t maxAlignment =
1ULL << llvm::countTrailingZeros(uintptr_t(mb->getBufferStart()));
- auto f = createELF<FileT>(llvm::object::getElfArchType(mb->getBuffer()),
- maxAlignment, std::move(mb), _ctx);
- if (std::error_code ec = f.getError())
- return ec;
- result.push_back(std::move(*f));
+ result.push_back(createELF(llvm::object::getElfArchType(mb->getBuffer()),
+ maxAlignment, std::move(mb)));
return std::error_code();
}
private:
+ /// Create an object depending on the runtime attributes and alignment
+ /// of an ELF file.
+ std::unique_ptr<File> createELF(std::pair<unsigned char, unsigned char> ident,
+ std::size_t maxAlignment,
+ std::unique_ptr<MemoryBuffer> mb) const {
+ using namespace llvm::ELF;
+ using namespace llvm::support;
+ using llvm::object::ELFType;
+ if (maxAlignment < 2)
+ llvm_unreachable("Invalid alignment for ELF file!");
+
+ File *file = nullptr;
+ unsigned char size = ident.first;
+ unsigned char endian = ident.second;
+ if (size == ELFCLASS32 && endian == ELFDATA2LSB) {
+ file = new FileT<ELFType<little, 2, false>>(std::move(mb), _ctx);
+ } else if (size == ELFCLASS32 && endian == ELFDATA2MSB) {
+ file = new FileT<ELFType<big, 2, false>>(std::move(mb), _ctx);
+ } else if (size == ELFCLASS64 && endian == ELFDATA2LSB) {
+ file = new FileT<ELFType<little, 2, true>>(std::move(mb), _ctx);
+ } else if (size == ELFCLASS64 && endian == ELFDATA2MSB) {
+ file = new FileT<ELFType<big, 2, true>>(std::move(mb), _ctx);
+ }
+ if (!file)
+ llvm_unreachable("Invalid ELF type!");
+ return std::unique_ptr<File>(file);
+ }
+
static const Elf_Ehdr *elfHeader(const MemoryBuffer &buf) {
return reinterpret_cast<const Elf_Ehdr *>(buf.getBuffer().data());
}
More information about the llvm-commits
mailing list