23 using namespace object;
34 uint64_t StubsIndSymIndex;
49 MCMachObjectSymbolizer::
53 StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) {
60 if (Name ==
"__stubs") {
71 assert(StubSize &&
"Mach-O stub entry size can't be zero!");
74 StubsCount /= StubSize;
79 StringRef MCMachObjectSymbolizer::findExternalFunctionAt(uint64_t Addr) {
85 uint64_t StubIdx = (Addr - StubsStart) / StubSize;
86 if (StubIdx >= StubsCount)
95 for (uint32_t i = 0; i != SymtabIdx; ++i) {
99 assert(SI != MOOF->
end_symbols() &&
"Stub wasn't found in the symbol table!");
100 assert(SymName.
front() ==
'_' &&
"Mach-O symbol doesn't start with '_'!");
109 if (!RelExpr || RelExpr->EvaluateAsAbsolute(Value) ==
false)
112 uint64_t Addr = Value;
113 if (
const SectionRef *S = findSectionContaining(Addr)) {
115 uint64_t SAddr; S->getAddress(SAddr);
116 if (Name ==
"__cstring") {
118 S->getContents(Contents);
119 Contents = Contents.
substr(Addr - SAddr);
120 cStream <<
" ## literal pool for: "
131 :
MCSymbolizer(Ctx, RelInfo), Obj(Obj), SortedSections(), AddrToReloc() {
136 int64_t Value, uint64_t Address,
bool IsBranch,
137 uint64_t Offset, uint64_t InstSize) {
140 if (!ExtFnName.
empty()) {
158 if (IsBranch ==
false)
160 uint64_t UValue = Value;
166 uint64_t SymAddr; SI->getAddress(SymAddr);
167 uint64_t SymSize; SI->getSize(SymSize);
174 if ( SymAddr == UValue ||
175 (SymAddr <= UValue && SymAddr + SymSize > UValue)) {
178 if (SymAddr != UValue) {
191 int64_t Value, uint64_t Address) {
203 return new MCMachObjectSymbolizer(Ctx, RelInfo, MOOF);
215 if (SortedSections.empty())
218 SortedSectionList::iterator
219 EndIt = SortedSections.end(),
220 It = std::lower_bound(SortedSections.begin(), EndIt,
224 uint64_t SAddr; It->getAddress(SAddr);
225 uint64_t SSize; It->getSize(SSize);
226 if (Addr >= SAddr + SSize)
232 if (AddrToReloc.
empty())
233 buildRelocationByAddrMap();
236 if (RI == AddrToReloc.
end())
241 void MCObjectSymbolizer::buildSectionList() {
247 bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec);
248 if (RequiredForExec ==
false)
250 uint64_t SAddr; SI->getAddress(SAddr);
251 uint64_t SSize; SI->getSize(SSize);
252 SortedSectionList::iterator It = std::lower_bound(SortedSections.begin(),
253 SortedSections.end(),
256 if (It != SortedSections.end()) {
257 uint64_t FoundSAddr; It->getAddress(FoundSAddr);
258 if (FoundSAddr < SAddr + SSize)
261 SortedSections.insert(It, *SI);
265 void MCObjectSymbolizer::buildRelocationByAddrMap() {
275 uint64_t StartAddr; RelSecI->getAddress(StartAddr);
276 uint64_t Size; RelSecI->getSize(Size);
277 bool RequiredForExec; RelSecI->isRequiredForExecution(RequiredForExec);
278 if (RequiredForExec ==
false || Size == 0)
281 RE = SI->end_relocations();
296 RI->getOffset(Offset);
299 RI->getAddress(Offset);
302 RI->getOffset(Offset);
306 if (AddrToReloc.
find(Offset) == AddrToReloc.
end())
307 AddrToReloc[Offset] = *RI;
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const object::SectionRef * findSectionContaining(uint64_t Addr)
error_code getSize(uint64_t &Result) const
static MCOperand CreateExpr(const MCExpr *Val)
StringRef substr(size_t Start, size_t N=npos) const
DataRefImpl getRawDataRefImpl() const
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
virtual section_iterator end_sections() const
MCSymbol * GetOrCreateSymbol(StringRef Name)
#define llvm_unreachable(msg)
virtual section_iterator end_sections() const =0
virtual section_iterator begin_sections() const
MCObjectSymbolizer(MCContext &Ctx, OwningPtr< MCRelocationInfo > &RelInfo, const object::ObjectFile *Obj)
static bool SectionStartsBefore(const SectionRef &S, uint64_t Addr)
const ELFFile< ELFT > * getELFFile() const
const object::ObjectFile * Obj
MachO::section_64 getSection64(DataRefImpl DRI) const
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
virtual section_iterator begin_sections() const =0
const object::RelocationRef * findRelocationAt(uint64_t Addr)
Symbolize and annotate disassembled instructions.
MachO::section getSection(DataRefImpl DRI) const
error_code getAddress(uint64_t &Result) const
MachO::dysymtab_command getDysymtabLoadCommand() const
void tryAddingPcLoadReferenceComment(raw_ostream &cStream, int64_t Value, uint64_t Address)
Try to add a comment on the PC-relative load. For instance, in Mach-O, this is used to add annotation...
virtual symbol_iterator end_symbols() const =0
content_iterator & increment(error_code &err)
virtual symbol_iterator begin_symbols() const
virtual const MCExpr * createExprForRelocation(object::RelocationRef Rel)
Create an MCExpr for the relocation Rel.
An ObjectFile-backed symbolizer.
virtual symbol_iterator end_symbols() const
const uint64_t UnknownAddressOrSize
static MCObjectSymbolizer * createObjectSymbolizer(MCContext &Ctx, OwningPtr< MCRelocationInfo > &RelInfo, const object::ObjectFile *Obj)
Create an object symbolizer for Obj.
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
bool tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t InstSize)
Try to add a symbolic operand instead of Value to the MCInst.
size_t find_first_of(char C, size_t From=0) const
char front() const
front - Get the first character in the string.
virtual symbol_iterator begin_symbols() const =0
LLVM Value Representation.
void addOperand(const MCOperand &Op)
static void tryAddingPcLoadReferenceComment(uint64_t Address, int Value, const void *Decoder)
iterator find(const KeyT &Val)
virtual StringRef findExternalFunctionAt(uint64_t Addr)
Look for an external function symbol at Addr. (References through the ELF PLT, Mach-O stubs...
bool empty() const
empty - Check if the string is empty.