blob: 663b84ec8b1f2d160b1e7074860a4305abfbd118 [file] [log] [blame]
Michael J. Spencerb84551a2011-01-20 06:38:47 +00001//===- 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//
Eli Benderskyf4eff4b2012-02-12 06:12:10 +000010// Part of the ELFObjectFile class implementation.
Michael J. Spencerb84551a2011-01-20 06:38:47 +000011//
12//===----------------------------------------------------------------------===//
13
Eli Benderskyf4eff4b2012-02-12 06:12:10 +000014#include "llvm/Object/ELF.h"
Eli Bendersky24973c12012-01-22 09:01:03 +000015
Michael J. Spencerb84551a2011-01-20 06:38:47 +000016namespace llvm {
17
Eli Benderskyf4eff4b2012-02-12 06:12:10 +000018using namespace object;
Eli Bendersky24973c12012-01-22 09:01:03 +000019
Eli Benderskyf4eff4b2012-02-12 06:12:10 +000020// Creates an in-memory object-file by default: createELFObjectFile(Buffer)
21ObjectFile *ObjectFile::createELFObjectFile(MemoryBuffer *Object) {
22 std::pair<unsigned char, unsigned char> Ident = getElfArchType(Object);
23 error_code ec;
24
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);
34 return result;
35 }
36
37 report_fatal_error("Buffer is not an ELF object file!");
38}
Michael J. Spencerb84551a2011-01-20 06:38:47 +000039
40} // end namespace llvm