Replace OwningPtr<T> with std::unique_ptr<T>.
[oota-llvm.git] / include / llvm / MC / MCObjectSymbolizer.h
index 0e3a17b8f7daaf749b6f9f3dce8804bc98c14f95..6f14b561c06ac94e0258398e36cda1a63aba6850 100644 (file)
 #ifndef LLVM_MC_MCOBJECTSYMBOLIZER_H
 #define LLVM_MC_MCOBJECTSYMBOLIZER_H
 
-#include "llvm/ADT/IntervalMap.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/MC/MCSymbolizer.h"
 #include "llvm/Object/ObjectFile.h"
+#include <vector>
 
 namespace llvm {
 
@@ -32,41 +32,49 @@ class MCObjectSymbolizer : public MCSymbolizer {
 protected:
   const object::ObjectFile *Obj;
 
-  typedef DenseMap<uint64_t, object::RelocationRef> AddrToRelocMap;
-  // FIXME: Working around a missing SectionRef operator!= by storing
-  // DataRefImpl.p instead of SectionRef. Feel free to improve!
-  typedef IntervalMap<uint64_t, uintptr_t> AddrToSectionMap;
-
-  AddrToSectionMap::Allocator AddrToSectionAllocator;
-  AddrToSectionMap AddrToSection;
-
   // Map a load address to the first relocation that applies there. As far as I
   // know, if there are several relocations at the exact same address, they are
   // related and the others can be determined from the first that was found in
   // the relocation table. For instance, on x86-64 mach-o, a SUBTRACTOR
   // relocation (referencing the minuend symbol) is followed by an UNSIGNED
   // relocation (referencing the subtrahend symbol).
-  AddrToRelocMap AddrToReloc;
+  const object::RelocationRef *findRelocationAt(uint64_t Addr);
+  const object::SectionRef *findSectionContaining(uint64_t Addr);
 
-  MCObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
+  MCObjectSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &RelInfo,
                      const object::ObjectFile *Obj);
 
 public:
   /// \name Overridden MCSymbolizer methods:
   /// @{
   bool tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream,
-                                int64_t Value,
-                                uint64_t Address, bool IsBranch,
-                                uint64_t Offset, uint64_t InstSize);
+                                int64_t Value, uint64_t Address,
+                                bool IsBranch, uint64_t Offset,
+                                uint64_t InstSize);
 
   void tryAddingPcLoadReferenceComment(raw_ostream &cStream,
                                        int64_t Value, uint64_t Address);
   /// @}
 
+  /// \brief Look for an external function symbol at \p Addr.
+  /// (References through the ELF PLT, Mach-O stubs, and similar).
+  /// \returns An MCExpr representing the external symbol, or 0 if not found.
+  virtual StringRef findExternalFunctionAt(uint64_t Addr);
+
   /// \brief Create an object symbolizer for \p Obj.
   static MCObjectSymbolizer *
-    createObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
-                           const object::ObjectFile *Obj);
+  createObjectSymbolizer(MCContext &Ctx,
+                         std::unique_ptr<MCRelocationInfo> &RelInfo,
+                         const object::ObjectFile *Obj);
+
+private:
+  typedef DenseMap<uint64_t, object::RelocationRef> AddrToRelocMap;
+  typedef std::vector<object::SectionRef> SortedSectionList;
+  SortedSectionList SortedSections;
+  AddrToRelocMap AddrToReloc;
+
+  void buildSectionList();
+  void buildRelocationByAddrMap();
 };
 
 }