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