1 //===-- llvm/MC/MCObjectSymbolizer.h --------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MCObjectSymbolizer class, an MCSymbolizer that is
11 // backed by an object::ObjectFile.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_MCOBJECTSYMBOLIZER_H
16 #define LLVM_MC_MCOBJECTSYMBOLIZER_H
18 #include "llvm/ADT/IntervalMap.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/MC/MCSymbolizer.h"
21 #include "llvm/Object/ObjectFile.h"
27 class MCRelocationInfo;
30 /// \brief An ObjectFile-backed symbolizer.
31 class MCObjectSymbolizer : public MCSymbolizer {
33 const object::ObjectFile *Obj;
35 typedef DenseMap<uint64_t, object::RelocationRef> AddrToRelocMap;
36 // FIXME: Working around a missing SectionRef operator!= by storing
37 // DataRefImpl.p instead of SectionRef. Feel free to improve!
38 typedef IntervalMap<uint64_t, uintptr_t> AddrToSectionMap;
40 AddrToSectionMap::Allocator AddrToSectionAllocator;
41 AddrToSectionMap AddrToSection;
43 // Map a load address to the first relocation that applies there. As far as I
44 // know, if there are several relocations at the exact same address, they are
45 // related and the others can be determined from the first that was found in
46 // the relocation table. For instance, on x86-64 mach-o, a SUBTRACTOR
47 // relocation (referencing the minuend symbol) is followed by an UNSIGNED
48 // relocation (referencing the subtrahend symbol).
49 AddrToRelocMap AddrToReloc;
51 MCObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
52 const object::ObjectFile *Obj);
55 /// \name Overridden MCSymbolizer methods:
57 bool tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream,
59 uint64_t Address, bool IsBranch,
60 uint64_t Offset, uint64_t InstSize);
62 void tryAddingPcLoadReferenceComment(raw_ostream &cStream,
63 int64_t Value, uint64_t Address);
66 /// \brief Create an object symbolizer for \p Obj.
67 static MCObjectSymbolizer *
68 createObjectSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo,
69 const object::ObjectFile *Obj);