~ubuntu-branches/ubuntu/quantal/llvm-3.1/quantal

« back to all changes in this revision

Viewing changes to lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-04-01 23:45:03 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120401234503-c04qxrk7s9my53uy
Tags: 3.1~svn153852-1
New snapshot release

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
namespace llvm {
27
27
class RuntimeDyldMachO : public RuntimeDyldImpl {
28
 
 
29
 
  // For each symbol, keep a list of relocations based on it. Anytime
30
 
  // its address is reassigned (the JIT re-compiled the function, e.g.),
31
 
  // the relocations get re-resolved.
32
 
  // The symbol (or section) the relocation is sourced from is the Key
33
 
  // in the relocation list where it's stored.
34
 
  struct RelocationEntry {
35
 
    unsigned    SectionID;  // Section the relocation is contained in.
36
 
    uint64_t    Offset;     // Offset into the section for the relocation.
37
 
    uint32_t    Data;       // Second word of the raw macho relocation entry.
38
 
    int64_t     Addend;     // Addend encoded in the instruction itself, if any,
39
 
                            // plus the offset into the source section for
40
 
                            // the symbol once the relocation is resolvable.
41
 
 
42
 
    RelocationEntry(unsigned id, uint64_t offset, uint32_t data, int64_t addend)
43
 
      : SectionID(id), Offset(offset), Data(data), Addend(addend) {}
44
 
  };
45
 
  typedef SmallVector<RelocationEntry, 4> RelocationList;
46
 
 
47
 
  // For each section, keep a list of referrers in that section that are clients
48
 
  // of relocations in other sections.  Whenever a relocation gets created,
49
 
  // create a corresponding referrer.  Whenever relocations are re-resolved,
50
 
  // re-resolve the referrers' relocations as well.
51
 
  struct Referrer {
52
 
    unsigned    SectionID;  // Section whose RelocationList contains the relocation.
53
 
    uint32_t    Index;      // Index of the RelocatonEntry in that RelocationList.
54
 
 
55
 
    Referrer(unsigned id, uint32_t index)
56
 
      : SectionID(id), Index(index) {}
57
 
  };
58
 
  typedef SmallVector<Referrer, 4> ReferrerList;
59
 
 
60
 
  // Relocations to sections already loaded. Indexed by SectionID which is the
61
 
  // source of the address. The target where the address will be writen is
62
 
  // SectionID/Offset in the relocation itself.
63
 
  IndexedMap<RelocationList> Relocations;
64
 
  // Referrers corresponding to Relocations.
65
 
  IndexedMap<ReferrerList> Referrers;
66
 
  // Relocations to symbols that are not yet resolved. Must be external
67
 
  // relocations by definition. Indexed by symbol name.
68
 
  StringMap<RelocationList> UnresolvedRelocations;
69
 
 
70
 
  bool resolveRelocation(uint8_t *LocalAddress,
71
 
                         uint64_t FinalAddress,
72
 
                         uint64_t Value,
73
 
                         bool isPCRel,
74
 
                         unsigned Type,
75
 
                         unsigned Size,
76
 
                         int64_t Addend);
 
28
protected:
77
29
  bool resolveI386Relocation(uint8_t *LocalAddress,
78
30
                             uint64_t FinalAddress,
79
31
                             uint64_t Value,
96
48
                            unsigned Size,
97
49
                            int64_t Addend);
98
50
 
99
 
  bool loadSegment32(const MachOObject *Obj,
100
 
                     const MachOObject::LoadCommandInfo *SegmentLCI,
101
 
                     const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC);
102
 
  bool loadSegment64(const MachOObject *Obj,
103
 
                     const MachOObject::LoadCommandInfo *SegmentLCI,
104
 
                     const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC);
105
 
  bool processSymbols32(const MachOObject *Obj,
106
 
                      SmallVectorImpl<unsigned> &SectionMap,
107
 
                      SmallVectorImpl<StringRef> &SymbolNames,
108
 
                      const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC);
109
 
  bool processSymbols64(const MachOObject *Obj,
110
 
                      SmallVectorImpl<unsigned> &SectionMap,
111
 
                      SmallVectorImpl<StringRef> &SymbolNames,
112
 
                      const InMemoryStruct<macho::SymtabLoadCommand> &SymtabLC);
113
 
 
114
 
  void resolveSymbol(StringRef Name);
 
51
  virtual void processRelocationRef(const ObjRelocationInfo &Rel,
 
52
                                    const ObjectFile &Obj,
 
53
                                    ObjSectionToIDMap &ObjSectionToID,
 
54
                                    LocalSymbolMap &Symbols, StubMap &Stubs);
115
55
 
116
56
public:
 
57
  virtual void resolveRelocation(uint8_t *LocalAddress,
 
58
                                 uint64_t FinalAddress,
 
59
                                 uint64_t Value,
 
60
                                 uint32_t Type,
 
61
                                 int64_t Addend);
 
62
                                 
117
63
  RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
118
64
 
119
 
  bool loadObject(MemoryBuffer *InputBuffer);
120
 
 
121
 
  void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
122
 
 
123
 
  static bool isKnownFormat(const MemoryBuffer *InputBuffer);
124
 
 
125
 
  bool isCompatibleFormat(const MemoryBuffer *InputBuffer) const {
126
 
    return isKnownFormat(InputBuffer);
127
 
  }
 
65
  bool isCompatibleFormat(const MemoryBuffer *InputBuffer) const;
128
66
};
129
67
 
130
68
} // end namespace llvm