LLVM: include/llvm/ExecutionEngine/JITSymbol.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_EXECUTIONENGINE_JITSYMBOL_H

14#define LLVM_EXECUTIONENGINE_JITSYMBOL_H

15

17#include

18#include

19#include

20#include

21#include

22#include

23#include

24#include

25

30

31namespace llvm {

32

35

37

39

40}

41

42

44

45

46

47

48

49

50

52 static_assert(std::is_pointer::value, "T must be a pointer type");

53 uintptr_t IntPtr = static_cast<uintptr_t>(Addr);

54 assert(IntPtr == Addr && "JITTargetAddress value out of range for uintptr_t");

55 return reinterpret_cast<T>(IntPtr);

56}

57

58

59

60

61

63 static_assert(std::is_pointer::value &&

64 std::is_function<std::remove_pointer_t>::value,

65 "T must be a function pointer type");

67}

68

69

73

74

76public:

79

92

93

95

96

98

99

100

102 : TargetFlags(TargetFlags), Flags(Flags) {}

103

104

105 explicit operator bool() const { return Flags != None || TargetFlags != 0; }

106

107

109 return Flags == RHS.Flags && TargetFlags == RHS.TargetFlags;

110 }

111

112

114 Flags &= RHS;

115 return *this;

116 }

117

118

120 Flags |= RHS;

121 return *this;

122 }

123

124

128

129

131 return (Flags & Weak) == Weak;

132 }

133

134

138

139

143

144

148

149

151

152

153

154

155

156

157

158

159

160

161

166

167

171

172

174

175

177

178

179

181

182

183

185

186

187

190

191private:

193 FlagNames Flags = None;

194};

195

199 Tmp &= RHS;

200 return Tmp;

201}

202

206 Tmp |= RHS;

207 return Tmp;

208}

209

210

211

213public:

215

220

222

225

226private:

228};

229

230

232public:

234

235

237

238

240 : Address(Address), Flags(Flags) {}

241

242

243 template

248

249

250 explicit operator bool() const { return Address != 0; }

251

252

254

255

257

258

260

261private:

264};

265

266

268public:

270

271

272

275

276

277

280

281

284

285

288

289

290

291

292

293

294

295

296

297

300

303

306 if (Flags.hasError())

308 else

310 }

311

313 GetAddress = std::move(Other.GetAddress);

314 Flags = std::move(Other.Flags);

315 if (Flags.hasError())

317 else

319 return *this;

320 }

321

323 if (Flags.hasError())

324 Err.~Error();

325 else

327 }

328

329

330 explicit operator bool() const {

331 return !Flags.hasError() && (CachedAddr || GetAddress);

332 }

333

334

336 if (Flags.hasError())

337 return std::move(Err);

339 }

340

341

342

344 assert(!Flags.hasError() && "getAddress called on error value");

345 if (GetAddress) {

346 if (auto CachedAddrOrErr = GetAddress()) {

347 GetAddress = nullptr;

350 } else

351 return CachedAddrOrErr.takeError();

352 }

354 }

355

357

358private:

360 union {

363 };

365};

366

367

368

369

370

371

372

374public:

376 using LookupResult = std::map<StringRef, JITEvaluatedSymbol>;

378

380

381

382

383

384

385

388

389

390

391

394

395

397

398private:

399 virtual void anchor();

400};

401

402

404public:

405

406

407

409

410

411

413

414

415

416

417

418

419

420

421

422

423

424

425

427

428

429

430

431

432

433

435

436private:

437 void anchor() override;

438};

439

440}

441

442#endif

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

static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)

A Lookup helper functions.

ARM-specific JIT symbol flags.

Definition JITSymbol.h:212

FlagNames

Definition JITSymbol.h:216

@ Thumb

Definition JITSymbol.h:218

@ None

Definition JITSymbol.h:217

static LLVM_ABI ARMJITSymbolFlags fromObjectSymbol(const object::SymbolRef &Symbol)

ARMJITSymbolFlags()=default

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.

Function and variable summary information to aid decisions and implementation of importing.

Represents a symbol that has been evaluated to an address already.

Definition JITSymbol.h:231

JITSymbolFlags getFlags() const

Return the flags for this symbol.

Definition JITSymbol.h:256

JITTargetAddress getAddress() const

Return the address of this symbol.

Definition JITSymbol.h:253

JITEvaluatedSymbol(JITTargetAddress Address, JITSymbolFlags Flags)

Create a symbol for the given address and flags.

Definition JITSymbol.h:239

JITEvaluatedSymbol()=default

void setFlags(JITSymbolFlags Flags)

Set the flags for this symbol.

Definition JITSymbol.h:259

static JITEvaluatedSymbol fromPointer(T *P, JITSymbolFlags Flags=JITSymbolFlags::Exported)

Create a symbol from the given pointer with the given flags.

Definition JITSymbol.h:245

JITEvaluatedSymbol(std::nullptr_t)

Create a 'null' symbol.

Definition JITSymbol.h:236

Flags for symbols in the JIT.

Definition JITSymbol.h:75

JITSymbolFlags(FlagNames Flags)

Construct a JITSymbolFlags instance from the given flags.

Definition JITSymbol.h:97

bool hasError() const

Return true if there was an error retrieving this symbol.

Definition JITSymbol.h:125

TargetFlagsType & getTargetFlags()

Return a reference to the target-specific flags.

Definition JITSymbol.h:173

const TargetFlagsType & getTargetFlags() const

Return a reference to the target-specific flags.

Definition JITSymbol.h:176

UnderlyingType getRawFlagsValue() const

Get the underlying flags value as an integer.

Definition JITSymbol.h:168

JITSymbolFlags & operator|=(const FlagNames &RHS)

Bitwise OR-assignment for FlagNames.

Definition JITSymbol.h:119

JITSymbolFlags & operator&=(const FlagNames &RHS)

Bitwise AND-assignment for FlagNames.

Definition JITSymbol.h:113

bool isStrong() const

Returns true if the symbol isn't weak or common.

Definition JITSymbol.h:140

bool isExported() const

Returns true if the Exported flag is set.

Definition JITSymbol.h:145

bool hasMaterializationSideEffectsOnly() const

Returns true if this symbol is a materialization-side-effects-only symbol.

Definition JITSymbol.h:162

uint8_t TargetFlagsType

Definition JITSymbol.h:78

bool isCallable() const

Returns true if the given symbol is known to be callable.

Definition JITSymbol.h:150

static LLVM_ABI Expected< JITSymbolFlags > fromObjectSymbol(const object::SymbolRef &Symbol)

Construct a JITSymbolFlags value based on the flags of the given libobject symbol.

JITSymbolFlags()=default

Default-construct a JITSymbolFlags instance.

static LLVM_ABI JITSymbolFlags fromSummary(GlobalValueSummary *S)

Construct a JITSymbolFlags value based on the flags of the given global value summary.

bool isCommon() const

Returns true if the Common flag is set.

Definition JITSymbol.h:135

static LLVM_ABI JITSymbolFlags fromGlobalValue(const GlobalValue &GV)

Construct a JITSymbolFlags value based on the flags of the given global value.

bool operator==(const JITSymbolFlags &RHS) const

Compare for equality.

Definition JITSymbol.h:108

FlagNames

Definition JITSymbol.h:80

@ HasError

Definition JITSymbol.h:82

@ Common

Definition JITSymbol.h:84

@ Callable

Definition JITSymbol.h:87

@ Absolute

Definition JITSymbol.h:85

@ MaterializationSideEffectsOnly

Definition JITSymbol.h:88

@ Weak

Definition JITSymbol.h:83

@ None

Definition JITSymbol.h:81

@ Exported

Definition JITSymbol.h:86

@ LLVM_MARK_AS_BITMASK_ENUM

Definition JITSymbol.h:89

bool isWeak() const

Returns true if the Weak flag is set.

Definition JITSymbol.h:130

uint8_t UnderlyingType

Definition JITSymbol.h:77

JITSymbolFlags(FlagNames Flags, TargetFlagsType TargetFlags)

Construct a JITSymbolFlags instance from the given flags and target flags.

Definition JITSymbol.h:101

Symbol resolution interface.

Definition JITSymbol.h:373

unique_function< void(Expected< LookupResult >)> OnResolvedFunction

Definition JITSymbol.h:377

virtual void lookup(const LookupSet &Symbols, OnResolvedFunction OnResolved)=0

Returns the fully resolved address and flags for each of the given symbols.

virtual ~JITSymbolResolver()=default

virtual bool allowsZeroSymbols()

Specify if this resolver can return valid symbols with zero value.

Definition JITSymbol.h:396

std::map< StringRef, JITEvaluatedSymbol > LookupResult

Definition JITSymbol.h:376

std::set< StringRef > LookupSet

Definition JITSymbol.h:375

virtual Expected< LookupSet > getResponsibilitySet(const LookupSet &Symbols)=0

Returns the subset of the given symbols that should be materialized by the caller.

Represents a symbol in the JIT.

Definition JITSymbol.h:267

JITSymbol(JITTargetAddress Addr, JITSymbolFlags Flags)

Create a symbol for a definition with a known address.

Definition JITSymbol.h:282

JITSymbol & operator=(JITSymbol &&Other)

Definition JITSymbol.h:312

JITTargetAddress CachedAddr

Definition JITSymbol.h:361

Error takeError()

Move the error field value out of this JITSymbol.

Definition JITSymbol.h:335

JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)

Create a symbol for a definition that doesn't have a known address yet.

Definition JITSymbol.h:298

Error Err

Definition JITSymbol.h:362

Expected< JITTargetAddress > getAddress()

Get the address of the symbol in the target address space.

Definition JITSymbol.h:343

JITSymbol(JITSymbol &&Other)

Definition JITSymbol.h:304

~JITSymbol()

Definition JITSymbol.h:322

JITSymbol & operator=(const JITSymbol &)=delete

JITSymbol(Error Err)

Create a JITSymbol representing an error in the symbol lookup process (e.g.

Definition JITSymbol.h:278

JITSymbol(const JITSymbol &)=delete

JITSymbol(JITEvaluatedSymbol Sym)

Construct a JITSymbol from a JITEvaluatedSymbol.

Definition JITSymbol.h:286

unique_function< Expected< JITTargetAddress >()> GetAddressFtor

Definition JITSymbol.h:269

JITSymbolFlags getFlags() const

Definition JITSymbol.h:356

JITSymbol(std::nullptr_t)

Create a 'null' symbol, used to represent a "symbol not found" result from a successful (non-erroneou...

Definition JITSymbol.h:273

Legacy symbol resolution interface.

Definition JITSymbol.h:403

virtual JITSymbol findSymbol(const std::string &Name)=0

This method returns the address of the specified function or variable.

Expected< LookupSet > getResponsibilitySet(const LookupSet &Symbols) final

Performs flags lookup by calling findSymbolInLogicalDylib and returning the flags value for that symb...

virtual JITSymbol findSymbolInLogicalDylib(const std::string &Name)=0

This method returns the address of the specified symbol if it exists within the logical dynamic libra...

This is a value type class that represents a single symbol in the list of symbols in the object file.

unique_function is a type-erasing functor similar to std::function.

This is an optimization pass for GlobalISel generic memory operations.

APInt operator&(APInt a, const APInt &b)

T jitTargetAddressToFunction(JITTargetAddress Addr)

Convert a JITTargetAddress to a callable function pointer.

Definition JITSymbol.h:62

T jitTargetAddressToPointer(JITTargetAddress Addr)

Convert a JITTargetAddress to a pointer.

Definition JITSymbol.h:51

uint64_t JITTargetAddress

Represents an address in the target process's address space.

Definition JITSymbol.h:43

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

JITTargetAddress pointerToJITTargetAddress(T *Ptr)

Convert a pointer to a JITTargetAddress.

Definition JITSymbol.h:70

APInt operator|(APInt a, const APInt &b)

uint8_t TargetFlagsType

Holds target-specific properties for a symbol.

Implement std::hash so that hash_code can be used in STL containers.