LLVM 20.0.0git
Classes | Macros | Functions
MachOObjectFile.cpp File Reference
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/bit.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/BinaryFormat/Swift.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/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <list>
#include <memory>
#include <system_error>
#include "llvm/BinaryFormat/Swift.def"

Go to the source code of this file.

Classes

struct  MachOElement
 

Macros

#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF)    .Case(MACHO, llvm::binaryformat::Swift5ReflectionSectionKind::KIND)
 

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, size_t MachOFilesetEntryOffset=0)
 
static MachO::nlist_base getSymbolTableEntryBase (const MachOObjectFile &O, DataRefImpl DRI)
 
static StringRef parseSegmentOrSectionName (const char *P)
 
static unsigned getCPUType (const MachOObjectFile &O)
 
static unsigned getCPUSubType (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::LoadCommandInfogetLoadCommandInfo (const MachOObjectFile &Obj, const char *Ptr, uint32_t LoadCommandIndex)
 
static Expected< MachOObjectFile::LoadCommandInfogetFirstLoadCommandInfo (const MachOObjectFile &Obj)
 
static Expected< MachOObjectFile::LoadCommandInfogetNextLoadCommandInfo (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)
 
template<typename T >
static int getEncodedOrdinal (T Value)
 
template<typename T , unsigned N>
static std::array< T, NgetArray (const MachOObjectFile &O, const void *Ptr)
 

Macro Definition Documentation

◆ HANDLE_SWIFT_SECTION

#define HANDLE_SWIFT_SECTION (   KIND,
  MACHO,
  ELF,
  COFF 
)     .Case(MACHO, llvm::binaryformat::Swift5ReflectionSectionKind::KIND)

Function Documentation

◆ checkDyldCommand()

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

Definition at line 786 of file MachOObjectFile.cpp.

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

◆ 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

Definition at line 737 of file MachOObjectFile.cpp.

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

Referenced by checkDylibIdCommand().

◆ checkDylibIdCommand()

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

◆ 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

◆ 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

◆ checkRpathCommand()

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

Definition at line 885 of file MachOObjectFile.cpp.

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

◆ 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 981 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 818 of file MachOObjectFile.cpp.

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

◆ getArray()

template<typename T , unsigned N>
static std::array< T, N > getArray ( const MachOObjectFile O,
const void *  Ptr 
)
static

◆ getCPUSubType()

static unsigned getCPUSubType ( const MachOObjectFile O)
static

Definition at line 136 of file MachOObjectFile.cpp.

Referenced by llvm::object::MachOObjectFile::getArch().

◆ getCPUType()

static unsigned getCPUType ( const MachOObjectFile O)
static

◆ getEncodedOrdinal()

template<typename T >
static int getEncodedOrdinal ( T  Value)
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

◆ 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,
size_t  MachOFilesetEntryOffset = 0 
)
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 1238 of file MachOObjectFile.cpp.

References llvm::MachO::linker_option_command::cmd.

◆ 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

◆ 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