LLVM: lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H

10#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H

11

13

14#define DEBUG_TYPE "dyld"

15

16namespace llvm {

17

20public:

21

23

27

29

31

36 StubMap &Stubs) override {

41 uint32_t RelType = Obj.getAnyRelocationType(RelInfo);

42

43 if (Obj.isRelocationScattered(RelInfo)) {

46 return processSECTDIFFRelocation(SectionID, RelI, Obj,

47 ObjSectionToID);

51 "type: " + Twine(RelType)).str());

52 }

53

54 switch (RelType) {

58 default:

62 " is out of range").str());

63 break;

64 }

65

70 Value = *ValueOrErr;

71 else

72 return ValueOrErr.takeError();

73

74

75

76

77

78

79

80

81

82

83

86

88

89 if (Value.SymbolName)

91 else

93

94 return ++RelI;

95 }

96

99

101 uint8_t *LocalAddress = Section.getAddressWithOffset(RE.Offset);

102

104 uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.Offset);

105 Value -= FinalAddress + 4;

106 }

107

111 break;

117 "Unexpected SECTDIFF relocation value.");

118 Value = SectionABase - SectionBBase + RE.Addend;

120 break;

121 }

122 default:

124 }

125 }

126

131 Name = *NameOrErr;

132 else

134

135 if (Name == "__jump_table")

137 else if (Name == "__pointers")

139 Section, SectionID);

141 }

142

143private:

152

154 uint32_t RelocType = Obj.getAnyRelocationType(RE);

155 bool IsPCRel = Obj.getAnyRelocationPCRel(RE);

156 unsigned Size = Obj.getAnyRelocationLength(RE);

158 uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);

159 unsigned NumBytes = 1 << Size;

161

162 ++RelI;

165

166 uint32_t AddrA = Obj.getScatteredRelocationValue(RE);

168 assert(SAI != Obj.section_end() && "Can't find section for address A");

170 uint64_t SectionAOffset = AddrA - SectionABase;

172 bool IsCode = SectionA.isText();

174 if (auto SectionAIDOrErr =

176 SectionAID = *SectionAIDOrErr;

177 else

178 return SectionAIDOrErr.takeError();

179

180 uint32_t AddrB = Obj.getScatteredRelocationValue(RE2);

182 assert(SBI != Obj.section_end() && "Can't find section for address B");

184 uint64_t SectionBOffset = AddrB - SectionBBase;

187 if (auto SectionBIDOrErr =

189 SectionBID = *SectionBIDOrErr;

190 else

191 return SectionBIDOrErr.takeError();

192

193

194 Addend -= AddrA - AddrB;

195

196 LLVM_DEBUG(dbgs() << "Found SECTDIFF: AddrA: " << AddrA

197 << ", AddrB: " << AddrB << ", Addend: " << Addend

198 << ", SectionA ID: " << SectionAID << ", SectionAOffset: "

199 << SectionAOffset << ", SectionB ID: " << SectionBID

200 << ", SectionBOffset: " << SectionBOffset << "\n");

202 SectionAOffset, SectionBID, SectionBOffset,

203 IsPCRel, Size);

204

206

207 return ++RelI;

208 }

209

210

213 unsigned JTSectionID) {

217 unsigned FirstIndirectSymbol = Sec32.reserved1;

218 unsigned JTEntrySize = Sec32.reserved2;

219 unsigned NumJTEntries = JTSectionSize / JTEntrySize;

221 unsigned JTEntryOffset = 0;

222

223 if (JTSectionSize % JTEntrySize != 0)

225 "a whole number of stubs?");

226

227 for (unsigned i = 0; i < NumJTEntries; ++i) {

228 unsigned SymbolIndex =

229 Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);

232 if (!IndirectSymbolName)

233 return IndirectSymbolName.takeError();

234 uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;

239 JTEntryOffset += JTEntrySize;

240 }

241

243 }

244

245};

246}

247

248#undef DEBUG_TYPE

249

250#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

#define UNIMPLEMENTED_RELOC(RelType)

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

Symbol resolution interface.

RelocationEntry - used to represent relocations internally in the dynamic linker.

unsigned Size

The size of this relocation (MachO specific).

uint32_t RelType

RelType - relocation type.

uint64_t Offset

Offset - offset into the section.

bool IsPCRel

True if this is a PCRel relocation (MachO specific).

int64_t Addend

Addend - the relocation addend encoded in the instruction itself.

unsigned SectionID

SectionID - the section this relocation points to.

Interface for looking up the initializer for a variable name, used by Init::resolveReferences.

std::map< SectionRef, unsigned > ObjSectionToIDMap

std::map< RelocationValueRef, uintptr_t > StubMap

void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)

void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)

Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)

Find Section in LocalSections.

void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const

Endian-aware write.

uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)

Emits long jump instruction to Addr.

uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const

Endian-aware read Read the least significant Size bytes from Src.

uint8_t * getSectionAddress(unsigned SectionID) const

RuntimeDyldMachOCRTPBase(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)

unsigned getMaxStubSize() const override

Definition RuntimeDyldMachOI386.h:28

Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)

Definition RuntimeDyldMachOI386.h:127

Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override

Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...

Definition RuntimeDyldMachOI386.h:33

Align getStubAlignment() override

Definition RuntimeDyldMachOI386.h:30

RuntimeDyldMachOI386(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)

Definition RuntimeDyldMachOI386.h:24

void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override

A object file specific relocation resolver.

Definition RuntimeDyldMachOI386.h:97

uint32_t TargetPtrT

Definition RuntimeDyldMachOI386.h:22

static section_iterator getSectionByAddress(const MachOObjectFile &Obj, uint64_t Addr)

int64_t memcpyAddend(const RelocationEntry &RE) const

This convenience method uses memcpy to extract a contiguous addend (the addend size and offset are ta...

Error populateIndirectSymbolPointersSection(const MachOObjectFile &Obj, const SectionRef &PTSection, unsigned PTSectionID)

void makeValueAddendPCRel(RelocationValueRef &Value, const relocation_iterator &RI, unsigned OffsetToNextPC)

Make the RelocationValueRef addend PC-relative.

RelocationEntry getRelocationEntry(unsigned SectionID, const ObjectFile &BaseTObj, const relocation_iterator &RI) const

Given a relocation_iterator for a non-scattered relocation, construct a RelocationEntry and fill in t...

Expected< RelocationValueRef > getRelocationValueRef(const ObjectFile &BaseTObj, const relocation_iterator &RI, const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID)

Construct a RelocationValueRef representing the relocation target.

Expected< relocation_iterator > processScatteredVANILLA(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID, bool TargetIsLocalThumbFunc=false)

Process a scattered vanilla relocation.

void dumpRelocationToResolve(const RelocationEntry &RE, uint64_t Value) const

Dump information about the relocation entry (RE) and resolved value.

SectionEntry - represents a section emitted into memory by the dynamic linker.

StringRef - Represent a constant reference to a string, i.e.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

LLVM Value Representation.

This class is the base class for all object file types.

uint64_t getOffset() const

DataRefImpl getRawDataRefImpl() const

This is a value type class that represents a single section in the list of sections in the object fil...

DataRefImpl getRawDataRefImpl() const

uint64_t getAddress() const

bool isText() const

Whether this section contains instructions.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ GENERIC_RELOC_LOCAL_SECTDIFF

@ GENERIC_RELOC_PB_LA_PTR

content_iterator< SectionRef > section_iterator

content_iterator< RelocationRef > relocation_iterator

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

Error make_error(ArgTs &&... Args)

Make a Error instance representing failure using the given error info type.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

void consumeError(Error Err)

Consume a Error without doing anything.

This struct is a compact representation of a valid (non-zero power of two) alignment.