1 //===- ELFObjectFile.cpp - ELF object file implementation -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Part of the ELFObjectFile class implementation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Object/ELF.h"
18 using namespace object;
20 // Creates an in-memory object-file by default: createELFObjectFile(Buffer)
21 ObjectFile *ObjectFile::createELFObjectFile(MemoryBuffer *Object) {
22 std::pair<unsigned char, unsigned char> Ident = getElfArchType(Object);
25 if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB)
26 return new ELFObjectFile<support::little, false>(Object, ec);
27 else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB)
28 return new ELFObjectFile<support::big, false>(Object, ec);
29 else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB)
30 return new ELFObjectFile<support::big, true>(Object, ec);
31 else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) {
32 ELFObjectFile<support::little, true> *result =
33 new ELFObjectFile<support::little, true>(Object, ec);
37 report_fatal_error("Buffer is not an ELF object file!");
40 } // end namespace llvm