LLVM  4.0.0
Classes | Functions
MachOObjectFile.cpp File Reference
#include "llvm/Object/MachO.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MachO.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <cctype>
#include <cstring>
#include <limits>
#include <list>
Include dependency graph for MachOObjectFile.cpp:

Go to the source code of this file.

Classes

struct  MachOElement
 

Functions

static Error malformedError (Twine Msg)
 
template<typename T >
static T getStruct (const MachOObjectFile &O, const char *P)
 
template<typename T >
static Expected< TgetStructOrErr (const MachOObjectFile &O, const char *P)
 
static const char * getSectionPtr (const MachOObjectFile &O, MachOObjectFile::LoadCommandInfo L, unsigned Sec)
 
static const char * getPtr (const MachOObjectFile &O, size_t Offset)
 
static MachO::nlist_base getSymbolTableEntryBase (const MachOObjectFile &O, DataRefImpl DRI)
 
static StringRef parseSegmentOrSectionName (const char *P)
 
template<class T >
static void advance (T &it, size_t Val)
 
static unsigned getCPUType (const MachOObjectFile &O)
 
static uint32_t getPlainRelocationAddress (const MachO::any_relocation_info &RE)
 
static unsigned getScatteredRelocationAddress (const MachO::any_relocation_info &RE)
 
static bool getPlainRelocationPCRel (const MachOObjectFile &O, const MachO::any_relocation_info &RE)
 
static bool getScatteredRelocationPCRel (const MachO::any_relocation_info &RE)
 
static unsigned getPlainRelocationLength (const MachOObjectFile &O, const MachO::any_relocation_info &RE)
 
static unsigned getScatteredRelocationLength (const MachO::any_relocation_info &RE)
 
static unsigned getPlainRelocationType (const MachOObjectFile &O, const MachO::any_relocation_info &RE)
 
static uint32_t getSectionFlags (const MachOObjectFile &O, DataRefImpl Sec)
 
static Expected
< MachOObjectFile::LoadCommandInfo
getLoadCommandInfo (const MachOObjectFile &Obj, const char *Ptr, uint32_t LoadCommandIndex)
 
static Expected
< MachOObjectFile::LoadCommandInfo
getFirstLoadCommandInfo (const MachOObjectFile &Obj)
 
static Expected
< MachOObjectFile::LoadCommandInfo
getNextLoadCommandInfo (const MachOObjectFile &Obj, uint32_t LoadCommandIndex, const MachOObjectFile::LoadCommandInfo &L)
 
template<typename T >
static void parseHeader (const MachOObjectFile &Obj, T &Header, Error &Err)
 
static Error checkOverlappingElement (std::list< MachOElement > &Elements, uint64_t Offset, uint64_t Size, const char *Name)
 
template<typename Segment , typename Section >
static Error parseSegmentLoadCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl< const char * > &Sections, bool &IsPageZeroSegment, uint32_t LoadCommandIndex, const char *CmdName, uint64_t SizeOfHeaders, std::list< MachOElement > &Elements)
 
static Error checkSymtabCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **SymtabLoadCmd, std::list< MachOElement > &Elements)
 
static Error checkDysymtabCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **DysymtabLoadCmd, std::list< MachOElement > &Elements)
 
static Error checkLinkeditDataCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName, std::list< MachOElement > &Elements, const char *ElementName)
 
static Error checkDyldInfoCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName, std::list< MachOElement > &Elements)
 
static Error checkDylibCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
 
static Error checkDylibIdCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd)
 
static Error checkDyldCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
 
static Error checkVersCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, const char *CmdName)
 
static Error checkRpathCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
 
static Error checkEncryptCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, uint64_t cryptoff, uint64_t cryptsize, const char **LoadCmd, const char *CmdName)
 
static Error checkLinkerOptCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex)
 
static Error checkSubCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName, size_t SizeOfCmd, const char *CmdStructName, uint32_t PathOffset, const char *PathFieldName)
 
static Error checkThreadCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char *CmdName)
 
static Error checkTwoLevelHintsCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, const char **LoadCmd, std::list< MachOElement > &Elements)
 
static bool isLoadCommandObsolete (uint32_t cmd)
 

Function Documentation

template<class T >
static void advance ( T it,
size_t  Val 
)
static
static Error checkDyldCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char *  CmdName 
)
static
static Error checkDyldInfoCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
const char *  CmdName,
std::list< MachOElement > &  Elements 
)
static
static Error checkDylibCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char *  CmdName 
)
static
static Error checkDylibIdCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd 
)
static
static Error checkDysymtabCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  DysymtabLoadCmd,
std::list< MachOElement > &  Elements 
)
static
static Error checkEncryptCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
uint64_t  cryptoff,
uint64_t  cryptsize,
const char **  LoadCmd,
const char *  CmdName 
)
static
static Error checkLinkeditDataCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
const char *  CmdName,
std::list< MachOElement > &  Elements,
const char *  ElementName 
)
static
static Error checkLinkerOptCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex 
)
static
static Error checkOverlappingElement ( std::list< MachOElement > &  Elements,
uint64_t  Offset,
uint64_t  Size,
const char *  Name 
)
static
static Error checkRpathCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex 
)
static
static Error checkSubCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char *  CmdName,
size_t  SizeOfCmd,
const char *  CmdStructName,
uint32_t  PathOffset,
const char *  PathFieldName 
)
static
static Error checkSymtabCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  SymtabLoadCmd,
std::list< MachOElement > &  Elements 
)
static
static Error checkThreadCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char *  CmdName 
)
static
static Error checkTwoLevelHintsCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
std::list< MachOElement > &  Elements 
)
static
static Error checkVersCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
const char *  CmdName 
)
static
static unsigned getCPUType ( const MachOObjectFile &  O)
static
static Expected<MachOObjectFile::LoadCommandInfo> getFirstLoadCommandInfo ( const MachOObjectFile &  Obj)
static

Definition at line 184 of file MachOObjectFile.cpp.

References getLoadCommandInfo(), getPtr(), and malformedError().

static Expected<MachOObjectFile::LoadCommandInfo> getLoadCommandInfo ( const MachOObjectFile &  Obj,
const char *  Ptr,
uint32_t  LoadCommandIndex 
)
static

Definition at line 172 of file MachOObjectFile.cpp.

References malformedError(), and Ptr.

Referenced by getFirstLoadCommandInfo(), and getNextLoadCommandInfo().

static Expected<MachOObjectFile::LoadCommandInfo> getNextLoadCommandInfo ( const MachOObjectFile &  Obj,
uint32_t  LoadCommandIndex,
const MachOObjectFile::LoadCommandInfo L 
)
static
static uint32_t getPlainRelocationAddress ( const MachO::any_relocation_info RE)
static
static unsigned getPlainRelocationLength ( const MachOObjectFile &  O,
const MachO::any_relocation_info RE 
)
static
static bool getPlainRelocationPCRel ( const MachOObjectFile &  O,
const MachO::any_relocation_info RE 
)
static
static unsigned getPlainRelocationType ( const MachOObjectFile &  O,
const MachO::any_relocation_info RE 
)
static
static const char* getPtr ( const MachOObjectFile &  O,
size_t  Offset 
)
static
static unsigned getScatteredRelocationAddress ( const MachO::any_relocation_info RE)
static
static unsigned getScatteredRelocationLength ( const MachO::any_relocation_info RE)
static
static bool getScatteredRelocationPCRel ( const MachO::any_relocation_info RE)
static
static uint32_t getSectionFlags ( const MachOObjectFile &  O,
DataRefImpl  Sec 
)
static
static const char* getSectionPtr ( const MachOObjectFile &  O,
MachOObjectFile::LoadCommandInfo  L,
unsigned  Sec 
)
static
template<typename T >
static T getStruct ( const MachOObjectFile &  O,
const char *  P 
)
static
template<typename T >
static Expected<T> getStructOrErr ( const MachOObjectFile &  O,
const char *  P 
)
static
static MachO::nlist_base getSymbolTableEntryBase ( const MachOObjectFile &  O,
DataRefImpl  DRI 
)
static
static bool isLoadCommandObsolete ( uint32_t  cmd)
static

Definition at line 1057 of file MachOObjectFile.cpp.

static Error malformedError ( Twine  Msg)
static
template<typename T >
static void parseHeader ( const MachOObjectFile &  Obj,
T Header,
Error Err 
)
static

Definition at line 206 of file MachOObjectFile.cpp.

References getPtr(), and malformedError().

template<typename Segment , typename Section >
static Error parseSegmentLoadCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo Load,
SmallVectorImpl< const char * > &  Sections,
bool IsPageZeroSegment,
uint32_t  LoadCommandIndex,
const char *  CmdName,
uint64_t  SizeOfHeaders,
std::list< MachOElement > &  Elements 
)
static
static StringRef parseSegmentOrSectionName ( const char *  P)
static