From 167957fa095bc7200b908e6e142be3e604bcfeea Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 9 May 2013 03:39:05 +0000 Subject: Change getRelocationAdditionalInfo to be ELF only. It was only implemented for ELF where it collected the Addend, so this patch also renames it to getRelocationAddend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181502 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/llvm/Object/MachO.h') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 14cd4d7..bedf5c1 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -76,8 +76,6 @@ public: virtual error_code getRelocationType(DataRefImpl Rel, uint64_t &Res) const; virtual error_code getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl &Result) const; - virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel, - int64_t &Res) const; virtual error_code getRelocationValueString(DataRefImpl Rel, SmallVectorImpl &Result) const; virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const; -- cgit v1.1 From 6c1202c459ffa6d693ad92fa84e43902bc780bca Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 5 Jun 2013 01:33:53 +0000 Subject: Handle relocations that don't point to symbols. In ELF (as in MachO), not all relocations point to symbols. Represent this properly by using a symbol_iterator instead of a SymbolRef. Update llvm-readobj ELF's dumper to handle relocatios without symbols. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183284 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/llvm/Object/MachO.h') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index bedf5c1..f3ba8ef 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -72,7 +72,7 @@ public: RelocationRef &Res) const; virtual error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const; virtual error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const; - virtual error_code getRelocationSymbol(DataRefImpl Rel, SymbolRef &Res) const; + virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const; virtual error_code getRelocationType(DataRefImpl Rel, uint64_t &Res) const; virtual error_code getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl &Result) const; -- cgit v1.1 From 54154f3bf1ae3d2dfd68cc9474cad061b3338a40 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Thu, 6 Jun 2013 17:20:50 +0000 Subject: Teach llvm-objdump with the -macho parser how to use the data in code table from the LC_DATA_IN_CODE load command. And when disassembling print the data in code formatted for the kind of data it and not disassemble those bytes. I added the format specific functionality to the derived class MachOObjectFile since these tables only appears in Mach-O object files. This is my first attempt to modify the libObject stuff so if folks have better suggestions how to fit this in or suggestions on the implementation please let me know. rdar://11791371 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183424 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'include/llvm/Object/MachO.h') diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index f3ba8ef..1b9faaa 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -25,6 +25,31 @@ namespace llvm { namespace object { +/// DiceRef - This is a value type class that represents a single +/// data in code entry in the table in a Mach-O object file. +class DiceRef { + DataRefImpl DicePimpl; + const ObjectFile *OwningObject; + +public: + DiceRef() : OwningObject(NULL) { } + + DiceRef(DataRefImpl DiceP, const ObjectFile *Owner); + + bool operator==(const DiceRef &Other) const; + bool operator<(const DiceRef &Other) const; + + error_code getNext(DiceRef &Result) const; + + error_code getOffset(uint32_t &Result) const; + error_code getLength(uint16_t &Result) const; + error_code getKind(uint16_t &Result) const; + + DataRefImpl getRawDataRefImpl() const; + const ObjectFile *getObjectFile() const; +}; +typedef content_iterator dice_iterator; + class MachOObjectFile : public ObjectFile { public: struct LoadCommandInfo { @@ -108,6 +133,9 @@ public: relocation_iterator getSectionRelBegin(unsigned Index) const; relocation_iterator getSectionRelEnd(unsigned Index) const; + dice_iterator begin_dices() const; + dice_iterator end_dices() const; + // In a MachO file, sections have a segment name. This is used in the .o // files. They have a single segment, but this field specifies which segment // a section should be put in in the final object. @@ -152,6 +180,7 @@ public: getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const; macho::RelocationEntry getRelocation(DataRefImpl Rel) const; + macho::DataInCodeTableEntry getDice(DataRefImpl Rel) const; macho::Header getHeader() const; macho::Header64Ext getHeader64Ext() const; macho::IndirectSymbolTableEntry @@ -161,6 +190,7 @@ public: unsigned Index) const; macho::SymtabLoadCommand getSymtabLoadCommand() const; macho::DysymtabLoadCommand getDysymtabLoadCommand() const; + macho::LinkeditDataLoadCommand getDataInCodeLoadCommand() const; StringRef getStringTableData() const; bool is64Bit() const; @@ -175,8 +205,66 @@ private: SectionList Sections; const char *SymtabLoadCmd; const char *DysymtabLoadCmd; + const char *DataInCodeLoadCmd; }; +/// DiceRef +inline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner) + : DicePimpl(DiceP) , OwningObject(Owner) {} + +inline bool DiceRef::operator==(const DiceRef &Other) const { + return DicePimpl == Other.DicePimpl; +} + +inline bool DiceRef::operator<(const DiceRef &Other) const { + return DicePimpl < Other.DicePimpl; +} + +inline error_code DiceRef::getNext(DiceRef &Result) const { + DataRefImpl Rel = DicePimpl; + const macho::DataInCodeTableEntry *P = + reinterpret_cast(Rel.p); + Rel.p = reinterpret_cast(P + 1); + Result = DiceRef(Rel, OwningObject); + return object_error::success; +} + +// Since a Mach-O data in code reference, a DiceRef, can only be created when +// the OwningObject ObjectFile is a MachOObjectFile a static_cast<> is used for +// the methods that get the values of the fields of the reference. + +inline error_code DiceRef::getOffset(uint32_t &Result) const { + const MachOObjectFile *MachOOF = + static_cast(OwningObject); + macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl); + Result = Dice.Offset; + return object_error::success; +} + +inline error_code DiceRef::getLength(uint16_t &Result) const { + const MachOObjectFile *MachOOF = + static_cast(OwningObject); + macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl); + Result = Dice.Length; + return object_error::success; +} + +inline error_code DiceRef::getKind(uint16_t &Result) const { + const MachOObjectFile *MachOOF = + static_cast(OwningObject); + macho::DataInCodeTableEntry Dice = MachOOF->getDice(DicePimpl); + Result = Dice.Kind; + return object_error::success; +} + +inline DataRefImpl DiceRef::getRawDataRefImpl() const { + return DicePimpl; +} + +inline const ObjectFile *DiceRef::getObjectFile() const { + return OwningObject; +} + } } -- cgit v1.1