LLVM  8.0.1
Classes | Functions
MachOObjectFile.cpp File Reference
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/Object/Error.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <list>
#include <memory>
#include <string>
#include <system_error>
Include dependency graph for MachOObjectFile.cpp:

Go to the source code of this file.

Classes

struct  MachOElement
 

Functions

static Error malformedError (const 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 chargetSectionPtr (const MachOObjectFile &O, MachOObjectFile::LoadCommandInfo L, unsigned Sec)
 
static const chargetPtr (const MachOObjectFile &O, size_t Offset)
 
static MachO::nlist_base getSymbolTableEntryBase (const MachOObjectFile &O, DataRefImpl DRI)
 
static StringRef parseSegmentOrSectionName (const char *P)
 
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 checkNoteCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, uint32_t LoadCommandIndex, std::list< MachOElement > &Elements)
 
static Error parseBuildVersionCommand (const MachOObjectFile &Obj, const MachOObjectFile::LoadCommandInfo &Load, SmallVectorImpl< const char *> &BuildTools, uint32_t LoadCommandIndex)
 
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

◆ checkDyldCommand()

static Error checkDyldCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char CmdName 
)
static

◆ checkDyldInfoCommand()

static Error checkDyldInfoCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
const char CmdName,
std::list< MachOElement > &  Elements 
)
static

◆ checkDylibCommand()

static Error checkDylibCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char CmdName 
)
static

◆ checkDylibIdCommand()

static Error checkDylibIdCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd 
)
static

Definition at line 741 of file MachOObjectFile.cpp.

◆ checkDysymtabCommand()

static Error checkDysymtabCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char **  DysymtabLoadCmd,
std::list< MachOElement > &  Elements 
)
static

◆ checkEncryptCommand()

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

Definition at line 877 of file MachOObjectFile.cpp.

References malformedError(), and llvm::Error::success().

◆ checkLinkeditDataCommand()

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

◆ checkLinkerOptCommand()

static Error checkLinkerOptCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex 
)
static

◆ checkNoteCommand()

static Error checkNoteCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
std::list< MachOElement > &  Elements 
)
static

◆ checkOverlappingElement()

static Error checkOverlappingElement ( std::list< MachOElement > &  Elements,
uint64_t  Offset,
uint64_t  Size,
const char Name 
)
static

Definition at line 241 of file MachOObjectFile.cpp.

References E, malformedError(), N, Size, and llvm::Error::success().

◆ checkRpathCommand()

static Error checkRpathCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex 
)
static

◆ checkSubCommand()

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

Definition at line 934 of file MachOObjectFile.cpp.

References for(), malformedError(), P, and llvm::Error::success().

◆ checkSymtabCommand()

static Error checkSymtabCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char **  SymtabLoadCmd,
std::list< MachOElement > &  Elements 
)
static

◆ checkThreadCommand()

static Error checkThreadCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char CmdName 
)
static

◆ checkTwoLevelHintsCommand()

static Error checkTwoLevelHintsCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
std::list< MachOElement > &  Elements 
)
static

◆ checkVersCommand()

static Error checkVersCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
uint32_t  LoadCommandIndex,
const char **  LoadCmd,
const char CmdName 
)
static

Definition at line 787 of file MachOObjectFile.cpp.

References malformedError(), and llvm::Error::success().

◆ getCPUType()

static unsigned getCPUType ( const MachOObjectFile &  O)
static

◆ getFirstLoadCommandInfo()

static Expected<MachOObjectFile::LoadCommandInfo> getFirstLoadCommandInfo ( const MachOObjectFile &  Obj)
static

◆ getLoadCommandInfo()

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

Definition at line 184 of file MachOObjectFile.cpp.

References malformedError().

Referenced by getFirstLoadCommandInfo(), and getNextLoadCommandInfo().

◆ getNextLoadCommandInfo()

static Expected<MachOObjectFile::LoadCommandInfo> getNextLoadCommandInfo ( const MachOObjectFile &  Obj,
uint32_t  LoadCommandIndex,
const MachOObjectFile::LoadCommandInfo &  L 
)
static

◆ getPlainRelocationAddress()

static uint32_t getPlainRelocationAddress ( const MachO::any_relocation_info RE)
static

◆ getPlainRelocationLength()

static unsigned getPlainRelocationLength ( const MachOObjectFile &  O,
const MachO::any_relocation_info RE 
)
static

◆ getPlainRelocationPCRel()

static bool getPlainRelocationPCRel ( const MachOObjectFile &  O,
const MachO::any_relocation_info RE 
)
static

◆ getPlainRelocationType()

static unsigned getPlainRelocationType ( const MachOObjectFile &  O,
const MachO::any_relocation_info RE 
)
static

◆ getPtr()

static const char* getPtr ( const MachOObjectFile &  O,
size_t  Offset 
)
static

◆ getScatteredRelocationAddress()

static unsigned getScatteredRelocationAddress ( const MachO::any_relocation_info RE)
static

◆ getScatteredRelocationLength()

static unsigned getScatteredRelocationLength ( const MachO::any_relocation_info RE)
static

◆ getScatteredRelocationPCRel()

static bool getScatteredRelocationPCRel ( const MachO::any_relocation_info RE)
static

◆ getSectionFlags()

static uint32_t getSectionFlags ( const MachOObjectFile &  O,
DataRefImpl  Sec 
)
static

◆ getSectionPtr()

static const char* getSectionPtr ( const MachOObjectFile &  O,
MachOObjectFile::LoadCommandInfo  L,
unsigned  Sec 
)
static

◆ getStruct()

template<typename T >
static T getStruct ( const MachOObjectFile &  O,
const char P 
)
static

◆ getStructOrErr()

template<typename T >
static Expected<T> getStructOrErr ( const MachOObjectFile &  O,
const char P 
)
static

◆ getSymbolTableEntryBase()

static MachO::nlist_base getSymbolTableEntryBase ( const MachOObjectFile &  O,
DataRefImpl  DRI 
)
static

◆ isLoadCommandObsolete()

static bool isLoadCommandObsolete ( uint32_t  cmd)
static

Definition at line 1185 of file MachOObjectFile.cpp.

◆ malformedError()

static Error malformedError ( const Twine Msg)
static

◆ parseBuildVersionCommand()

static Error parseBuildVersionCommand ( const MachOObjectFile &  Obj,
const MachOObjectFile::LoadCommandInfo &  Load,
SmallVectorImpl< const char *> &  BuildTools,
uint32_t  LoadCommandIndex 
)
static

◆ parseHeader()

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

Definition at line 221 of file MachOObjectFile.cpp.

◆ parseSegmentLoadCommand()

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

◆ parseSegmentOrSectionName()

static StringRef parseSegmentOrSectionName ( const char P)
static