From: Alexander Potapenko Date: Wed, 15 Oct 2014 23:35:45 +0000 (+0000) Subject: Add MachOObjectFile::getUuid() X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4976a53fb76817cc405a7b1a7c18d40c3b7e7e3a;p=oota-llvm.git Add MachOObjectFile::getUuid() This CL introduces MachOObjectFile::getUuid(). This function returns an ArrayRef to the object file's UUID, or an empty ArrayRef if the object file doesn't contain an LC_UUID load command. The new function is gonna be used by llvm-symbolizer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219866 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 1936e4178dc..2497b7aea66 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -380,6 +380,7 @@ public: ArrayRef getDyldInfoWeakBindOpcodes() const; ArrayRef getDyldInfoLazyBindOpcodes() const; ArrayRef getDyldInfoExportsTrie() const; + ArrayRef getUuid() const; StringRef getStringTableData() const; bool is64Bit() const; @@ -417,6 +418,7 @@ private: const char *DysymtabLoadCmd; const char *DataInCodeLoadCmd; const char *DyldInfoLoadCmd; + const char *UuidLoadCmd; bool HasPageZeroSegment; }; diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 260e7557f43..4435815b899 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -239,7 +239,7 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, : 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 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, 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 @@ ArrayRef MachOObjectFile::getDyldInfoExportsTrie() const { 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();