Home | History | Annotate | Download | only in MC
      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.
     31 class MCObjectSymbolizer : public MCSymbolizer {
     32 protected:
     33   const object::ObjectFile *Obj;
     34 
     35   typedef DenseMap<uint64_t, object::RelocationRef> AddrToRelocMap;
     36   typedef std::vector<object::SectionRef> SortedSectionList;
     37   SortedSectionList SortedSections;
     38 
     39   // Map a load address to the first relocation that applies there. As far as I
     40   // know, if there are several relocations at the exact same address, they are
     41   // related and the others can be determined from the first that was found in
     42   // the relocation table. For instance, on x86-64 mach-o, a SUBTRACTOR
     43   // relocation (referencing the minuend symbol) is followed by an UNSIGNED
     44   // relocation (referencing the subtrahend symbol).
     45   AddrToRelocMap AddrToReloc;
     46 
     47   // Helpers around SortedSections.
     48   SortedSectionList::const_iterator findSectionContaining(uint64_t Addr) const;
     49   void insertSection(object::SectionRef Section);
     50 
     51 
     52   MCObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
     53                      const object::ObjectFile *Obj);
     54 
     55 public:
     56   /// \name Overridden MCSymbolizer methods:
     57   /// @{
     58   bool tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream,
     59                                 int64_t Value,
     60                                 uint64_t Address, bool IsBranch,
     61                                 uint64_t Offset, uint64_t InstSize);
     62 
     63   void tryAddingPcLoadReferenceComment(raw_ostream &cStream,
     64                                        int64_t Value, uint64_t Address);
     65   /// @}
     66 
     67   /// \brief Create an object symbolizer for \p Obj.
     68   static MCObjectSymbolizer *
     69     createObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
     70                            const object::ObjectFile *Obj);
     71 };
     72 
     73 }
     74 
     75 #endif
     76