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

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFI386_H

14#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFI386_H

15

19

20#define DEBUG_TYPE "dyld"

21

22namespace llvm {

23

25public:

29

33

35

41 StubMap &Stubs) override {

42

44 if (Symbol == Obj.symbol_end())

46

48 if (!TargetNameOrErr)

49 return TargetNameOrErr.takeError();

50 StringRef TargetName = *TargetNameOrErr;

51

52 auto SectionOrErr = Symbol->getSection();

53 if (!SectionOrErr)

55 auto Section = *SectionOrErr;

56 bool IsExtern = Section == Obj.section_end();

57

60

61 unsigned TargetSectionID = -1;

64 TargetSectionID = SectionID;

65 TargetOffset = getDLLImportOffset(SectionID, Stubs, TargetName, true);

67 IsExtern = false;

68 } else if (!IsExtern) {

70 Obj, *Section, Section->isText(), ObjSectionToID))

71 TargetSectionID = *TargetSectionIDOrErr;

72 else

73 return TargetSectionIDOrErr.takeError();

76 }

77

78

83

84 switch (RelType) {

90 break;

91 }

92 default:

93 break;

94 }

95

96#if !defined(NDEBUG)

99#endif

101 << " RelType: " << RelTypeName << " TargetName: "

102 << TargetName << " Addend " << Addend << "\n");

103

104 if (IsExtern) {

107 } else {

108

109 switch (RelType) {

111

112 break;

118 TargetOffset, 0, 0, false, 0);

120 break;

121 }

126 break;

127 }

132 break;

133 }

134 default:

136 }

137 }

138

139 return ++RelI;

140 }

141

145

148

149 break;

151

157 assert(Result <= UINT32_MAX && "relocation overflow");

159 << " RelType: IMAGE_REL_I386_DIR32"

161 << " Value: " << format("0x%08" PRIx32, Result)

162 << '\n');

164 break;

165 }

167

168

171 Sections[0].getLoadAddress();

172 assert(Result <= UINT32_MAX && "relocation overflow");

174 << " RelType: IMAGE_REL_I386_DIR32NB"

176 << " Value: " << format("0x%08" PRIx32, Result)

177 << '\n');

179 break;

180 }

182

186 Result = Result - Section.getLoadAddress() + RE.Addend - 4 - RE.Offset;

187 assert(static_cast<int64_t>(Result) <= INT32_MAX &&

188 "relocation overflow");

189 assert(static_cast<int64_t>(Result) >= INT32_MIN &&

190 "relocation underflow");

192 << " RelType: IMAGE_REL_I386_REL32"

194 << " Value: " << format("0x%08" PRIx32, Result)

195 << '\n');

197 break;

198 }

200

202 "relocation overflow");

204 << " RelType: IMAGE_REL_I386_SECTION Value: "

207 break;

209

211 "relocation overflow");

213 << " RelType: IMAGE_REL_I386_SECREL Value: "

214 << RE.Addend << '\n');

216 break;

217 default:

219 }

220 }

221

223};

224

225}

226

227#endif

228

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

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.

uint32_t RelType

RelType - relocation type.

uint64_t Offset

Offset - offset into the section.

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.

Align getStubAlignment() override

Definition RuntimeDyldCOFFI386.h:34

void registerEHFrames() override

Definition RuntimeDyldCOFFI386.h:222

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

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

Definition RuntimeDyldCOFFI386.h:37

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

Definition RuntimeDyldCOFFI386.h:26

unsigned getMaxStubSize() const override

Definition RuntimeDyldCOFFI386.h:30

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

A object file specific relocation resolver.

Definition RuntimeDyldCOFFI386.h:142

uint64_t getSymbolOffset(const SymbolRef &Sym)

static constexpr StringRef getImportSymbolPrefix()

RuntimeDyldCOFF(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver, unsigned PointerSize, uint32_t PointerReloc)

uint64_t getDLLImportOffset(unsigned SectionID, StubMap &Stubs, StringRef Name, bool SetSectionIDMinus1=false)

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.

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

uintptr_t getObjAddress() const

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

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

bool starts_with(StringRef Prefix) const

Check if this string starts with the given Prefix.

Target - Wrapper for Target specific information.

LLVM Value Representation.

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

uint64_t getOffset() const

symbol_iterator getSymbol() const

void getTypeName(SmallVectorImpl< char > &Result) const

Get a string that represents the type of this relocation.

#define llvm_unreachable(msg)

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

@ IMAGE_REL_I386_ABSOLUTE

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.

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

format_object< Ts... > format(const char *Fmt, const Ts &... Vals)

These are helper functions used to produce formatted output.

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