Home | History | Annotate | Download | only in Object
      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 namespace llvm {
     17 
     18 using namespace object;
     19 
     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);
     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 }
     39 
     40 } // end namespace llvm
     41