Index: include/llvm/Object/MachO.h =================================================================== --- include/llvm/Object/MachO.h +++ include/llvm/Object/MachO.h @@ -380,6 +380,7 @@ ArrayRef getDyldInfoWeakBindOpcodes() const; ArrayRef getDyldInfoLazyBindOpcodes() const; ArrayRef getDyldInfoExportsTrie() const; + ArrayRef getUuid() const; StringRef getStringTableData() const; bool is64Bit() const; @@ -417,6 +418,7 @@ const char *DysymtabLoadCmd; const char *DataInCodeLoadCmd; const char *DyldInfoLoadCmd; + const char *UuidLoadCmd; bool HasPageZeroSegment; }; Index: lib/Object/MachOObjectFile.cpp =================================================================== --- lib/Object/MachOObjectFile.cpp +++ lib/Object/MachOObjectFile.cpp @@ -239,7 +239,7 @@ : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object), SymtabLoadCmd(nullptr), DysymtabLoadCmd(nullptr), DataInCodeLoadCmd(nullptr), DyldInfoLoadCmd(nullptr), - HasPageZeroSegment(false) { + UuidLoadCmd(nullptr), HasPageZeroSegment(false) { uint32_t LoadCommandCount = this->getHeader().ncmds; MachO::LoadCommandType SegmentLoadType = is64Bit() ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT; @@ -259,6 +259,9 @@ Load.C.cmd == MachO::LC_DYLD_INFO_ONLY) { assert(!DyldInfoLoadCmd && "Multiple dyldinfo load commands"); DyldInfoLoadCmd = Load.Ptr; + } else if (Load.C.cmd == MachO::LC_UUID) { + assert(!UuidLoadCmd && "Multiple UUID load commands"); + UuidLoadCmd = Load.Ptr; } else if (Load.C.cmd == SegmentLoadType) { uint32_t NumSections = getSegmentLoadCommandNumSections(this, Load); for (unsigned J = 0; J < NumSections; ++J) { @@ -2418,6 +2421,12 @@ return ArrayRef(Ptr, DyldInfo.export_size); } +ArrayRef MachOObjectFile::getUuid() const { + if (!UuidLoadCmd) + return ArrayRef(); + MachO::uuid_command Uuid = getStruct(this, UuidLoadCmd); + return ArrayRef(Uuid.uuid, 16); +} StringRef MachOObjectFile::getStringTableData() const { MachO::symtab_command S = getSymtabLoadCommand();