Michael J. Spencer | b84551a | 2011-01-20 06:38:47 +0000 | [diff] [blame] | 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 | // |
Eli Bendersky | f4eff4b | 2012-02-12 06:12:10 +0000 | [diff] [blame] | 10 | // Part of the ELFObjectFile class implementation. |
Michael J. Spencer | b84551a | 2011-01-20 06:38:47 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Eli Bendersky | f4eff4b | 2012-02-12 06:12:10 +0000 | [diff] [blame] | 14 | #include "llvm/Object/ELF.h" |
Eli Bendersky | 24973c1 | 2012-01-22 09:01:03 +0000 | [diff] [blame] | 15 | |
Michael J. Spencer | b84551a | 2011-01-20 06:38:47 +0000 | [diff] [blame] | 16 | namespace llvm { |
| 17 | |
Eli Bendersky | f4eff4b | 2012-02-12 06:12:10 +0000 | [diff] [blame] | 18 | using namespace object; |
Eli Bendersky | 24973c1 | 2012-01-22 09:01:03 +0000 | [diff] [blame] | 19 | |
Eli Bendersky | f4eff4b | 2012-02-12 06:12:10 +0000 | [diff] [blame] | 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 | } |
Michael J. Spencer | b84551a | 2011-01-20 06:38:47 +0000 | [diff] [blame] | 39 | |
| 40 | } // end namespace llvm |