mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-16 14:31:16 +00:00
Simplify the handling of iterators in ObjectFile.
None of the object file formats reported error on iterator increment. In retrospect, that is not too surprising: no object format stores symbols or sections in a linked list or other structure that requires chasing pointers. As a consequence, all error checking can be done on begin() and end(). This reduces the text segment of bin/llvm-readobj in my machine from 521233 to 518526 bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200442 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6bf3966f7f
commit
efdbec8b0a
include/llvm/Object
lib
DebugInfo
ExecutionEngine/RuntimeDyld
MC
Object
Target/X86/MCTargetDesc
tools
llvm-ar
llvm-nm
llvm-objdump
llvm-readobj
llvm-rtdyld
llvm-size
llvm-symbolizer
macho-dump
obj2yaml
@ -271,8 +271,7 @@ private:
|
|||||||
error_code initExportTablePtr();
|
error_code initExportTablePtr();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
|
void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
|
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const
|
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const
|
||||||
@ -288,8 +287,7 @@ protected:
|
|||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const
|
error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
|
void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
|
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
|
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
|
||||||
@ -313,8 +311,7 @@ protected:
|
|||||||
relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE;
|
relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE;
|
||||||
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
|
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
|
||||||
|
|
||||||
error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
|
void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
|
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
|
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
|
||||||
@ -397,7 +394,7 @@ public:
|
|||||||
: ImportTable(Table), Index(I), OwningObject(Owner) {}
|
: ImportTable(Table), Index(I), OwningObject(Owner) {}
|
||||||
|
|
||||||
bool operator==(const ImportDirectoryEntryRef &Other) const;
|
bool operator==(const ImportDirectoryEntryRef &Other) const;
|
||||||
error_code getNext(ImportDirectoryEntryRef &Result) const;
|
void moveNext();
|
||||||
error_code getName(StringRef &Result) const;
|
error_code getName(StringRef &Result) const;
|
||||||
|
|
||||||
error_code
|
error_code
|
||||||
@ -421,7 +418,7 @@ public:
|
|||||||
: ExportTable(Table), Index(I), OwningObject(Owner) {}
|
: ExportTable(Table), Index(I), OwningObject(Owner) {}
|
||||||
|
|
||||||
bool operator==(const ExportDirectoryEntryRef &Other) const;
|
bool operator==(const ExportDirectoryEntryRef &Other) const;
|
||||||
error_code getNext(ExportDirectoryEntryRef &Result) const;
|
void moveNext();
|
||||||
|
|
||||||
error_code getDllName(StringRef &Result) const;
|
error_code getDllName(StringRef &Result) const;
|
||||||
error_code getOrdinalBase(uint32_t &Result) const;
|
error_code getOrdinalBase(uint32_t &Result) const;
|
||||||
|
@ -55,8 +55,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
ELFFile<ELFT> EF;
|
ELFFile<ELFT> EF;
|
||||||
|
|
||||||
error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
|
void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
|
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const
|
error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const
|
||||||
@ -78,8 +77,7 @@ protected:
|
|||||||
error_code getLibraryPath(DataRefImpl Data, StringRef &Res) const
|
error_code getLibraryPath(DataRefImpl Data, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
|
void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
|
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
|
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
|
||||||
@ -102,8 +100,7 @@ protected:
|
|||||||
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
|
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
|
||||||
section_iterator getRelocatedSection(DataRefImpl Sec) const LLVM_OVERRIDE;
|
section_iterator getRelocatedSection(DataRefImpl Sec) const LLVM_OVERRIDE;
|
||||||
|
|
||||||
error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
|
void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
|
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
|
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
|
||||||
@ -222,10 +219,8 @@ typedef ELFObjectFile<ELFType<support::big, 2, false> > ELF32BEObjectFile;
|
|||||||
typedef ELFObjectFile<ELFType<support::big, 2, true> > ELF64BEObjectFile;
|
typedef ELFObjectFile<ELFType<support::big, 2, true> > ELF64BEObjectFile;
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
error_code ELFObjectFile<ELFT>::getSymbolNext(DataRefImpl Symb,
|
void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Symb) const {
|
||||||
SymbolRef &Result) const {
|
Symb = toDRI(++toELFSymIter(Symb));
|
||||||
Result = SymbolRef(toDRI(++toELFSymIter(Symb)), this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
@ -439,10 +434,8 @@ error_code ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
error_code ELFObjectFile<ELFT>::getSectionNext(DataRefImpl Sec,
|
void ELFObjectFile<ELFT>::moveSectionNext(DataRefImpl &Sec) const {
|
||||||
SectionRef &Result) const {
|
Sec = toDRI(++toELFShdrIter(Sec));
|
||||||
Result = SectionRef(toDRI(++toELFShdrIter(Sec)), this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
@ -594,11 +587,8 @@ ELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const {
|
|||||||
|
|
||||||
// Relocations
|
// Relocations
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
error_code ELFObjectFile<ELFT>::getRelocationNext(DataRefImpl Rel,
|
void ELFObjectFile<ELFT>::moveRelocationNext(DataRefImpl &Rel) const {
|
||||||
RelocationRef &Result) const {
|
|
||||||
++Rel.d.b;
|
++Rel.d.b;
|
||||||
Result = RelocationRef(Rel, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
bool operator==(const DiceRef &Other) const;
|
bool operator==(const DiceRef &Other) const;
|
||||||
bool operator<(const DiceRef &Other) const;
|
bool operator<(const DiceRef &Other) const;
|
||||||
|
|
||||||
error_code getNext(DiceRef &Result) const;
|
void moveNext();
|
||||||
|
|
||||||
error_code getOffset(uint32_t &Result) const;
|
error_code getOffset(uint32_t &Result) const;
|
||||||
error_code getLength(uint16_t &Result) const;
|
error_code getLength(uint16_t &Result) const;
|
||||||
@ -59,8 +59,7 @@ public:
|
|||||||
MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits,
|
MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits,
|
||||||
error_code &EC, bool BufferOwned = true);
|
error_code &EC, bool BufferOwned = true);
|
||||||
|
|
||||||
error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const
|
void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
|
error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const
|
error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const
|
||||||
@ -79,8 +78,7 @@ public:
|
|||||||
error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const
|
error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const
|
void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
|
error_code getSectionName(DataRefImpl Sec, StringRef &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
|
error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const
|
||||||
@ -104,8 +102,7 @@ public:
|
|||||||
relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE;
|
relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE;
|
||||||
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
|
relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE;
|
||||||
|
|
||||||
error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const
|
void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE;
|
||||||
LLVM_OVERRIDE;
|
|
||||||
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
|
error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
|
error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const
|
||||||
@ -244,13 +241,10 @@ inline bool DiceRef::operator<(const DiceRef &Other) const {
|
|||||||
return DicePimpl < Other.DicePimpl;
|
return DicePimpl < Other.DicePimpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code DiceRef::getNext(DiceRef &Result) const {
|
inline void DiceRef::moveNext() {
|
||||||
DataRefImpl Rel = DicePimpl;
|
|
||||||
const MachO::data_in_code_entry *P =
|
const MachO::data_in_code_entry *P =
|
||||||
reinterpret_cast<const MachO::data_in_code_entry *>(Rel.p);
|
reinterpret_cast<const MachO::data_in_code_entry *>(DicePimpl.p);
|
||||||
Rel.p = reinterpret_cast<uintptr_t>(P + 1);
|
DicePimpl.p = reinterpret_cast<uintptr_t>(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
|
// Since a Mach-O data in code reference, a DiceRef, can only be created when
|
||||||
|
@ -63,12 +63,8 @@ public:
|
|||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
content_iterator& increment(error_code &err) {
|
content_iterator &operator++() { // preincrement
|
||||||
content_type next;
|
Current.moveNext();
|
||||||
if (error_code ec = Current.getNext(next))
|
|
||||||
err = ec;
|
|
||||||
else
|
|
||||||
Current = next;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -101,7 +97,7 @@ public:
|
|||||||
|
|
||||||
bool operator==(const RelocationRef &Other) const;
|
bool operator==(const RelocationRef &Other) const;
|
||||||
|
|
||||||
error_code getNext(RelocationRef &Result) const;
|
void moveNext();
|
||||||
|
|
||||||
error_code getAddress(uint64_t &Result) const;
|
error_code getAddress(uint64_t &Result) const;
|
||||||
error_code getOffset(uint64_t &Result) const;
|
error_code getOffset(uint64_t &Result) const;
|
||||||
@ -146,7 +142,7 @@ public:
|
|||||||
bool operator==(const SectionRef &Other) const;
|
bool operator==(const SectionRef &Other) const;
|
||||||
bool operator<(const SectionRef &Other) const;
|
bool operator<(const SectionRef &Other) const;
|
||||||
|
|
||||||
error_code getNext(SectionRef &Result) const;
|
void moveNext();
|
||||||
|
|
||||||
error_code getName(StringRef &Result) const;
|
error_code getName(StringRef &Result) const;
|
||||||
error_code getAddress(uint64_t &Result) const;
|
error_code getAddress(uint64_t &Result) const;
|
||||||
@ -210,7 +206,7 @@ public:
|
|||||||
bool operator==(const SymbolRef &Other) const;
|
bool operator==(const SymbolRef &Other) const;
|
||||||
bool operator<(const SymbolRef &Other) const;
|
bool operator<(const SymbolRef &Other) const;
|
||||||
|
|
||||||
error_code getNext(SymbolRef &Result) const;
|
void moveNext();
|
||||||
|
|
||||||
error_code getName(StringRef &Result) const;
|
error_code getName(StringRef &Result) const;
|
||||||
/// Returns the symbol virtual address (i.e. address at which it will be
|
/// Returns the symbol virtual address (i.e. address at which it will be
|
||||||
@ -285,7 +281,7 @@ protected:
|
|||||||
// Implementations assume that the DataRefImpl is valid and has not been
|
// Implementations assume that the DataRefImpl is valid and has not been
|
||||||
// modified externally. It's UB otherwise.
|
// modified externally. It's UB otherwise.
|
||||||
friend class SymbolRef;
|
friend class SymbolRef;
|
||||||
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0;
|
virtual void moveSymbolNext(DataRefImpl &Symb) const = 0;
|
||||||
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
|
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
|
||||||
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0;
|
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0;
|
||||||
virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0;
|
virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0;
|
||||||
@ -301,7 +297,7 @@ protected:
|
|||||||
|
|
||||||
// Same as above for SectionRef.
|
// Same as above for SectionRef.
|
||||||
friend class SectionRef;
|
friend class SectionRef;
|
||||||
virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const = 0;
|
virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
|
||||||
virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const = 0;
|
virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const = 0;
|
||||||
virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const =0;
|
virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const =0;
|
||||||
virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const = 0;
|
virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const = 0;
|
||||||
@ -324,8 +320,7 @@ protected:
|
|||||||
|
|
||||||
// Same as above for RelocationRef.
|
// Same as above for RelocationRef.
|
||||||
friend class RelocationRef;
|
friend class RelocationRef;
|
||||||
virtual error_code getRelocationNext(DataRefImpl Rel,
|
virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
|
||||||
RelocationRef &Res) const = 0;
|
|
||||||
virtual error_code getRelocationAddress(DataRefImpl Rel,
|
virtual error_code getRelocationAddress(DataRefImpl Rel,
|
||||||
uint64_t &Res) const =0;
|
uint64_t &Res) const =0;
|
||||||
virtual error_code getRelocationOffset(DataRefImpl Rel,
|
virtual error_code getRelocationOffset(DataRefImpl Rel,
|
||||||
@ -412,8 +407,8 @@ inline bool SymbolRef::operator<(const SymbolRef &Other) const {
|
|||||||
return SymbolPimpl < Other.SymbolPimpl;
|
return SymbolPimpl < Other.SymbolPimpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code SymbolRef::getNext(SymbolRef &Result) const {
|
inline void SymbolRef::moveNext() {
|
||||||
return OwningObject->getSymbolNext(SymbolPimpl, Result);
|
return OwningObject->moveSymbolNext(SymbolPimpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code SymbolRef::getName(StringRef &Result) const {
|
inline error_code SymbolRef::getName(StringRef &Result) const {
|
||||||
@ -471,8 +466,8 @@ inline bool SectionRef::operator<(const SectionRef &Other) const {
|
|||||||
return SectionPimpl < Other.SectionPimpl;
|
return SectionPimpl < Other.SectionPimpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code SectionRef::getNext(SectionRef &Result) const {
|
inline void SectionRef::moveNext() {
|
||||||
return OwningObject->getSectionNext(SectionPimpl, Result);
|
return OwningObject->moveSectionNext(SectionPimpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code SectionRef::getName(StringRef &Result) const {
|
inline error_code SectionRef::getName(StringRef &Result) const {
|
||||||
@ -554,8 +549,8 @@ inline bool RelocationRef::operator==(const RelocationRef &Other) const {
|
|||||||
return RelocationPimpl == Other.RelocationPimpl;
|
return RelocationPimpl == Other.RelocationPimpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code RelocationRef::getNext(RelocationRef &Result) const {
|
inline void RelocationRef::moveNext() {
|
||||||
return OwningObject->getRelocationNext(RelocationPimpl, Result);
|
return OwningObject->moveRelocationNext(RelocationPimpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline error_code RelocationRef::getAddress(uint64_t &Result) const {
|
inline error_code RelocationRef::getAddress(uint64_t &Result) const {
|
||||||
|
@ -603,10 +603,9 @@ static bool consumeCompressedDebugSectionHeader(StringRef &data,
|
|||||||
DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
|
DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
|
||||||
IsLittleEndian(Obj->isLittleEndian()),
|
IsLittleEndian(Obj->isLittleEndian()),
|
||||||
AddressSize(Obj->getBytesInAddress()) {
|
AddressSize(Obj->getBytesInAddress()) {
|
||||||
error_code ec;
|
|
||||||
for (object::section_iterator i = Obj->begin_sections(),
|
for (object::section_iterator i = Obj->begin_sections(),
|
||||||
e = Obj->end_sections();
|
e = Obj->end_sections();
|
||||||
i != e; i.increment(ec)) {
|
i != e; ++i) {
|
||||||
StringRef name;
|
StringRef name;
|
||||||
i->getName(name);
|
i->getName(name);
|
||||||
StringRef data;
|
StringRef data;
|
||||||
@ -697,8 +696,8 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
|
|||||||
uint64_t SectionSize;
|
uint64_t SectionSize;
|
||||||
RelocatedSection->getSize(SectionSize);
|
RelocatedSection->getSize(SectionSize);
|
||||||
for (object::relocation_iterator reloc_i = i->begin_relocations(),
|
for (object::relocation_iterator reloc_i = i->begin_relocations(),
|
||||||
reloc_e = i->end_relocations();
|
reloc_e = i->end_relocations();
|
||||||
reloc_i != reloc_e; reloc_i.increment(ec)) {
|
reloc_i != reloc_e; ++reloc_i) {
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
reloc_i->getOffset(Address);
|
reloc_i->getOffset(Address);
|
||||||
uint64_t Type;
|
uint64_t Type;
|
||||||
|
@ -115,12 +115,10 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
|
|||||||
// Maximum required total memory to allocate all common symbols
|
// Maximum required total memory to allocate all common symbols
|
||||||
uint64_t CommonSize = 0;
|
uint64_t CommonSize = 0;
|
||||||
|
|
||||||
error_code err;
|
|
||||||
// Parse symbols
|
// Parse symbols
|
||||||
DEBUG(dbgs() << "Parse symbols:\n");
|
DEBUG(dbgs() << "Parse symbols:\n");
|
||||||
for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols();
|
for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols(); i != e;
|
||||||
i != e; i.increment(err)) {
|
++i) {
|
||||||
Check(err);
|
|
||||||
object::SymbolRef::Type SymType;
|
object::SymbolRef::Type SymType;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
Check(i->getType(SymType));
|
Check(i->getType(SymType));
|
||||||
@ -173,18 +171,16 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
|
|||||||
|
|
||||||
// Parse and process relocations
|
// Parse and process relocations
|
||||||
DEBUG(dbgs() << "Parse relocations:\n");
|
DEBUG(dbgs() << "Parse relocations:\n");
|
||||||
for (section_iterator si = obj->begin_sections(),
|
for (section_iterator si = obj->begin_sections(), se = obj->end_sections();
|
||||||
se = obj->end_sections(); si != se; si.increment(err)) {
|
si != se; ++si) {
|
||||||
Check(err);
|
|
||||||
bool isFirstRelocation = true;
|
bool isFirstRelocation = true;
|
||||||
unsigned SectionID = 0;
|
unsigned SectionID = 0;
|
||||||
StubMap Stubs;
|
StubMap Stubs;
|
||||||
section_iterator RelocatedSection = si->getRelocatedSection();
|
section_iterator RelocatedSection = si->getRelocatedSection();
|
||||||
|
|
||||||
for (relocation_iterator i = si->begin_relocations(),
|
for (relocation_iterator i = si->begin_relocations(),
|
||||||
e = si->end_relocations(); i != e; i.increment(err)) {
|
e = si->end_relocations();
|
||||||
Check(err);
|
i != e; ++i) {
|
||||||
|
|
||||||
// If it's the first relocation in this section, find its SectionID
|
// If it's the first relocation in this section, find its SectionID
|
||||||
if (isFirstRelocation) {
|
if (isFirstRelocation) {
|
||||||
SectionID =
|
SectionID =
|
||||||
@ -251,21 +247,21 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
|
|||||||
|
|
||||||
unsigned StubBufSize = 0,
|
unsigned StubBufSize = 0,
|
||||||
StubSize = getMaxStubSize();
|
StubSize = getMaxStubSize();
|
||||||
error_code err;
|
|
||||||
const ObjectFile *ObjFile = Obj.getObjectFile();
|
const ObjectFile *ObjFile = Obj.getObjectFile();
|
||||||
// FIXME: this is an inefficient way to handle this. We should computed the
|
// FIXME: this is an inefficient way to handle this. We should computed the
|
||||||
// necessary section allocation size in loadObject by walking all the sections
|
// necessary section allocation size in loadObject by walking all the sections
|
||||||
// once.
|
// once.
|
||||||
if (StubSize > 0) {
|
if (StubSize > 0) {
|
||||||
for (section_iterator SI = ObjFile->begin_sections(),
|
for (section_iterator SI = ObjFile->begin_sections(),
|
||||||
SE = ObjFile->end_sections();
|
SE = ObjFile->end_sections();
|
||||||
SI != SE; SI.increment(err), Check(err)) {
|
SI != SE; ++SI) {
|
||||||
section_iterator RelSecI = SI->getRelocatedSection();
|
section_iterator RelSecI = SI->getRelocatedSection();
|
||||||
if (!(RelSecI == Section))
|
if (!(RelSecI == Section))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (relocation_iterator I = SI->begin_relocations(),
|
for (relocation_iterator I = SI->begin_relocations(),
|
||||||
E = SI->end_relocations(); I != E; I.increment(err), Check(err)) {
|
E = SI->end_relocations();
|
||||||
|
I != E; ++I) {
|
||||||
StubBufSize += StubSize;
|
StubBufSize += StubSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -621,10 +621,8 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj,
|
|||||||
RelocationValueRef &Rel) {
|
RelocationValueRef &Rel) {
|
||||||
// Get the ELF symbol value (st_value) to compare with Relocation offset in
|
// Get the ELF symbol value (st_value) to compare with Relocation offset in
|
||||||
// .opd entries
|
// .opd entries
|
||||||
|
for (section_iterator si = Obj.begin_sections(), se = Obj.end_sections();
|
||||||
error_code err;
|
si != se; ++si) {
|
||||||
for (section_iterator si = Obj.begin_sections(),
|
|
||||||
se = Obj.end_sections(); si != se; si.increment(err)) {
|
|
||||||
section_iterator RelSecI = si->getRelocatedSection();
|
section_iterator RelSecI = si->getRelocatedSection();
|
||||||
if (RelSecI == Obj.end_sections())
|
if (RelSecI == Obj.end_sections())
|
||||||
continue;
|
continue;
|
||||||
@ -636,14 +634,12 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj,
|
|||||||
|
|
||||||
for (relocation_iterator i = si->begin_relocations(),
|
for (relocation_iterator i = si->begin_relocations(),
|
||||||
e = si->end_relocations(); i != e;) {
|
e = si->end_relocations(); i != e;) {
|
||||||
check(err);
|
|
||||||
|
|
||||||
// The R_PPC64_ADDR64 relocation indicates the first field
|
// The R_PPC64_ADDR64 relocation indicates the first field
|
||||||
// of a .opd entry
|
// of a .opd entry
|
||||||
uint64_t TypeFunc;
|
uint64_t TypeFunc;
|
||||||
check(i->getType(TypeFunc));
|
check(i->getType(TypeFunc));
|
||||||
if (TypeFunc != ELF::R_PPC64_ADDR64) {
|
if (TypeFunc != ELF::R_PPC64_ADDR64) {
|
||||||
i.increment(err);
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,10 +649,9 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj,
|
|||||||
int64_t Addend;
|
int64_t Addend;
|
||||||
check(getELFRelocationAddend(*i, Addend));
|
check(getELFRelocationAddend(*i, Addend));
|
||||||
|
|
||||||
i = i.increment(err);
|
++i;
|
||||||
if (i == e)
|
if (i == e)
|
||||||
break;
|
break;
|
||||||
check(err);
|
|
||||||
|
|
||||||
// Just check if following relocation is a R_PPC64_TOC
|
// Just check if following relocation is a R_PPC64_TOC
|
||||||
uint64_t TypeTOC;
|
uint64_t TypeTOC;
|
||||||
|
@ -37,11 +37,8 @@ MCObjectDisassembler::MCObjectDisassembler(const ObjectFile &Obj,
|
|||||||
: Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {}
|
: Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {}
|
||||||
|
|
||||||
uint64_t MCObjectDisassembler::getEntrypoint() {
|
uint64_t MCObjectDisassembler::getEntrypoint() {
|
||||||
error_code ec;
|
|
||||||
for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
|
for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec)
|
|
||||||
break;
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
SI->getName(Name);
|
SI->getName(Name);
|
||||||
if (Name == "main" || Name == "_main") {
|
if (Name == "main" || Name == "_main") {
|
||||||
@ -90,13 +87,8 @@ MCModule *MCObjectDisassembler::buildModule(bool withCFG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
|
void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) {
|
||||||
error_code ec;
|
for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections();
|
||||||
for (section_iterator SI = Obj.begin_sections(),
|
SI != SE; ++SI) {
|
||||||
SE = Obj.end_sections();
|
|
||||||
SI != SE;
|
|
||||||
SI.increment(ec)) {
|
|
||||||
if (ec) break;
|
|
||||||
|
|
||||||
bool isText; SI->isText(isText);
|
bool isText; SI->isText(isText);
|
||||||
bool isData; SI->isData(isData);
|
bool isData; SI->isData(isData);
|
||||||
if (!isData && !isText)
|
if (!isData && !isText)
|
||||||
@ -184,11 +176,8 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) {
|
|||||||
AddressSetTy Splits;
|
AddressSetTy Splits;
|
||||||
AddressSetTy Calls;
|
AddressSetTy Calls;
|
||||||
|
|
||||||
error_code ec;
|
|
||||||
for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
|
for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec)
|
|
||||||
break;
|
|
||||||
SymbolRef::Type SymType;
|
SymbolRef::Type SymType;
|
||||||
SI->getType(SymType);
|
SI->getType(SymType);
|
||||||
if (SymType == SymbolRef::ST_Function) {
|
if (SymType == SymbolRef::ST_Function) {
|
||||||
@ -506,11 +495,8 @@ MCMachOObjectDisassembler::MCMachOObjectDisassembler(
|
|||||||
: MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF),
|
: MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF),
|
||||||
VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) {
|
VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) {
|
||||||
|
|
||||||
error_code ec;
|
|
||||||
for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections();
|
for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec)
|
|
||||||
break;
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
SI->getName(Name);
|
SI->getName(Name);
|
||||||
// FIXME: We should use the S_ section type instead of the name.
|
// FIXME: We should use the S_ section type instead of the name.
|
||||||
|
@ -52,10 +52,8 @@ MCMachObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
|
|||||||
: MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF),
|
: MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF),
|
||||||
StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) {
|
StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) {
|
||||||
|
|
||||||
error_code ec;
|
|
||||||
for (section_iterator SI = MOOF->begin_sections(), SE = MOOF->end_sections();
|
for (section_iterator SI = MOOF->begin_sections(), SE = MOOF->end_sections();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec) break;
|
|
||||||
StringRef Name; SI->getName(Name);
|
StringRef Name; SI->getName(Name);
|
||||||
if (Name == "__stubs") {
|
if (Name == "__stubs") {
|
||||||
SectionRef StubsSec = *SI;
|
SectionRef StubsSec = *SI;
|
||||||
@ -91,10 +89,8 @@ StringRef MCMachObjectSymbolizer::findExternalFunctionAt(uint64_t Addr) {
|
|||||||
|
|
||||||
StringRef SymName;
|
StringRef SymName;
|
||||||
symbol_iterator SI = MOOF->begin_symbols();
|
symbol_iterator SI = MOOF->begin_symbols();
|
||||||
error_code ec;
|
for (uint32_t i = 0; i != SymtabIdx; ++i)
|
||||||
for (uint32_t i = 0; i != SymtabIdx; ++i) {
|
++SI;
|
||||||
SI.increment(ec);
|
|
||||||
}
|
|
||||||
SI->getName(SymName);
|
SI->getName(SymName);
|
||||||
assert(SI != MOOF->end_symbols() && "Stub wasn't found in the symbol table!");
|
assert(SI != MOOF->end_symbols() && "Stub wasn't found in the symbol table!");
|
||||||
assert(SymName.front() == '_' && "Mach-O symbol doesn't start with '_'!");
|
assert(SymName.front() == '_' && "Mach-O symbol doesn't start with '_'!");
|
||||||
@ -159,10 +155,8 @@ tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream,
|
|||||||
return false;
|
return false;
|
||||||
uint64_t UValue = Value;
|
uint64_t UValue = Value;
|
||||||
// FIXME: map instead of looping each time?
|
// FIXME: map instead of looping each time?
|
||||||
error_code ec;
|
|
||||||
for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
|
for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec) break;
|
|
||||||
uint64_t SymAddr; SI->getAddress(SymAddr);
|
uint64_t SymAddr; SI->getAddress(SymAddr);
|
||||||
uint64_t SymSize; SI->getSize(SymSize);
|
uint64_t SymSize; SI->getSize(SymSize);
|
||||||
StringRef SymName; SI->getName(SymName);
|
StringRef SymName; SI->getName(SymName);
|
||||||
@ -239,11 +233,8 @@ const RelocationRef *MCObjectSymbolizer::findRelocationAt(uint64_t Addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MCObjectSymbolizer::buildSectionList() {
|
void MCObjectSymbolizer::buildSectionList() {
|
||||||
error_code ec;
|
|
||||||
for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
|
for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec) break;
|
|
||||||
|
|
||||||
bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec);
|
bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec);
|
||||||
if (RequiredForExec == false)
|
if (RequiredForExec == false)
|
||||||
continue;
|
continue;
|
||||||
@ -263,11 +254,8 @@ void MCObjectSymbolizer::buildSectionList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MCObjectSymbolizer::buildRelocationByAddrMap() {
|
void MCObjectSymbolizer::buildRelocationByAddrMap() {
|
||||||
error_code ec;
|
|
||||||
for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
|
for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec) break;
|
|
||||||
|
|
||||||
section_iterator RelSecI = SI->getRelocatedSection();
|
section_iterator RelSecI = SI->getRelocatedSection();
|
||||||
if (RelSecI == Obj->end_sections())
|
if (RelSecI == Obj->end_sections())
|
||||||
continue;
|
continue;
|
||||||
@ -279,9 +267,7 @@ void MCObjectSymbolizer::buildRelocationByAddrMap() {
|
|||||||
continue;
|
continue;
|
||||||
for (relocation_iterator RI = SI->begin_relocations(),
|
for (relocation_iterator RI = SI->begin_relocations(),
|
||||||
RE = SI->end_relocations();
|
RE = SI->end_relocations();
|
||||||
RI != RE;
|
RI != RE; ++RI) {
|
||||||
RI.increment(ec)) {
|
|
||||||
if (ec) break;
|
|
||||||
// FIXME: libObject is inconsistent regarding error handling. The
|
// FIXME: libObject is inconsistent regarding error handling. The
|
||||||
// overwhelming majority of methods always return object_error::success,
|
// overwhelming majority of methods always return object_error::success,
|
||||||
// and assert for simple errors.. Here, ELFObjectFile::getRelocationOffset
|
// and assert for simple errors.. Here, ELFObjectFile::getRelocationOffset
|
||||||
|
@ -87,13 +87,10 @@ const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const {
|
|||||||
return Addr;
|
return Addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getSymbolNext(DataRefImpl Ref,
|
void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
|
||||||
SymbolRef &Result) const {
|
|
||||||
const coff_symbol *Symb = toSymb(Ref);
|
const coff_symbol *Symb = toSymb(Ref);
|
||||||
Symb += 1 + Symb->NumberOfAuxSymbols;
|
Symb += 1 + Symb->NumberOfAuxSymbols;
|
||||||
Ref.p = reinterpret_cast<uintptr_t>(Symb);
|
Ref.p = reinterpret_cast<uintptr_t>(Symb);
|
||||||
Result = SymbolRef(Ref, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
|
error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
|
||||||
@ -221,13 +218,10 @@ error_code COFFObjectFile::getSymbolValue(DataRefImpl Ref,
|
|||||||
report_fatal_error("getSymbolValue unimplemented in COFFObjectFile");
|
report_fatal_error("getSymbolValue unimplemented in COFFObjectFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getSectionNext(DataRefImpl Ref,
|
void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
|
||||||
SectionRef &Result) const {
|
|
||||||
const coff_section *Sec = toSec(Ref);
|
const coff_section *Sec = toSec(Ref);
|
||||||
Sec += 1;
|
Sec += 1;
|
||||||
Ref.p = reinterpret_cast<uintptr_t>(Sec);
|
Ref.p = reinterpret_cast<uintptr_t>(Sec);
|
||||||
Result = SectionRef(Ref, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
|
error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
|
||||||
@ -386,11 +380,8 @@ error_code COFFObjectFile::initSymbolTablePtr() {
|
|||||||
|
|
||||||
// Returns the file offset for the given RVA.
|
// Returns the file offset for the given RVA.
|
||||||
error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
|
error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
|
||||||
error_code EC;
|
|
||||||
for (section_iterator I = begin_sections(), E = end_sections(); I != E;
|
for (section_iterator I = begin_sections(), E = end_sections(); I != E;
|
||||||
I.increment(EC)) {
|
++I) {
|
||||||
if (EC)
|
|
||||||
return EC;
|
|
||||||
const coff_section *Section = getCOFFSection(I);
|
const coff_section *Section = getCOFFSection(I);
|
||||||
uint32_t SectionStart = Section->VirtualAddress;
|
uint32_t SectionStart = Section->VirtualAddress;
|
||||||
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
|
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
|
||||||
@ -801,12 +792,9 @@ const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
|
|||||||
return reinterpret_cast<const coff_relocation*>(Rel.p);
|
return reinterpret_cast<const coff_relocation*>(Rel.p);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
|
void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
|
||||||
RelocationRef &Res) const {
|
|
||||||
Rel.p = reinterpret_cast<uintptr_t>(
|
Rel.p = reinterpret_cast<uintptr_t>(
|
||||||
reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
|
reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
|
||||||
Res = RelocationRef(Rel, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
|
error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
|
||||||
@ -932,10 +920,8 @@ operator==(const ImportDirectoryEntryRef &Other) const {
|
|||||||
return ImportTable == Other.ImportTable && Index == Other.Index;
|
return ImportTable == Other.ImportTable && Index == Other.Index;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code
|
void ImportDirectoryEntryRef::moveNext() {
|
||||||
ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const {
|
++Index;
|
||||||
Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code ImportDirectoryEntryRef::
|
error_code ImportDirectoryEntryRef::
|
||||||
@ -967,10 +953,8 @@ operator==(const ExportDirectoryEntryRef &Other) const {
|
|||||||
return ExportTable == Other.ExportTable && Index == Other.Index;
|
return ExportTable == Other.ExportTable && Index == Other.Index;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code
|
void ExportDirectoryEntryRef::moveNext() {
|
||||||
ExportDirectoryEntryRef::getNext(ExportDirectoryEntryRef &Result) const {
|
++Index;
|
||||||
Result = ExportDirectoryEntryRef(ExportTable, Index + 1, OwningObject);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the name of the current export symbol. If the symbol is exported only
|
// Returns the name of the current export symbol. If the symbol is exported only
|
||||||
|
@ -275,18 +275,9 @@ static StringRef parseSegmentOrSectionName(const char *P) {
|
|||||||
|
|
||||||
// Helper to advance a section or symbol iterator multiple increments at a time.
|
// Helper to advance a section or symbol iterator multiple increments at a time.
|
||||||
template<class T>
|
template<class T>
|
||||||
static error_code advance(T &it, size_t Val) {
|
static void advance(T &it, size_t Val) {
|
||||||
error_code ec;
|
while (Val--)
|
||||||
while (Val--) {
|
++it;
|
||||||
it.increment(ec);
|
|
||||||
}
|
|
||||||
return ec;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
static void advanceTo(T &it, size_t Val) {
|
|
||||||
if (error_code ec = advance(it, Val))
|
|
||||||
report_fatal_error(ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned getCPUType(const MachOObjectFile *O) {
|
static unsigned getCPUType(const MachOObjectFile *O) {
|
||||||
@ -305,11 +296,9 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
|||||||
if (IsScattered) {
|
if (IsScattered) {
|
||||||
uint32_t Val = O->getPlainRelocationSymbolNum(RE);
|
uint32_t Val = O->getPlainRelocationSymbolNum(RE);
|
||||||
|
|
||||||
error_code ec;
|
|
||||||
for (symbol_iterator SI = O->begin_symbols(), SE = O->end_symbols();
|
for (symbol_iterator SI = O->begin_symbols(), SE = O->end_symbols();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec) report_fatal_error(ec.message());
|
error_code ec;
|
||||||
|
|
||||||
uint64_t Addr;
|
uint64_t Addr;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
|
|
||||||
@ -325,9 +314,8 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
|||||||
// If we couldn't find a symbol that this relocation refers to, try
|
// If we couldn't find a symbol that this relocation refers to, try
|
||||||
// to find a section beginning instead.
|
// to find a section beginning instead.
|
||||||
for (section_iterator SI = O->begin_sections(), SE = O->end_sections();
|
for (section_iterator SI = O->begin_sections(), SE = O->end_sections();
|
||||||
SI != SE; SI.increment(ec)) {
|
SI != SE; ++SI) {
|
||||||
if (ec) report_fatal_error(ec.message());
|
error_code ec;
|
||||||
|
|
||||||
uint64_t Addr;
|
uint64_t Addr;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
|
|
||||||
@ -350,12 +338,12 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
|||||||
|
|
||||||
if (isExtern) {
|
if (isExtern) {
|
||||||
symbol_iterator SI = O->begin_symbols();
|
symbol_iterator SI = O->begin_symbols();
|
||||||
advanceTo(SI, Val);
|
advance(SI, Val);
|
||||||
SI->getName(S);
|
SI->getName(S);
|
||||||
} else {
|
} else {
|
||||||
section_iterator SI = O->begin_sections();
|
section_iterator SI = O->begin_sections();
|
||||||
// Adjust for the fact that sections are 1-indexed.
|
// Adjust for the fact that sections are 1-indexed.
|
||||||
advanceTo(SI, Val - 1);
|
advance(SI, Val - 1);
|
||||||
SI->getName(S);
|
SI->getName(S);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,14 +442,11 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb,
|
void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
|
||||||
SymbolRef &Res) const {
|
|
||||||
unsigned SymbolTableEntrySize = is64Bit() ?
|
unsigned SymbolTableEntrySize = is64Bit() ?
|
||||||
sizeof(MachO::nlist_64) :
|
sizeof(MachO::nlist_64) :
|
||||||
sizeof(MachO::nlist);
|
sizeof(MachO::nlist);
|
||||||
Symb.p += SymbolTableEntrySize;
|
Symb.p += SymbolTableEntrySize;
|
||||||
Res = SymbolRef(Symb, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSymbolName(DataRefImpl Symb,
|
error_code MachOObjectFile::getSymbolName(DataRefImpl Symb,
|
||||||
@ -545,9 +530,7 @@ error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI,
|
|||||||
}
|
}
|
||||||
// Unfortunately symbols are unsorted so we need to touch all
|
// Unfortunately symbols are unsorted so we need to touch all
|
||||||
// symbols from load command
|
// symbols from load command
|
||||||
error_code ec;
|
for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; ++I) {
|
||||||
for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E;
|
|
||||||
I.increment(ec)) {
|
|
||||||
DataRefImpl DRI = I->getRawDataRefImpl();
|
DataRefImpl DRI = I->getRawDataRefImpl();
|
||||||
Entry = getSymbolTableEntryBase(this, DRI);
|
Entry = getSymbolTableEntryBase(this, DRI);
|
||||||
getSymbolAddress(DRI, Value);
|
getSymbolAddress(DRI, Value);
|
||||||
@ -648,11 +631,8 @@ error_code MachOObjectFile::getSymbolValue(DataRefImpl Symb,
|
|||||||
report_fatal_error("getSymbolValue unimplemented in MachOObjectFile");
|
report_fatal_error("getSymbolValue unimplemented in MachOObjectFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getSectionNext(DataRefImpl Sec,
|
void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const {
|
||||||
SectionRef &Res) const {
|
|
||||||
Sec.d.a++;
|
Sec.d.a++;
|
||||||
Res = SectionRef(Sec, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code
|
error_code
|
||||||
@ -834,13 +814,10 @@ MachOObjectFile::section_rel_end(DataRefImpl Sec) const {
|
|||||||
return relocation_iterator(RelocationRef(Ret, this));
|
return relocation_iterator(RelocationRef(Ret, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel,
|
void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
|
||||||
RelocationRef &Res) const {
|
|
||||||
const MachO::any_relocation_info *P =
|
const MachO::any_relocation_info *P =
|
||||||
reinterpret_cast<const MachO::any_relocation_info *>(Rel.p);
|
reinterpret_cast<const MachO::any_relocation_info *>(Rel.p);
|
||||||
Rel.p = reinterpret_cast<uintptr_t>(P + 1);
|
Rel.p = reinterpret_cast<uintptr_t>(P + 1);
|
||||||
Res = RelocationRef(Rel, this);
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code
|
error_code
|
||||||
|
@ -84,9 +84,7 @@ LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
|
void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) {
|
||||||
error_code ec;
|
++(*unwrap(SI));
|
||||||
unwrap(SI)->increment(ec);
|
|
||||||
if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
|
void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
|
||||||
@ -111,9 +109,7 @@ LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) {
|
void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) {
|
||||||
error_code ec;
|
++(*unwrap(SI));
|
||||||
unwrap(SI)->increment(ec);
|
|
||||||
if (ec) report_fatal_error("LLVMMoveToNextSymbol failed: " + ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SectionRef accessors
|
// SectionRef accessors
|
||||||
@ -169,10 +165,7 @@ LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
|
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
|
||||||
error_code ec;
|
++(*unwrap(SI));
|
||||||
unwrap(SI)->increment(ec);
|
|
||||||
if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " +
|
|
||||||
ec.message());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ public:
|
|||||||
break;
|
break;
|
||||||
case X86_64_RELOC_SUBTRACTOR:
|
case X86_64_RELOC_SUBTRACTOR:
|
||||||
{
|
{
|
||||||
RelocationRef RelNext;
|
Rel.moveNext();
|
||||||
Obj->getRelocationNext(Rel.getRawDataRefImpl(), RelNext);
|
any_relocation_info RENext =
|
||||||
any_relocation_info RENext = Obj->getRelocation(RelNext.getRawDataRefImpl());
|
Obj->getRelocation(Rel.getRawDataRefImpl());
|
||||||
|
|
||||||
// X86_64_SUBTRACTOR must be followed by a relocation of type
|
// X86_64_SUBTRACTOR must be followed by a relocation of type
|
||||||
// X86_64_RELOC_UNSIGNED.
|
// X86_64_RELOC_UNSIGNED.
|
||||||
@ -86,7 +86,7 @@ public:
|
|||||||
|
|
||||||
const MCExpr *LHS = MCSymbolRefExpr::Create(Sym, Ctx);
|
const MCExpr *LHS = MCSymbolRefExpr::Create(Sym, Ctx);
|
||||||
|
|
||||||
symbol_iterator RSymI = RelNext.getSymbol();
|
symbol_iterator RSymI = Rel.getSymbol();
|
||||||
uint64_t RSymAddr;
|
uint64_t RSymAddr;
|
||||||
RSymI->getAddress(RSymAddr);
|
RSymI->getAddress(RSymAddr);
|
||||||
StringRef RSymName;
|
StringRef RSymName;
|
||||||
|
@ -716,10 +716,9 @@ static void writeSymbolTable(
|
|||||||
print32BE(Out, 0);
|
print32BE(Out, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code Err;
|
|
||||||
for (object::symbol_iterator I = Obj->begin_symbols(),
|
for (object::symbol_iterator I = Obj->begin_symbols(),
|
||||||
E = Obj->end_symbols();
|
E = Obj->end_symbols();
|
||||||
I != E; I.increment(Err), failIfError(Err)) {
|
I != E; ++I) {
|
||||||
uint32_t Symflags;
|
uint32_t Symflags;
|
||||||
failIfError(I->getFlags(Symflags));
|
failIfError(I->getFlags(Symflags));
|
||||||
if (Symflags & object::SymbolRef::SF_FormatSpecific)
|
if (Symflags & object::SymbolRef::SF_FormatSpecific)
|
||||||
|
@ -532,16 +532,13 @@ static char getNMTypeChar(ObjectFile *Obj, symbol_iterator I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void dumpSymbolNamesFromObject(ObjectFile *Obj) {
|
static void dumpSymbolNamesFromObject(ObjectFile *Obj) {
|
||||||
error_code EC;
|
|
||||||
symbol_iterator IBegin = Obj->begin_symbols();
|
symbol_iterator IBegin = Obj->begin_symbols();
|
||||||
symbol_iterator IEnd = Obj->end_symbols();
|
symbol_iterator IEnd = Obj->end_symbols();
|
||||||
if (DynamicSyms) {
|
if (DynamicSyms) {
|
||||||
IBegin = Obj->begin_dynamic_symbols();
|
IBegin = Obj->begin_dynamic_symbols();
|
||||||
IEnd = Obj->end_dynamic_symbols();
|
IEnd = Obj->end_dynamic_symbols();
|
||||||
}
|
}
|
||||||
for (symbol_iterator I = IBegin; I != IEnd; I.increment(EC)) {
|
for (symbol_iterator I = IBegin; I != IEnd; ++I) {
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
uint32_t SymFlags;
|
uint32_t SymFlags;
|
||||||
if (error(I->getFlags(SymFlags)))
|
if (error(I->getFlags(SymFlags)))
|
||||||
break;
|
break;
|
||||||
|
@ -241,11 +241,7 @@ static void printImportTables(const COFFObjectFile *Obj) {
|
|||||||
if (I == E)
|
if (I == E)
|
||||||
return;
|
return;
|
||||||
outs() << "The Import Tables:\n";
|
outs() << "The Import Tables:\n";
|
||||||
error_code EC;
|
for (; I != E; I = ++I) {
|
||||||
for (; I != E; I = I.increment(EC)) {
|
|
||||||
if (EC)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const import_directory_table_entry *Dir;
|
const import_directory_table_entry *Dir;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (I->getImportTableEntry(Dir)) return;
|
if (I->getImportTableEntry(Dir)) return;
|
||||||
@ -294,10 +290,7 @@ static void printExportTable(const COFFObjectFile *Obj) {
|
|||||||
outs() << " DLL name: " << DllName << "\n";
|
outs() << " DLL name: " << DllName << "\n";
|
||||||
outs() << " Ordinal base: " << OrdinalBase << "\n";
|
outs() << " Ordinal base: " << OrdinalBase << "\n";
|
||||||
outs() << " Ordinal RVA Name\n";
|
outs() << " Ordinal RVA Name\n";
|
||||||
error_code EC;
|
for (; I != E; I = ++I) {
|
||||||
for (; I != E; I = I.increment(EC)) {
|
|
||||||
if (EC)
|
|
||||||
return;
|
|
||||||
uint32_t Ordinal;
|
uint32_t Ordinal;
|
||||||
if (I->getOrdinal(Ordinal))
|
if (I->getOrdinal(Ordinal))
|
||||||
return;
|
return;
|
||||||
@ -327,12 +320,8 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
|
|||||||
|
|
||||||
const coff_section *Pdata = 0;
|
const coff_section *Pdata = 0;
|
||||||
|
|
||||||
error_code EC;
|
for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections();
|
||||||
for (section_iterator SI = Obj->begin_sections(),
|
SI != SE; ++SI) {
|
||||||
SE = Obj->end_sections();
|
|
||||||
SI != SE; SI.increment(EC)) {
|
|
||||||
if (error(EC)) return;
|
|
||||||
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (error(SI->getName(Name))) continue;
|
if (error(SI->getName(Name))) continue;
|
||||||
|
|
||||||
@ -342,10 +331,8 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
|
|||||||
std::vector<RelocationRef> Rels;
|
std::vector<RelocationRef> Rels;
|
||||||
for (relocation_iterator RI = SI->begin_relocations(),
|
for (relocation_iterator RI = SI->begin_relocations(),
|
||||||
RE = SI->end_relocations();
|
RE = SI->end_relocations();
|
||||||
RI != RE; RI.increment(EC)) {
|
RI != RE; ++RI)
|
||||||
if (error(EC)) break;
|
|
||||||
Rels.push_back(*RI);
|
Rels.push_back(*RI);
|
||||||
}
|
|
||||||
|
|
||||||
// Sort relocations by address.
|
// Sort relocations by address.
|
||||||
std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
|
std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
|
||||||
|
@ -154,13 +154,14 @@ getSectionsAndSymbols(const MachO::mach_header Header,
|
|||||||
std::vector<SymbolRef> &Symbols,
|
std::vector<SymbolRef> &Symbols,
|
||||||
SmallVectorImpl<uint64_t> &FoundFns,
|
SmallVectorImpl<uint64_t> &FoundFns,
|
||||||
uint64_t &BaseSegmentAddress) {
|
uint64_t &BaseSegmentAddress) {
|
||||||
error_code ec;
|
|
||||||
for (symbol_iterator SI = MachOObj->begin_symbols(),
|
for (symbol_iterator SI = MachOObj->begin_symbols(),
|
||||||
SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
|
SE = MachOObj->end_symbols();
|
||||||
|
SI != SE; ++SI)
|
||||||
Symbols.push_back(*SI);
|
Symbols.push_back(*SI);
|
||||||
|
|
||||||
for (section_iterator SI = MachOObj->begin_sections(),
|
for (section_iterator SI = MachOObj->begin_sections(),
|
||||||
SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) {
|
SE = MachOObj->end_sections();
|
||||||
|
SI != SE; ++SI) {
|
||||||
SectionRef SR = *SI;
|
SectionRef SR = *SI;
|
||||||
StringRef SectName;
|
StringRef SectName;
|
||||||
SR.getName(SectName);
|
SR.getName(SectName);
|
||||||
@ -270,9 +271,8 @@ static void DisassembleInputMachO2(StringRef Filename,
|
|||||||
else
|
else
|
||||||
BaseAddress = BaseSegmentAddress;
|
BaseAddress = BaseSegmentAddress;
|
||||||
DiceTable Dices;
|
DiceTable Dices;
|
||||||
error_code ec;
|
|
||||||
for (dice_iterator DI = MachOOF->begin_dices(), DE = MachOOF->end_dices();
|
for (dice_iterator DI = MachOOF->begin_dices(), DE = MachOOF->end_dices();
|
||||||
DI != DE; DI.increment(ec)){
|
DI != DE; ++DI) {
|
||||||
uint32_t Offset;
|
uint32_t Offset;
|
||||||
DI->getOffset(Offset);
|
DI->getOffset(Offset);
|
||||||
Dices.push_back(std::make_pair(BaseAddress + Offset, *DI));
|
Dices.push_back(std::make_pair(BaseAddress + Offset, *DI));
|
||||||
@ -329,9 +329,9 @@ static void DisassembleInputMachO2(StringRef Filename,
|
|||||||
|
|
||||||
// Parse relocations.
|
// Parse relocations.
|
||||||
std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
|
std::vector<std::pair<uint64_t, SymbolRef> > Relocs;
|
||||||
error_code ec;
|
|
||||||
for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
|
for (relocation_iterator RI = Sections[SectIdx].begin_relocations(),
|
||||||
RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) {
|
RE = Sections[SectIdx].end_relocations();
|
||||||
|
RI != RE; ++RI) {
|
||||||
uint64_t RelocOffset, SectionAddress;
|
uint64_t RelocOffset, SectionAddress;
|
||||||
RI->getOffset(RelocOffset);
|
RI->getOffset(RelocOffset);
|
||||||
Sections[SectIdx].getAddress(SectionAddress);
|
Sections[SectIdx].getAddress(SectionAddress);
|
||||||
|
@ -387,18 +387,14 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
error_code EC;
|
error_code EC;
|
||||||
std::map<SectionRef, SmallVector<SectionRef, 1> > SectionRelocMap;
|
std::map<SectionRef, SmallVector<SectionRef, 1> > SectionRelocMap;
|
||||||
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
|
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
|
||||||
I != E; I.increment(EC)) {
|
I != E; ++I) {
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
section_iterator Sec2 = I->getRelocatedSection();
|
section_iterator Sec2 = I->getRelocatedSection();
|
||||||
if (Sec2 != Obj->end_sections())
|
if (Sec2 != Obj->end_sections())
|
||||||
SectionRelocMap[*Sec2].push_back(*I);
|
SectionRelocMap[*Sec2].push_back(*I);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
|
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
|
||||||
I != E; I.increment(EC)) {
|
I != E; ++I) {
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
bool Text;
|
bool Text;
|
||||||
if (error(I->isText(Text)))
|
if (error(I->isText(Text)))
|
||||||
break;
|
break;
|
||||||
@ -412,7 +408,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
// Make a list of all the symbols in this section.
|
// Make a list of all the symbols in this section.
|
||||||
std::vector<std::pair<uint64_t, StringRef> > Symbols;
|
std::vector<std::pair<uint64_t, StringRef> > Symbols;
|
||||||
for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
|
for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
|
||||||
SI != SE; SI.increment(EC)) {
|
SI != SE; ++SI) {
|
||||||
bool contains;
|
bool contains;
|
||||||
if (!error(I->containsSymbol(*SI, contains)) && contains) {
|
if (!error(I->containsSymbol(*SI, contains)) && contains) {
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
@ -441,11 +437,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
RelocSec != E; ++RelocSec) {
|
RelocSec != E; ++RelocSec) {
|
||||||
for (relocation_iterator RI = RelocSec->begin_relocations(),
|
for (relocation_iterator RI = RelocSec->begin_relocations(),
|
||||||
RE = RelocSec->end_relocations();
|
RE = RelocSec->end_relocations();
|
||||||
RI != RE; RI.increment(EC)) {
|
RI != RE; ++RI)
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
Rels.push_back(*RI);
|
Rels.push_back(*RI);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,11 +552,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void PrintRelocations(const ObjectFile *o) {
|
static void PrintRelocations(const ObjectFile *o) {
|
||||||
error_code EC;
|
|
||||||
for (section_iterator si = o->begin_sections(), se = o->end_sections();
|
for (section_iterator si = o->begin_sections(), se = o->end_sections();
|
||||||
si != se; si.increment(EC)) {
|
si != se; ++si) {
|
||||||
if (error(EC))
|
|
||||||
return;
|
|
||||||
if (si->begin_relocations() == si->end_relocations())
|
if (si->begin_relocations() == si->end_relocations())
|
||||||
continue;
|
continue;
|
||||||
StringRef secname;
|
StringRef secname;
|
||||||
@ -571,10 +561,7 @@ static void PrintRelocations(const ObjectFile *o) {
|
|||||||
outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
|
outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
|
||||||
for (relocation_iterator ri = si->begin_relocations(),
|
for (relocation_iterator ri = si->begin_relocations(),
|
||||||
re = si->end_relocations();
|
re = si->end_relocations();
|
||||||
ri != re; ri.increment(EC)) {
|
ri != re; ++ri) {
|
||||||
if (error(EC))
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool hidden;
|
bool hidden;
|
||||||
uint64_t address;
|
uint64_t address;
|
||||||
SmallString<32> relocname;
|
SmallString<32> relocname;
|
||||||
@ -593,12 +580,9 @@ static void PrintRelocations(const ObjectFile *o) {
|
|||||||
static void PrintSectionHeaders(const ObjectFile *o) {
|
static void PrintSectionHeaders(const ObjectFile *o) {
|
||||||
outs() << "Sections:\n"
|
outs() << "Sections:\n"
|
||||||
"Idx Name Size Address Type\n";
|
"Idx Name Size Address Type\n";
|
||||||
error_code EC;
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (section_iterator si = o->begin_sections(), se = o->end_sections();
|
for (section_iterator si = o->begin_sections(), se = o->end_sections();
|
||||||
si != se; si.increment(EC)) {
|
si != se; ++si) {
|
||||||
if (error(EC))
|
|
||||||
return;
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (error(si->getName(Name)))
|
if (error(si->getName(Name)))
|
||||||
return;
|
return;
|
||||||
@ -621,9 +605,7 @@ static void PrintSectionHeaders(const ObjectFile *o) {
|
|||||||
static void PrintSectionContents(const ObjectFile *o) {
|
static void PrintSectionContents(const ObjectFile *o) {
|
||||||
error_code EC;
|
error_code EC;
|
||||||
for (section_iterator si = o->begin_sections(), se = o->end_sections();
|
for (section_iterator si = o->begin_sections(), se = o->end_sections();
|
||||||
si != se; si.increment(EC)) {
|
si != se; ++si) {
|
||||||
if (error(EC))
|
|
||||||
return;
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
StringRef Contents;
|
StringRef Contents;
|
||||||
uint64_t BaseAddr;
|
uint64_t BaseAddr;
|
||||||
@ -714,11 +696,8 @@ static void PrintSymbolTable(const ObjectFile *o) {
|
|||||||
if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o))
|
if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o))
|
||||||
PrintCOFFSymbolTable(coff);
|
PrintCOFFSymbolTable(coff);
|
||||||
else {
|
else {
|
||||||
error_code EC;
|
|
||||||
for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols();
|
for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols();
|
||||||
si != se; si.increment(EC)) {
|
si != se; ++si) {
|
||||||
if (error(EC))
|
|
||||||
return;
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
uint64_t Address;
|
uint64_t Address;
|
||||||
SymbolRef::Type Type;
|
SymbolRef::Type Type;
|
||||||
|
@ -541,23 +541,15 @@ error_code COFFDumper::getSection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void COFFDumper::cacheRelocations() {
|
void COFFDumper::cacheRelocations() {
|
||||||
error_code EC;
|
|
||||||
for (section_iterator SecI = Obj->begin_sections(),
|
for (section_iterator SecI = Obj->begin_sections(),
|
||||||
SecE = Obj->end_sections();
|
SecE = Obj->end_sections();
|
||||||
SecI != SecE; SecI.increment(EC)) {
|
SecI != SecE; ++SecI) {
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
|
|
||||||
const coff_section *Section = Obj->getCOFFSection(SecI);
|
const coff_section *Section = Obj->getCOFFSection(SecI);
|
||||||
|
|
||||||
for (relocation_iterator RelI = SecI->begin_relocations(),
|
for (relocation_iterator RelI = SecI->begin_relocations(),
|
||||||
RelE = SecI->end_relocations();
|
RelE = SecI->end_relocations();
|
||||||
RelI != RelE; RelI.increment(EC)) {
|
RelI != RelE; ++RelI)
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
|
|
||||||
RelocMap[Section].push_back(*RelI);
|
RelocMap[Section].push_back(*RelI);
|
||||||
}
|
|
||||||
|
|
||||||
// Sort relocations by address.
|
// Sort relocations by address.
|
||||||
std::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
|
std::sort(RelocMap[Section].begin(), RelocMap[Section].end(),
|
||||||
@ -824,16 +816,11 @@ void COFFDumper::printCodeViewLineTables(section_iterator SecI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void COFFDumper::printSections() {
|
void COFFDumper::printSections() {
|
||||||
error_code EC;
|
|
||||||
|
|
||||||
ListScope SectionsD(W, "Sections");
|
ListScope SectionsD(W, "Sections");
|
||||||
int SectionNumber = 0;
|
int SectionNumber = 0;
|
||||||
for (section_iterator SecI = Obj->begin_sections(),
|
for (section_iterator SecI = Obj->begin_sections(),
|
||||||
SecE = Obj->end_sections();
|
SecE = Obj->end_sections();
|
||||||
SecI != SecE; SecI.increment(EC)) {
|
SecI != SecE; ++SecI) {
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
|
|
||||||
++SectionNumber;
|
++SectionNumber;
|
||||||
const coff_section *Section = Obj->getCOFFSection(SecI);
|
const coff_section *Section = Obj->getCOFFSection(SecI);
|
||||||
|
|
||||||
@ -860,20 +847,15 @@ void COFFDumper::printSections() {
|
|||||||
ListScope D(W, "Relocations");
|
ListScope D(W, "Relocations");
|
||||||
for (relocation_iterator RelI = SecI->begin_relocations(),
|
for (relocation_iterator RelI = SecI->begin_relocations(),
|
||||||
RelE = SecI->end_relocations();
|
RelE = SecI->end_relocations();
|
||||||
RelI != RelE; RelI.increment(EC)) {
|
RelI != RelE; ++RelI)
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
printRelocation(SecI, RelI);
|
printRelocation(SecI, RelI);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts::SectionSymbols) {
|
if (opts::SectionSymbols) {
|
||||||
ListScope D(W, "Symbols");
|
ListScope D(W, "Symbols");
|
||||||
for (symbol_iterator SymI = Obj->begin_symbols(),
|
for (symbol_iterator SymI = Obj->begin_symbols(),
|
||||||
SymE = Obj->end_symbols();
|
SymE = Obj->end_symbols();
|
||||||
SymI != SymE; SymI.increment(EC)) {
|
SymI != SymE; ++SymI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
bool Contained = false;
|
bool Contained = false;
|
||||||
if (SecI->containsSymbol(*SymI, Contained) || !Contained)
|
if (SecI->containsSymbol(*SymI, Contained) || !Contained)
|
||||||
continue;
|
continue;
|
||||||
@ -897,15 +879,11 @@ void COFFDumper::printSections() {
|
|||||||
void COFFDumper::printRelocations() {
|
void COFFDumper::printRelocations() {
|
||||||
ListScope D(W, "Relocations");
|
ListScope D(W, "Relocations");
|
||||||
|
|
||||||
error_code EC;
|
|
||||||
int SectionNumber = 0;
|
int SectionNumber = 0;
|
||||||
for (section_iterator SecI = Obj->begin_sections(),
|
for (section_iterator SecI = Obj->begin_sections(),
|
||||||
SecE = Obj->end_sections();
|
SecE = Obj->end_sections();
|
||||||
SecI != SecE; SecI.increment(EC)) {
|
SecI != SecE; ++SecI) {
|
||||||
++SectionNumber;
|
++SectionNumber;
|
||||||
if (error(EC))
|
|
||||||
break;
|
|
||||||
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (error(SecI->getName(Name)))
|
if (error(SecI->getName(Name)))
|
||||||
continue;
|
continue;
|
||||||
@ -913,9 +891,7 @@ void COFFDumper::printRelocations() {
|
|||||||
bool PrintedGroup = false;
|
bool PrintedGroup = false;
|
||||||
for (relocation_iterator RelI = SecI->begin_relocations(),
|
for (relocation_iterator RelI = SecI->begin_relocations(),
|
||||||
RelE = SecI->end_relocations();
|
RelE = SecI->end_relocations();
|
||||||
RelI != RelE; RelI.increment(EC)) {
|
RelI != RelE; ++RelI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
if (!PrintedGroup) {
|
if (!PrintedGroup) {
|
||||||
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
|
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
|
||||||
W.indent();
|
W.indent();
|
||||||
@ -963,14 +939,9 @@ void COFFDumper::printRelocation(section_iterator SecI,
|
|||||||
void COFFDumper::printSymbols() {
|
void COFFDumper::printSymbols() {
|
||||||
ListScope Group(W, "Symbols");
|
ListScope Group(W, "Symbols");
|
||||||
|
|
||||||
error_code EC;
|
for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
|
||||||
for (symbol_iterator SymI = Obj->begin_symbols(),
|
SymI != SymE; ++SymI)
|
||||||
SymE = Obj->end_symbols();
|
|
||||||
SymI != SymE; SymI.increment(EC)) {
|
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
printSymbol(SymI);
|
printSymbol(SymI);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void COFFDumper::printDynamicSymbols() {
|
void COFFDumper::printDynamicSymbols() {
|
||||||
@ -1116,12 +1087,9 @@ void COFFDumper::printUnwindInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void COFFDumper::printX64UnwindInfo() {
|
void COFFDumper::printX64UnwindInfo() {
|
||||||
error_code EC;
|
|
||||||
for (section_iterator SecI = Obj->begin_sections(),
|
for (section_iterator SecI = Obj->begin_sections(),
|
||||||
SecE = Obj->end_sections();
|
SecE = Obj->end_sections();
|
||||||
SecI != SecE; SecI.increment(EC)) {
|
SecI != SecE; ++SecI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (error(SecI->getName(Name)))
|
if (error(SecI->getName(Name)))
|
||||||
continue;
|
continue;
|
||||||
|
@ -222,12 +222,9 @@ void MachODumper::printSections(const MachOObjectFile *Obj) {
|
|||||||
ListScope Group(W, "Sections");
|
ListScope Group(W, "Sections");
|
||||||
|
|
||||||
int SectionIndex = -1;
|
int SectionIndex = -1;
|
||||||
error_code EC;
|
|
||||||
for (section_iterator SecI = Obj->begin_sections(),
|
for (section_iterator SecI = Obj->begin_sections(),
|
||||||
SecE = Obj->end_sections();
|
SecE = Obj->end_sections();
|
||||||
SecI != SecE; SecI.increment(EC)) {
|
SecI != SecE; ++SecI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
++SectionIndex;
|
++SectionIndex;
|
||||||
|
|
||||||
MachOSection Section;
|
MachOSection Section;
|
||||||
@ -263,20 +260,15 @@ void MachODumper::printSections(const MachOObjectFile *Obj) {
|
|||||||
ListScope D(W, "Relocations");
|
ListScope D(W, "Relocations");
|
||||||
for (relocation_iterator RelI = SecI->begin_relocations(),
|
for (relocation_iterator RelI = SecI->begin_relocations(),
|
||||||
RelE = SecI->end_relocations();
|
RelE = SecI->end_relocations();
|
||||||
RelI != RelE; RelI.increment(EC)) {
|
RelI != RelE; ++RelI)
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
printRelocation(SecI, RelI);
|
printRelocation(SecI, RelI);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts::SectionSymbols) {
|
if (opts::SectionSymbols) {
|
||||||
ListScope D(W, "Symbols");
|
ListScope D(W, "Symbols");
|
||||||
for (symbol_iterator SymI = Obj->begin_symbols(),
|
for (symbol_iterator SymI = Obj->begin_symbols(),
|
||||||
SymE = Obj->end_symbols();
|
SymE = Obj->end_symbols();
|
||||||
SymI != SymE; SymI.increment(EC)) {
|
SymI != SymE; ++SymI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
bool Contained = false;
|
bool Contained = false;
|
||||||
if (SecI->containsSymbol(*SymI, Contained) || !Contained)
|
if (SecI->containsSymbol(*SymI, Contained) || !Contained)
|
||||||
continue;
|
continue;
|
||||||
@ -300,9 +292,7 @@ void MachODumper::printRelocations() {
|
|||||||
error_code EC;
|
error_code EC;
|
||||||
for (section_iterator SecI = Obj->begin_sections(),
|
for (section_iterator SecI = Obj->begin_sections(),
|
||||||
SecE = Obj->end_sections();
|
SecE = Obj->end_sections();
|
||||||
SecI != SecE; SecI.increment(EC)) {
|
SecI != SecE; ++SecI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
if (error(SecI->getName(Name)))
|
if (error(SecI->getName(Name)))
|
||||||
continue;
|
continue;
|
||||||
@ -310,9 +300,7 @@ void MachODumper::printRelocations() {
|
|||||||
bool PrintedGroup = false;
|
bool PrintedGroup = false;
|
||||||
for (relocation_iterator RelI = SecI->begin_relocations(),
|
for (relocation_iterator RelI = SecI->begin_relocations(),
|
||||||
RelE = SecI->end_relocations();
|
RelE = SecI->end_relocations();
|
||||||
RelI != RelE; RelI.increment(EC)) {
|
RelI != RelE; ++RelI) {
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
if (!PrintedGroup) {
|
if (!PrintedGroup) {
|
||||||
W.startLine() << "Section " << Name << " {\n";
|
W.startLine() << "Section " << Name << " {\n";
|
||||||
W.indent();
|
W.indent();
|
||||||
@ -382,12 +370,8 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
|
|||||||
void MachODumper::printSymbols() {
|
void MachODumper::printSymbols() {
|
||||||
ListScope Group(W, "Symbols");
|
ListScope Group(W, "Symbols");
|
||||||
|
|
||||||
error_code EC;
|
for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols();
|
||||||
for (symbol_iterator SymI = Obj->begin_symbols(),
|
SymI != SymE; ++SymI) {
|
||||||
SymE = Obj->end_symbols();
|
|
||||||
SymI != SymE; SymI.increment(EC)) {
|
|
||||||
if (error(EC)) break;
|
|
||||||
|
|
||||||
printSymbol(SymI);
|
printSymbol(SymI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,11 +151,9 @@ static int printLineInfoForInput() {
|
|||||||
OwningPtr<DIContext> Context(DIContext::getDWARFContext(LoadedObject->getObjectFile()));
|
OwningPtr<DIContext> Context(DIContext::getDWARFContext(LoadedObject->getObjectFile()));
|
||||||
|
|
||||||
// Use symbol info to iterate functions in the object.
|
// Use symbol info to iterate functions in the object.
|
||||||
error_code ec;
|
|
||||||
for (object::symbol_iterator I = LoadedObject->begin_symbols(),
|
for (object::symbol_iterator I = LoadedObject->begin_symbols(),
|
||||||
E = LoadedObject->end_symbols();
|
E = LoadedObject->end_symbols();
|
||||||
I != E && !ec;
|
I != E; ++I) {
|
||||||
I.increment(ec)) {
|
|
||||||
object::SymbolRef::Type SymType;
|
object::SymbolRef::Type SymType;
|
||||||
if (I->getType(SymType)) continue;
|
if (I->getType(SymType)) continue;
|
||||||
if (SymType == object::SymbolRef::ST_Function) {
|
if (SymType == object::SymbolRef::ST_Function) {
|
||||||
|
@ -111,12 +111,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) {
|
|||||||
std::size_t max_name_len = strlen("section");
|
std::size_t max_name_len = strlen("section");
|
||||||
std::size_t max_size_len = strlen("size");
|
std::size_t max_size_len = strlen("size");
|
||||||
std::size_t max_addr_len = strlen("addr");
|
std::size_t max_addr_len = strlen("addr");
|
||||||
error_code ec;
|
for (section_iterator i = o->begin_sections(), e = o->end_sections();
|
||||||
for (section_iterator i = o->begin_sections(),
|
i != e; ++i) {
|
||||||
e = o->end_sections(); i != e;
|
|
||||||
i.increment(ec)) {
|
|
||||||
if (error(ec))
|
|
||||||
return;
|
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
if (error(i->getSize(size)))
|
if (error(i->getSize(size)))
|
||||||
return;
|
return;
|
||||||
@ -154,12 +150,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) {
|
|||||||
<< "%#" << max_addr_len << radix_fmt << "\n";
|
<< "%#" << max_addr_len << radix_fmt << "\n";
|
||||||
|
|
||||||
// Print each section.
|
// Print each section.
|
||||||
for (section_iterator i = o->begin_sections(),
|
for (section_iterator i = o->begin_sections(), e = o->end_sections();
|
||||||
e = o->end_sections(); i != e;
|
i != e; ++i) {
|
||||||
i.increment(ec)) {
|
|
||||||
if (error(ec))
|
|
||||||
return;
|
|
||||||
|
|
||||||
StringRef name;
|
StringRef name;
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
uint64_t addr = 0;
|
uint64_t addr = 0;
|
||||||
@ -189,13 +181,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) {
|
|||||||
uint64_t total_bss = 0;
|
uint64_t total_bss = 0;
|
||||||
|
|
||||||
// Make one pass over the section table to calculate sizes.
|
// Make one pass over the section table to calculate sizes.
|
||||||
error_code ec;
|
for (section_iterator i = o->begin_sections(), e = o->end_sections();
|
||||||
for (section_iterator i = o->begin_sections(),
|
i != e; ++i) {
|
||||||
e = o->end_sections(); i != e;
|
|
||||||
i.increment(ec)) {
|
|
||||||
if (error(ec))
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
bool isText = false;
|
bool isText = false;
|
||||||
bool isData = false;
|
bool isData = false;
|
||||||
|
@ -52,11 +52,8 @@ static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName,
|
|||||||
|
|
||||||
ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
|
ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
|
||||||
: Module(Obj), DebugInfoContext(DICtx) {
|
: Module(Obj), DebugInfoContext(DICtx) {
|
||||||
error_code ec;
|
|
||||||
for (symbol_iterator si = Module->begin_symbols(), se = Module->end_symbols();
|
for (symbol_iterator si = Module->begin_symbols(), se = Module->end_symbols();
|
||||||
si != se; si.increment(ec)) {
|
si != se; ++si) {
|
||||||
if (error(ec))
|
|
||||||
return;
|
|
||||||
SymbolRef::Type SymbolType;
|
SymbolRef::Type SymbolType;
|
||||||
if (error(si->getType(SymbolType)))
|
if (error(si->getType(SymbolType)))
|
||||||
continue;
|
continue;
|
||||||
@ -268,9 +265,8 @@ static bool getGNUDebuglinkContents(const Binary *Bin, std::string &DebugName,
|
|||||||
const ObjectFile *Obj = dyn_cast<ObjectFile>(Bin);
|
const ObjectFile *Obj = dyn_cast<ObjectFile>(Bin);
|
||||||
if (!Obj)
|
if (!Obj)
|
||||||
return false;
|
return false;
|
||||||
error_code EC;
|
|
||||||
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
|
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
|
||||||
I != E; I.increment(EC)) {
|
I != E; ++I) {
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
I->getName(Name);
|
I->getName(Name);
|
||||||
Name = Name.substr(Name.find_first_not_of("._"));
|
Name = Name.substr(Name.find_first_not_of("._"));
|
||||||
|
@ -96,9 +96,9 @@ static int DumpSectionData(const MachOObjectFile &Obj, unsigned Index,
|
|||||||
// Dump the relocation entries.
|
// Dump the relocation entries.
|
||||||
outs() << " ('_relocations', [\n";
|
outs() << " ('_relocations', [\n";
|
||||||
unsigned RelNum = 0;
|
unsigned RelNum = 0;
|
||||||
error_code EC;
|
|
||||||
for (relocation_iterator I = Obj.section_rel_begin(Index),
|
for (relocation_iterator I = Obj.section_rel_begin(Index),
|
||||||
E = Obj.section_rel_end(Index); I != E; I.increment(EC), ++RelNum) {
|
E = Obj.section_rel_end(Index);
|
||||||
|
I != E; ++I, ++RelNum) {
|
||||||
MachO::any_relocation_info RE = Obj.getRelocation(I->getRawDataRefImpl());
|
MachO::any_relocation_info RE = Obj.getRelocation(I->getRawDataRefImpl());
|
||||||
outs() << " # Relocation " << RelNum << "\n";
|
outs() << " # Relocation " << RelNum << "\n";
|
||||||
outs() << " (('word-0', " << format("0x%x", RE.r_word0) << "),\n";
|
outs() << " (('word-0', " << format("0x%x", RE.r_word0) << "),\n";
|
||||||
@ -201,10 +201,9 @@ static int DumpSymtabCommand(const MachOObjectFile &Obj) {
|
|||||||
|
|
||||||
// Dump the symbol table.
|
// Dump the symbol table.
|
||||||
outs() << " ('_symbols', [\n";
|
outs() << " ('_symbols', [\n";
|
||||||
error_code EC;
|
|
||||||
unsigned SymNum = 0;
|
unsigned SymNum = 0;
|
||||||
for (symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;
|
for (symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;
|
||||||
I.increment(EC), ++SymNum) {
|
++I, ++SymNum) {
|
||||||
DataRefImpl DRI = I->getRawDataRefImpl();
|
DataRefImpl DRI = I->getRawDataRefImpl();
|
||||||
if (Obj.is64Bit()) {
|
if (Obj.is64Bit()) {
|
||||||
MachO::nlist_64 STE = Obj.getSymbol64TableEntry(DRI);
|
MachO::nlist_64 STE = Obj.getSymbol64TableEntry(DRI);
|
||||||
|
@ -51,10 +51,8 @@ void COFFDumper::dumpHeader(const object::coff_file_header *Header) {
|
|||||||
|
|
||||||
void COFFDumper::dumpSections(unsigned NumSections) {
|
void COFFDumper::dumpSections(unsigned NumSections) {
|
||||||
std::vector<COFFYAML::Section> &Sections = YAMLObj.Sections;
|
std::vector<COFFYAML::Section> &Sections = YAMLObj.Sections;
|
||||||
error_code ec;
|
|
||||||
for (object::section_iterator iter = Obj.begin_sections();
|
for (object::section_iterator iter = Obj.begin_sections();
|
||||||
iter != Obj.end_sections(); iter.increment(ec)) {
|
iter != Obj.end_sections(); ++iter) {
|
||||||
check(ec);
|
|
||||||
const object::coff_section *Sect = Obj.getCOFFSection(iter);
|
const object::coff_section *Sect = Obj.getCOFFSection(iter);
|
||||||
COFFYAML::Section Sec;
|
COFFYAML::Section Sec;
|
||||||
Sec.Name = Sect->Name; // FIXME: check the null termination!
|
Sec.Name = Sect->Name; // FIXME: check the null termination!
|
||||||
@ -68,7 +66,7 @@ void COFFDumper::dumpSections(unsigned NumSections) {
|
|||||||
|
|
||||||
std::vector<COFFYAML::Relocation> Relocations;
|
std::vector<COFFYAML::Relocation> Relocations;
|
||||||
for (object::relocation_iterator rIter = iter->begin_relocations();
|
for (object::relocation_iterator rIter = iter->begin_relocations();
|
||||||
rIter != iter->end_relocations(); rIter.increment(ec)) {
|
rIter != iter->end_relocations(); ++rIter) {
|
||||||
const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
||||||
COFFYAML::Relocation Rel;
|
COFFYAML::Relocation Rel;
|
||||||
object::symbol_iterator Sym = rIter->getSymbol();
|
object::symbol_iterator Sym = rIter->getSymbol();
|
||||||
@ -83,11 +81,9 @@ void COFFDumper::dumpSections(unsigned NumSections) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void COFFDumper::dumpSymbols(unsigned NumSymbols) {
|
void COFFDumper::dumpSymbols(unsigned NumSymbols) {
|
||||||
error_code ec;
|
|
||||||
std::vector<COFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
|
std::vector<COFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
|
||||||
for (object::symbol_iterator iter = Obj.begin_symbols();
|
for (object::symbol_iterator iter = Obj.begin_symbols();
|
||||||
iter != Obj.end_symbols(); iter.increment(ec)) {
|
iter != Obj.end_symbols(); ++iter) {
|
||||||
check(ec);
|
|
||||||
const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
|
const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
|
||||||
COFFYAML::Symbol Sym;
|
COFFYAML::Symbol Sym;
|
||||||
Obj.getSymbolName(Symbol, Sym.Name);
|
Obj.getSymbolName(Symbol, Sym.Name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user