LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCObjectSymbolizer.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCObjectSymbolizer.h --------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the MCObjectSymbolizer class, an MCSymbolizer that is
11 // backed by an object::ObjectFile.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_MC_MCOBJECTSYMBOLIZER_H
16 #define LLVM_MC_MCOBJECTSYMBOLIZER_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/MC/MCSymbolizer.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include <vector>
22 
23 namespace llvm {
24 
25 class MCExpr;
26 class MCInst;
27 class MCRelocationInfo;
28 class raw_ostream;
29 
30 /// \brief An ObjectFile-backed symbolizer.
32 protected:
34 
35  // Map a load address to the first relocation that applies there. As far as I
36  // know, if there are several relocations at the exact same address, they are
37  // related and the others can be determined from the first that was found in
38  // the relocation table. For instance, on x86-64 mach-o, a SUBTRACTOR
39  // relocation (referencing the minuend symbol) is followed by an UNSIGNED
40  // relocation (referencing the subtrahend symbol).
41  const object::RelocationRef *findRelocationAt(uint64_t Addr);
42  const object::SectionRef *findSectionContaining(uint64_t Addr);
43 
45  const object::ObjectFile *Obj);
46 
47 public:
48  /// \name Overridden MCSymbolizer methods:
49  /// @{
51  int64_t Value, uint64_t Address,
52  bool IsBranch, uint64_t Offset,
53  uint64_t InstSize);
54 
56  int64_t Value, uint64_t Address);
57  /// @}
58 
59  /// \brief Look for an external function symbol at \p Addr.
60  /// (References through the ELF PLT, Mach-O stubs, and similar).
61  /// \returns An MCExpr representing the external symbol, or 0 if not found.
62  virtual StringRef findExternalFunctionAt(uint64_t Addr);
63 
64  /// \brief Create an object symbolizer for \p Obj.
65  static MCObjectSymbolizer *
67  const object::ObjectFile *Obj);
68 
69 private:
71  typedef std::vector<object::SectionRef> SortedSectionList;
72  SortedSectionList SortedSections;
73  AddrToRelocMap AddrToReloc;
74 
75  void buildSectionList();
76  void buildRelocationByAddrMap();
77 };
78 
79 }
80 
81 #endif
const object::SectionRef * findSectionContaining(uint64_t Addr)
MCContext & Ctx
Definition: MCSymbolizer.h:44
MCObjectSymbolizer(MCContext &Ctx, OwningPtr< MCRelocationInfo > &RelInfo, const object::ObjectFile *Obj)
const object::ObjectFile * Obj
const object::RelocationRef * findRelocationAt(uint64_t Addr)
Symbolize and annotate disassembled instructions.
Definition: MCSymbolizer.h:39
OwningPtr< MCRelocationInfo > RelInfo
Definition: MCSymbolizer.h:45
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...
An ObjectFile-backed symbolizer.
static MCObjectSymbolizer * createObjectSymbolizer(MCContext &Ctx, OwningPtr< MCRelocationInfo > &RelInfo, const object::ObjectFile *Obj)
Create an object symbolizer for Obj.
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.
LLVM Value Representation.
Definition: Value.h:66
virtual StringRef findExternalFunctionAt(uint64_t Addr)
Look for an external function symbol at Addr. (References through the ELF PLT, Mach-O stubs...