MachOObject.h revision 95369163f58f06a6494ca9623184a8849ecf85f3
1//===- MachOObject.h - Mach-O Object File Wrapper ---------------*- 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#ifndef LLVM_OBJECT_MACHOOBJECT_H 11#define LLVM_OBJECT_MACHOOBJECT_H 12 13#include <string> 14#include "llvm/ADT/OwningPtr.h" 15 16namespace llvm { 17 18class MemoryBuffer; 19 20namespace object { 21 22/// \brief Wrapper object for manipulating Mach-O object files. 23/// 24/// This class is designed to implement a full-featured, efficient, portable, 25/// and robust Mach-O interface to Mach-O object files. It does not attempt to 26/// smooth over rough edges in the Mach-O format or generalize access to object 27/// independent features. 28/// 29/// The class is designed around accessing the Mach-O object which is expected 30/// to be fully loaded into memory. 31/// 32/// This class is *not* suitable for concurrent use. For efficient operation, 33/// the class uses APIs which rely on the ability to cache the results of 34/// certain calls in internal objects which are not safe for concurrent 35/// access. This allows the API to be zero-copy on the common paths. 36// 37// FIXME: It would be cool if we supported a "paged" MemoryBuffer 38// implementation. This would allow us to implement a more sensible version of 39// MemoryObject which can work like a MemoryBuffer, but be more efficient for 40// objects which are in the current address space. 41class MachOObject { 42public: 43 44private: 45 OwningPtr<MemoryBuffer> Buffer; 46 47 /// Whether the object is little endian. 48 bool IsLittleEndian; 49 /// Whether the object is 64-bit. 50 bool Is64Bit; 51 52private: 53 MachOObject(MemoryBuffer *Buffer, bool IsLittleEndian, bool Is64Bit); 54 55public: 56 /// \brief Load a Mach-O object from a MemoryBuffer object. 57 /// 58 /// \param Buffer - The buffer to load the object from. This routine takes 59 /// exclusive ownership of the buffer (which is passed to the returned object 60 /// on success). 61 /// \param ErrorStr [out] - If given, will be set to a user readable error 62 /// message on failure. 63 /// \returns The loaded object, or null on error. 64 static MachOObject *LoadFromBuffer(MemoryBuffer *Buffer, 65 std::string *ErrorStr = 0); 66 67 /// @name Object Header Information 68 /// @{ 69 /// @} 70}; 71 72} // end namespace object 73} // end namespace llvm 74 75#endif 76