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

1

2

3

4

5

6

7

8

9#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOX86_64_H

10#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOX86_64_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

44 return processSubtractRelocation(SectionID, RelI, Obj, ObjSectionToID);

45

46 assert(!Obj.isRelocationScattered(RelInfo) &&

47 "Scattered relocations not supported on X86_64");

48

53 Value = *ValueOrErr;

54 else

55 return ValueOrErr.takeError();

56

57 bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);

58 if (!IsExtern && RE.IsPCRel)

60

61 switch (RelType) {

63 default:

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

68 break;

69 }

70

73 processGOTRelocation(RE, Value, Stubs);

74 else {

76 if (Value.SymbolName)

78 else

80 }

81

82 return ++RelI;

83 }

84

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

89

90

91

93

94

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

96 Value -= FinalAddress + 4;

97 }

98

100 default:

109 break;

114 "Unexpected SUBTRACTOR relocation value.");

115 Value = SectionABase - SectionBBase + RE.Addend;

117 break;

118 }

119 }

120 }

121

126

127private:

134 RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(Value);

136 if (i != Stubs.end()) {

137 Addr = Section.getAddressWithOffset(i->second);

138 } else {

139 Stubs[Value] = Section.getStubOffset();

140 uint8_t *GOTEntry = Section.getAddressWithOffset(Section.getStubOffset());

143 3);

144 if (Value.SymbolName)

146 else

148 Section.advanceStubOffset(8);

149 Addr = GOTEntry;

150 }

154 }

155

156 Expected<relocation_iterator>

158 const MachOObjectFile &BaseObj,

160 const MachOObjectFile &Obj = BaseObj;

161 MachO::any_relocation_info RE =

163

164 unsigned Size = Obj.getAnyRelocationLength(RE);

166 uint8_t *LocalAddress = Sections[SectionID].getAddressWithOffset(Offset);

167 unsigned NumBytes = 1 << Size;

168 int64_t Addend =

170

171 unsigned SectionBID = ~0U;

172 uint64_t SectionBOffset = 0;

173

174 MachO::any_relocation_info RelInfo =

176

178

179 if (AIsExternal) {

180 Expected SubtrahendNameOrErr = RelI->getSymbol()->getName();

181 if (!SubtrahendNameOrErr)

182 return SubtrahendNameOrErr.takeError();

184 SectionBID = SubtrahendI->second.getSectionID();

185 SectionBOffset = SubtrahendI->second.getOffset();

186 } else {

187 SectionRef SecB = Obj.getAnyRelocationSection(RelInfo);

188 bool IsCode = SecB.isText();

189 Expected SectionBIDOrErr =

191 if (!SectionBIDOrErr)

192 return SectionBIDOrErr.takeError();

193 SectionBID = *SectionBIDOrErr;

195 }

196

197 ++RelI;

198

199 unsigned SectionAID = ~0U;

200 uint64_t SectionAOffset = 0;

201

203

205 if (BIsExternal) {

206 Expected MinuendNameOrErr = RelI->getSymbol()->getName();

207 if (!MinuendNameOrErr)

208 return MinuendNameOrErr.takeError();

210 SectionAID = MinuendI->second.getSectionID();

211 SectionAOffset = MinuendI->second.getOffset();

212 } else {

213 SectionRef SecA = Obj.getAnyRelocationSection(RelInfo);

214 bool IsCode = SecA.isText();

215 Expected SectionAIDOrErr =

217 if (!SectionAIDOrErr)

218 return SectionAIDOrErr.takeError();

219 SectionAID = *SectionAIDOrErr;

221 }

222

224 SectionAID, SectionAOffset, SectionBID, SectionBOffset,

225 false, Size);

226

228

229 return ++RelI;

230 }

231

232};

233}

234

235#undef DEBUG_TYPE

236

237#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.

uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const

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

RTDyldSymbolTable GlobalSymbolTable

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

uint64_t TargetPtrT

Definition RuntimeDyldMachOX86_64.h:22

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 RuntimeDyldMachOX86_64.h:33

unsigned getMaxStubSize() const override

Definition RuntimeDyldMachOX86_64.h:28

Align getStubAlignment() override

Definition RuntimeDyldMachOX86_64.h:30

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

A object file specific relocation resolver.

Definition RuntimeDyldMachOX86_64.h:85

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

Definition RuntimeDyldMachOX86_64.h:122

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

Definition RuntimeDyldMachOX86_64.h:24

int64_t memcpyAddend(const RelocationEntry &RE) const

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

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.

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.

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

LLVM Value Representation.

bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const

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

uint64_t getOffset() const

symbol_iterator getSymbol() const

DataRefImpl getRawDataRefImpl() const

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

uint64_t getAddress() const

bool isText() const

Whether this section contains instructions.

Expected< StringRef > getName() const

#define llvm_unreachable(msg)

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

@ X86_64_RELOC_SUBTRACTOR

content_iterator< RelocationRef > relocation_iterator

This is an optimization pass for GlobalISel generic memory operations.

Error make_error(ArgTs &&... Args)

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

constexpr int64_t SignExtend64(uint64_t x)

Sign-extend the number in the bottom B bits of X to a 64-bit integer.

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