LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectFile.cpp
Go to the documentation of this file.
1 //===- ObjectFile.cpp - File format independent object file -----*- 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 // This file defines a file format independent ObjectFile class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Object/ObjectFile.h"
15 #include "llvm/ADT/OwningPtr.h"
20 
21 using namespace llvm;
22 using namespace object;
23 
24 void ObjectFile::anchor() { }
25 
26 ObjectFile::ObjectFile(unsigned int Type, MemoryBuffer *source)
27  : Binary(Type, source) {
28 }
29 
31  uint32_t &Result) const {
32  Result = 0;
33  return object_error::success;
34 }
35 
37  return section_iterator(SectionRef(Sec, this));
38 }
39 
41  if (Object->getBufferSize() < 64) {
42  delete Object;
43  return 0;
44  }
45 
47  switch (Type) {
53  delete Object;
54  return 0;
59  return createELFObjectFile(Object);
70  return createMachOObjectFile(Object);
74  return createCOFFObjectFile(Object);
75  }
76  llvm_unreachable("Unexpected Object File Type");
77 }
78 
81  if (MemoryBuffer::getFile(ObjectPath, File))
82  return NULL;
83  return createObjectFile(File.take());
84 }
static ObjectFile * createELFObjectFile(MemoryBuffer *Object)
friend class SectionRef
Definition: ObjectFile.h:302
StringRef getBuffer() const
Definition: MemoryBuffer.h:55
ELF Relocatable object file.
Definition: FileSystem.h:225
#define llvm_unreachable(msg)
static ObjectFile * createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
Definition: ObjectFile.cpp:79
ELF dynamically linked shared lib.
Definition: FileSystem.h:227
Windows compiled resource file (.rc)
Definition: FileSystem.h:243
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:133
ar style archive file
Definition: FileSystem.h:224
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Path.cpp:846
static error_code getFile(Twine Filename, OwningPtr< MemoryBuffer > &result, int64_t FileSize=-1, bool RequiresNullTerminator=true)
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const
Definition: ObjectFile.cpp:36
size_t getBufferSize() const
Definition: MemoryBuffer.h:53
virtual error_code getSymbolAlignment(DataRefImpl Symb, uint32_t &Res) const
Definition: ObjectFile.cpp:30
static ObjectFile * createCOFFObjectFile(MemoryBuffer *Object)
static ObjectFile * createMachOObjectFile(MemoryBuffer *Object)