LLVM  16.0.0git
COFFPlatform.cpp
Go to the documentation of this file.
1 //===------- COFFPlatform.cpp - Utilities for executing COFF in Orc -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
13 
14 #include "llvm/Object/COFF.h"
15 
17 
19 
20 #define DEBUG_TYPE "orc"
21 
22 using namespace llvm;
23 using namespace llvm::orc;
24 using namespace llvm::orc::shared;
25 
26 namespace llvm {
27 namespace orc {
28 namespace shared {
29 
39 
40 } // namespace shared
41 } // namespace orc
42 } // namespace llvm
43 namespace {
44 
45 class COFFHeaderMaterializationUnit : public MaterializationUnit {
46 public:
47  COFFHeaderMaterializationUnit(COFFPlatform &CP,
48  const SymbolStringPtr &HeaderStartSymbol)
49  : MaterializationUnit(createHeaderInterface(CP, HeaderStartSymbol)),
50  CP(CP) {}
51 
52  StringRef getName() const override { return "COFFHeaderMU"; }
53 
54  void materialize(std::unique_ptr<MaterializationResponsibility> R) override {
55  unsigned PointerSize;
57  const auto &TT =
58  CP.getExecutionSession().getExecutorProcessControl().getTargetTriple();
59 
60  switch (TT.getArch()) {
61  case Triple::x86_64:
62  PointerSize = 8;
64  break;
65  default:
66  llvm_unreachable("Unrecognized architecture");
67  }
68 
69  auto G = std::make_unique<jitlink::LinkGraph>(
70  "<COFFHeaderMU>", TT, PointerSize, Endianness,
72  auto &HeaderSection = G->createSection("__header", MemProt::Read);
73  auto &HeaderBlock = createHeaderBlock(*G, HeaderSection);
74 
75  // Init symbol is __ImageBase symbol.
76  auto &ImageBaseSymbol = G->addDefinedSymbol(
77  HeaderBlock, 0, *R->getInitializerSymbol(), HeaderBlock.getSize(),
79 
80  addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
81 
82  CP.getObjectLinkingLayer().emit(std::move(R), std::move(G));
83  }
84 
85  void discard(const JITDylib &JD, const SymbolStringPtr &Sym) override {}
86 
87 private:
88  struct HeaderSymbol {
89  const char *Name;
91  };
92 
93  struct NTHeader {
95  object::coff_file_header FileHeader;
96  struct PEHeader {
99  } OptionalHeader;
100  };
101 
102  struct HeaderBlockContent {
103  object::dos_header DOSHeader;
104  COFFHeaderMaterializationUnit::NTHeader NTHeader;
105  };
106 
107  static jitlink::Block &createHeaderBlock(jitlink::LinkGraph &G,
108  jitlink::Section &HeaderSection) {
109  HeaderBlockContent Hdr = {};
110 
111  // Set up magic
112  Hdr.DOSHeader.Magic[0] = 'M';
113  Hdr.DOSHeader.Magic[1] = 'Z';
114  Hdr.DOSHeader.AddressOfNewExeHeader =
115  offsetof(HeaderBlockContent, NTHeader);
116  uint32_t PEMagic = *reinterpret_cast<const uint32_t *>(COFF::PEMagic);
117  Hdr.NTHeader.PEMagic = PEMagic;
118  Hdr.NTHeader.OptionalHeader.Header.Magic = COFF::PE32Header::PE32_PLUS;
119 
120  switch (G.getTargetTriple().getArch()) {
121  case Triple::x86_64:
122  Hdr.NTHeader.FileHeader.Machine = COFF::IMAGE_FILE_MACHINE_AMD64;
123  break;
124  default:
125  llvm_unreachable("Unrecognized architecture");
126  }
127 
128  auto HeaderContent = G.allocateString(
129  StringRef(reinterpret_cast<const char *>(&Hdr), sizeof(Hdr)));
130 
131  return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
132  0);
133  }
134 
135  static void addImageBaseRelocationEdge(jitlink::Block &B,
136  jitlink::Symbol &ImageBase) {
137  auto ImageBaseOffset = offsetof(HeaderBlockContent, NTHeader) +
138  offsetof(NTHeader, OptionalHeader) +
139  offsetof(object::pe32plus_header, ImageBase);
140  B.addEdge(jitlink::x86_64::Pointer64, ImageBaseOffset, ImageBase, 0);
141  }
142 
144  createHeaderInterface(COFFPlatform &MOP,
145  const SymbolStringPtr &HeaderStartSymbol) {
146  SymbolFlagsMap HeaderSymbolFlags;
147 
148  HeaderSymbolFlags[HeaderStartSymbol] = JITSymbolFlags::Exported;
149 
150  return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
151  HeaderStartSymbol);
152  }
153 
154  COFFPlatform &CP;
155 };
156 
157 } // end anonymous namespace
158 
159 namespace llvm {
160 namespace orc {
161 
164  JITDylib &PlatformJD, const char *OrcRuntimePath,
165  LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime,
166  const char *VCRuntimePath,
167  Optional<SymbolAliasMap> RuntimeAliases) {
168  auto &EPC = ES.getExecutorProcessControl();
169 
170  // If the target is not supported then bail out immediately.
171  if (!supportedTarget(EPC.getTargetTriple()))
172  return make_error<StringError>("Unsupported COFFPlatform triple: " +
173  EPC.getTargetTriple().str(),
175 
176  // Create default aliases if the caller didn't supply any.
177  if (!RuntimeAliases)
178  RuntimeAliases = standardPlatformAliases(ES);
179 
180  // Define the aliases.
181  if (auto Err = PlatformJD.define(symbolAliases(std::move(*RuntimeAliases))))
182  return std::move(Err);
183 
184  auto &HostFuncJD = ES.createBareJITDylib("$<PlatformRuntimeHostFuncJD>");
185 
186  // Add JIT-dispatch function support symbols.
187  if (auto Err = HostFuncJD.define(absoluteSymbols(
188  {{ES.intern("__orc_rt_jit_dispatch"),
189  {EPC.getJITDispatchInfo().JITDispatchFunction.getValue(),
191  {ES.intern("__orc_rt_jit_dispatch_ctx"),
192  {EPC.getJITDispatchInfo().JITDispatchContext.getValue(),
194  return std::move(Err);
195 
196  PlatformJD.addToLinkOrder(HostFuncJD);
197 
198  // Create the instance.
199  Error Err = Error::success();
200  auto P = std::unique_ptr<COFFPlatform>(new COFFPlatform(
201  ES, ObjLinkingLayer, PlatformJD, OrcRuntimePath,
202  std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath, Err));
203  if (Err)
204  return std::move(Err);
205  return std::move(P);
206 }
207 
208 Expected<MemoryBufferRef> COFFPlatform::getPerJDObjectFile() {
209  auto PerJDObj = OrcRuntimeArchive->findSym("__orc_rt_coff_per_jd_marker");
210  if (!PerJDObj)
211  return PerJDObj.takeError();
212 
213  if (!*PerJDObj)
214  return make_error<StringError>("Could not find per jd object file",
216 
217  auto Buffer = (*PerJDObj)->getAsBinary();
218  if (!Buffer)
219  return Buffer.takeError();
220 
221  return (*Buffer)->getMemoryBufferRef();
222 }
223 
224 static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases,
225  ArrayRef<std::pair<const char *, const char *>> AL) {
226  for (auto &KV : AL) {
227  auto AliasName = ES.intern(KV.first);
228  assert(!Aliases.count(AliasName) && "Duplicate symbol name in alias map");
229  Aliases[std::move(AliasName)] = {ES.intern(KV.second),
231  }
232 }
233 
235  if (auto Err = JD.define(std::make_unique<COFFHeaderMaterializationUnit>(
236  *this, COFFHeaderStartSymbol)))
237  return Err;
238 
239  if (auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
240  return Err;
241 
242  // Define the CXX aliases.
243  SymbolAliasMap CXXAliases;
244  addAliases(ES, CXXAliases, requiredCXXAliases());
245  if (auto Err = JD.define(symbolAliases(std::move(CXXAliases))))
246  return Err;
247 
248  auto PerJDObj = getPerJDObjectFile();
249  if (!PerJDObj)
250  return PerJDObj.takeError();
251 
252  auto I = getObjectFileInterface(ES, *PerJDObj);
253  if (!I)
254  return I.takeError();
255 
256  if (auto Err = ObjLinkingLayer.add(
257  JD, MemoryBuffer::getMemBuffer(*PerJDObj, false), std::move(*I)))
258  return Err;
259 
260  if (!Bootstrapping) {
261  auto ImportedLibs = StaticVCRuntime
262  ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
263  : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
264  if (!ImportedLibs)
265  return ImportedLibs.takeError();
266  for (auto &Lib : *ImportedLibs)
267  if (auto Err = LoadDynLibrary(JD, Lib))
268  return Err;
269  if (StaticVCRuntime)
270  if (auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
271  return Err;
272  }
273 
274  JD.addGenerator(DLLImportDefinitionGenerator::Create(ES, ObjLinkingLayer));
275  return Error::success();
276 }
277 
279  std::lock_guard<std::mutex> Lock(PlatformMutex);
280  auto I = JITDylibToHeaderAddr.find(&JD);
281  if (I != JITDylibToHeaderAddr.end()) {
282  assert(HeaderAddrToJITDylib.count(I->second) &&
283  "HeaderAddrToJITDylib missing entry");
284  HeaderAddrToJITDylib.erase(I->second);
285  JITDylibToHeaderAddr.erase(I);
286  }
287  return Error::success();
288 }
289 
291  const MaterializationUnit &MU) {
292  auto &JD = RT.getJITDylib();
293  const auto &InitSym = MU.getInitializerSymbol();
294  if (!InitSym)
295  return Error::success();
296 
297  RegisteredInitSymbols[&JD].add(InitSym,
299 
300  LLVM_DEBUG({
301  dbgs() << "COFFPlatform: Registered init symbol " << *InitSym << " for MU "
302  << MU.getName() << "\n";
303  });
304  return Error::success();
305 }
306 
308  llvm_unreachable("Not supported yet");
309 }
310 
312  SymbolAliasMap Aliases;
313  addAliases(ES, Aliases, standardRuntimeUtilityAliases());
314  return Aliases;
315 }
316 
319  static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
320  {"_CxxThrowException", "__orc_rt_coff_cxx_throw_exception"},
321  {"_onexit", "__orc_rt_coff_onexit_per_jd"},
322  {"atexit", "__orc_rt_coff_atexit_per_jd"}};
323 
324  return ArrayRef<std::pair<const char *, const char *>>(RequiredCXXAliases);
325 }
326 
329  static const std::pair<const char *, const char *>
330  StandardRuntimeUtilityAliases[] = {
331  {"__orc_rt_run_program", "__orc_rt_coff_run_program"},
332  {"__orc_rt_jit_dlerror", "__orc_rt_coff_jit_dlerror"},
333  {"__orc_rt_jit_dlopen", "__orc_rt_coff_jit_dlopen"},
334  {"__orc_rt_jit_dlclose", "__orc_rt_coff_jit_dlclose"},
335  {"__orc_rt_jit_dlsym", "__orc_rt_coff_jit_dlsym"},
336  {"__orc_rt_log_error", "__orc_rt_log_error_to_stderr"}};
337 
339  StandardRuntimeUtilityAliases);
340 }
341 
342 bool COFFPlatform::supportedTarget(const Triple &TT) {
343  switch (TT.getArch()) {
344  case Triple::x86_64:
345  return true;
346  default:
347  return false;
348  }
349 }
350 
351 COFFPlatform::COFFPlatform(ExecutionSession &ES,
352  ObjectLinkingLayer &ObjLinkingLayer,
353  JITDylib &PlatformJD, const char *OrcRuntimePath,
354  LoadDynamicLibrary LoadDynLibrary,
355  bool StaticVCRuntime, const char *VCRuntimePath,
356  Error &Err)
357  : ES(ES), ObjLinkingLayer(ObjLinkingLayer),
358  LoadDynLibrary(std::move(LoadDynLibrary)),
359  StaticVCRuntime(StaticVCRuntime),
360  COFFHeaderStartSymbol(ES.intern("__ImageBase")) {
361  ErrorAsOutParameter _(&Err);
362 
363  // Create a generator for the ORC runtime archive.
364  auto OrcRuntimeArchiveGenerator =
365  StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath);
366  if (!OrcRuntimeArchiveGenerator) {
367  Err = OrcRuntimeArchiveGenerator.takeError();
368  return;
369  }
370 
371  auto ArchiveBuffer = MemoryBuffer::getFile(OrcRuntimePath);
372  if (!ArchiveBuffer) {
373  Err = createFileError(OrcRuntimePath, ArchiveBuffer.getError());
374  return;
375  }
376  OrcRuntimeArchiveBuffer = std::move(*ArchiveBuffer);
377  OrcRuntimeArchive =
378  std::make_unique<object::Archive>(*OrcRuntimeArchiveBuffer, Err);
379  if (Err)
380  return;
381 
382  Bootstrapping.store(true);
383  ObjLinkingLayer.addPlugin(std::make_unique<COFFPlatformPlugin>(*this));
384 
385  // Load vc runtime
386  auto VCRT =
387  COFFVCRuntimeBootstrapper::Create(ES, ObjLinkingLayer, VCRuntimePath);
388  if (!VCRT) {
389  Err = VCRT.takeError();
390  return;
391  }
392  VCRuntimeBootstrap = std::move(*VCRT);
393 
394  for (auto &Lib : (*OrcRuntimeArchiveGenerator)->getImportedDynamicLibraries())
395  DylibsToPreload.insert(Lib);
396 
397  auto ImportedLibs =
398  StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
399  : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
400  if (!ImportedLibs) {
401  Err = ImportedLibs.takeError();
402  return;
403  }
404 
405  for (auto &Lib : *ImportedLibs)
406  DylibsToPreload.insert(Lib);
407 
408  PlatformJD.addGenerator(std::move(*OrcRuntimeArchiveGenerator));
409 
410  // PlatformJD hasn't been set up by the platform yet (since we're creating
411  // the platform now), so set it up.
412  if (auto E2 = setupJITDylib(PlatformJD)) {
413  Err = std::move(E2);
414  return;
415  }
416 
417  for (auto& Lib : DylibsToPreload)
418  if (auto E2 = LoadDynLibrary(PlatformJD, Lib)) {
419  Err = std::move(E2);
420  return;
421  }
422 
423  if (StaticVCRuntime)
424  if (auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
425  Err = std::move(E2);
426  return;
427  }
428 
429  // Associate wrapper function tags with JIT-side function implementations.
430  if (auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
431  Err = std::move(E2);
432  return;
433  }
434 
435  // Lookup addresses of runtime functions callable by the platform,
436  // call the platform bootstrap function to initialize the platform-state
437  // object in the executor.
438  if (auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
439  Err = std::move(E2);
440  return;
441  }
442 
443  Bootstrapping.store(false);
444  JDBootstrapStates.clear();
445 }
446 
448 COFFPlatform::buildJDDepMap(JITDylib &JD) {
449  return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
450  JITDylibDepMap JDDepMap;
451 
452  SmallVector<JITDylib *, 16> Worklist({&JD});
453  while (!Worklist.empty()) {
454  auto CurJD = Worklist.back();
455  Worklist.pop_back();
456 
457  auto &DM = JDDepMap[CurJD];
458  CurJD->withLinkOrderDo([&](const JITDylibSearchOrder &O) {
459  DM.reserve(O.size());
460  for (auto &KV : O) {
461  if (KV.first == CurJD)
462  continue;
463  {
464  // Bare jitdylibs not known to the platform
465  std::lock_guard<std::mutex> Lock(PlatformMutex);
466  if (!JITDylibToHeaderAddr.count(KV.first)) {
467  LLVM_DEBUG({
468  dbgs() << "JITDylib unregistered to COFFPlatform detected in "
469  "LinkOrder: "
470  << CurJD->getName() << "\n";
471  });
472  continue;
473  }
474  }
475  DM.push_back(KV.first);
476  // Push unvisited entry.
477  if (!JDDepMap.count(KV.first)) {
478  Worklist.push_back(KV.first);
479  JDDepMap[KV.first] = {};
480  }
481  }
482  });
483  }
484  return std::move(JDDepMap);
485  });
486 }
487 
488 void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
489  JITDylibSP JD,
490  JITDylibDepMap &JDDepMap) {
491  SmallVector<JITDylib *, 16> Worklist({JD.get()});
492  DenseSet<JITDylib *> Visited({JD.get()});
494  ES.runSessionLocked([&]() {
495  while (!Worklist.empty()) {
496  auto CurJD = Worklist.back();
497  Worklist.pop_back();
498 
499  auto RISItr = RegisteredInitSymbols.find(CurJD);
500  if (RISItr != RegisteredInitSymbols.end()) {
501  NewInitSymbols[CurJD] = std::move(RISItr->second);
502  RegisteredInitSymbols.erase(RISItr);
503  }
504 
505  for (auto *DepJD : JDDepMap[CurJD])
506  if (!Visited.count(DepJD)) {
507  Worklist.push_back(DepJD);
508  Visited.insert(DepJD);
509  }
510  }
511  });
512 
513  // If there are no further init symbols to look up then send the link order
514  // (as a list of header addresses) to the caller.
515  if (NewInitSymbols.empty()) {
516  // Build the dep info map to return.
517  COFFJITDylibDepInfoMap DIM;
518  DIM.reserve(JDDepMap.size());
519  for (auto &KV : JDDepMap) {
520  std::lock_guard<std::mutex> Lock(PlatformMutex);
521  COFFJITDylibDepInfo DepInfo;
522  DepInfo.reserve(KV.second.size());
523  for (auto &Dep : KV.second) {
524  DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
525  }
526  auto H = JITDylibToHeaderAddr[KV.first];
527  DIM.push_back(std::make_pair(H, std::move(DepInfo)));
528  }
529  SendResult(DIM);
530  return;
531  }
532 
533  // Otherwise issue a lookup and re-run this phase when it completes.
534  lookupInitSymbolsAsync(
535  [this, SendResult = std::move(SendResult), &JD,
536  JDDepMap = std::move(JDDepMap)](Error Err) mutable {
537  if (Err)
538  SendResult(std::move(Err));
539  else
540  pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
541  },
542  ES, std::move(NewInitSymbols));
543 }
544 
545 void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
546  ExecutorAddr JDHeaderAddr) {
547  JITDylibSP JD;
548  {
549  std::lock_guard<std::mutex> Lock(PlatformMutex);
550  auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
551  if (I != HeaderAddrToJITDylib.end())
552  JD = I->second;
553  }
554 
555  LLVM_DEBUG({
556  dbgs() << "COFFPlatform::rt_pushInitializers(" << JDHeaderAddr << ") ";
557  if (JD)
558  dbgs() << "pushing initializers for " << JD->getName() << "\n";
559  else
560  dbgs() << "No JITDylib for header address.\n";
561  });
562 
563  if (!JD) {
564  SendResult(
565  make_error<StringError>("No JITDylib with header addr " +
566  formatv("{0:x}", JDHeaderAddr.getValue()),
568  return;
569  }
570 
571  auto JDDepMap = buildJDDepMap(*JD);
572  if (!JDDepMap) {
573  SendResult(JDDepMap.takeError());
574  return;
575  }
576 
577  pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
578 }
579 
580 void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
582  LLVM_DEBUG({
583  dbgs() << "COFFPlatform::rt_lookupSymbol(\""
584  << formatv("{0:x}", Handle.getValue()) << "\")\n";
585  });
586 
587  JITDylib *JD = nullptr;
588 
589  {
590  std::lock_guard<std::mutex> Lock(PlatformMutex);
591  auto I = HeaderAddrToJITDylib.find(Handle);
592  if (I != HeaderAddrToJITDylib.end())
593  JD = I->second;
594  }
595 
596  if (!JD) {
597  LLVM_DEBUG({
598  dbgs() << " No JITDylib for handle "
599  << formatv("{0:x}", Handle.getValue()) << "\n";
600  });
601  SendResult(make_error<StringError>("No JITDylib associated with handle " +
602  formatv("{0:x}", Handle.getValue()),
604  return;
605  }
606 
607  // Use functor class to work around XL build compiler issue on AIX.
608  class RtLookupNotifyComplete {
609  public:
610  RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
611  : SendResult(std::move(SendResult)) {}
612  void operator()(Expected<SymbolMap> Result) {
613  if (Result) {
614  assert(Result->size() == 1 && "Unexpected result map count");
615  SendResult(ExecutorAddr(Result->begin()->second.getAddress()));
616  } else {
617  SendResult(Result.takeError());
618  }
619  }
620 
621  private:
622  SendSymbolAddressFn SendResult;
623  };
624 
625  ES.lookup(
626  LookupKind::DLSym, {{JD, JITDylibLookupFlags::MatchExportedSymbolsOnly}},
627  SymbolLookupSet(ES.intern(SymbolName)), SymbolState::Ready,
628  RtLookupNotifyComplete(std::move(SendResult)), NoDependenciesToRegister);
629 }
630 
631 Error COFFPlatform::associateRuntimeSupportFunctions(JITDylib &PlatformJD) {
633 
634  using LookupSymbolSPSSig =
636  WFs[ES.intern("__orc_rt_coff_symbol_lookup_tag")] =
637  ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(this,
638  &COFFPlatform::rt_lookupSymbol);
639  using PushInitializersSPSSig =
641  WFs[ES.intern("__orc_rt_coff_push_initializers_tag")] =
642  ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
643  this, &COFFPlatform::rt_pushInitializers);
644 
645  return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
646 }
647 
648 Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
649  llvm::sort(BState.Initializers);
650  if (auto Err =
651  runBootstrapSubsectionInitializers(BState, ".CRT$XIA", ".CRT$XIZ"))
652  return Err;
653 
654  if (auto Err = runSymbolIfExists(*BState.JD, "__run_after_c_init"))
655  return Err;
656 
657  if (auto Err =
658  runBootstrapSubsectionInitializers(BState, ".CRT$XCA", ".CRT$XCZ"))
659  return Err;
660  return Error::success();
661 }
662 
663 Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
664  StringRef Start,
665  StringRef End) {
666  for (auto &Initializer : BState.Initializers)
667  if (Initializer.first >= Start && Initializer.first <= End &&
668  Initializer.second) {
669  auto Res =
670  ES.getExecutorProcessControl().runAsVoidFunction(Initializer.second);
671  if (!Res)
672  return Res.takeError();
673  }
674  return Error::success();
675 }
676 
677 Error COFFPlatform::bootstrapCOFFRuntime(JITDylib &PlatformJD) {
678  // Lookup of runtime symbols causes the collection of initializers if
679  // it's static linking setting.
680  if (auto Err = lookupAndRecordAddrs(
682  {
683  {ES.intern("__orc_rt_coff_platform_bootstrap"),
684  &orc_rt_coff_platform_bootstrap},
685  {ES.intern("__orc_rt_coff_platform_shutdown"),
686  &orc_rt_coff_platform_shutdown},
687  {ES.intern("__orc_rt_coff_register_jitdylib"),
688  &orc_rt_coff_register_jitdylib},
689  {ES.intern("__orc_rt_coff_deregister_jitdylib"),
690  &orc_rt_coff_deregister_jitdylib},
691  {ES.intern("__orc_rt_coff_register_object_sections"),
692  &orc_rt_coff_register_object_sections},
693  {ES.intern("__orc_rt_coff_deregister_object_sections"),
694  &orc_rt_coff_deregister_object_sections},
695  }))
696  return Err;
697 
698  // Call bootstrap functions
699  if (auto Err = ES.callSPSWrapper<void()>(orc_rt_coff_platform_bootstrap))
700  return Err;
701 
702  // Do the pending jitdylib registration actions that we couldn't do
703  // because orc runtime was not linked fully.
704  for (auto KV : JDBootstrapStates) {
705  auto &JDBState = KV.second;
706  if (auto Err = ES.callSPSWrapper<void(SPSString, SPSExecutorAddr)>(
707  orc_rt_coff_register_jitdylib, JDBState.JDName,
708  JDBState.HeaderAddr))
709  return Err;
710 
711  for (auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
712  if (auto Err = ES.callSPSWrapper<void(SPSExecutorAddr,
713  SPSCOFFObjectSectionsMap, bool)>(
714  orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
715  ObjSectionMap, false))
716  return Err;
717  }
718 
719  // Run static initializers collected in bootstrap stage.
720  for (auto KV : JDBootstrapStates) {
721  auto &JDBState = KV.second;
722  if (auto Err = runBootstrapInitializers(JDBState))
723  return Err;
724  }
725 
726  return Error::success();
727 }
728 
729 Error COFFPlatform::runSymbolIfExists(JITDylib &PlatformJD,
731  ExecutorAddr jit_function;
732  auto AfterCLookupErr = lookupAndRecordAddrs(
734  {{ES.intern(SymbolName), &jit_function}});
735  if (!AfterCLookupErr) {
736  auto Res = ES.getExecutorProcessControl().runAsVoidFunction(jit_function);
737  if (!Res)
738  return Res.takeError();
739  return Error::success();
740  }
741  if (!AfterCLookupErr.isA<SymbolsNotFound>())
742  return AfterCLookupErr;
743  consumeError(std::move(AfterCLookupErr));
744  return Error::success();
745 }
746 
747 void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
749  jitlink::PassConfiguration &Config) {
750 
751  bool IsBootstrapping = CP.Bootstrapping.load();
752 
753  if (auto InitSymbol = MR.getInitializerSymbol()) {
754  if (InitSymbol == CP.COFFHeaderStartSymbol) {
755  Config.PostAllocationPasses.push_back(
756  [this, &MR, IsBootstrapping](jitlink::LinkGraph &G) {
757  return associateJITDylibHeaderSymbol(G, MR, IsBootstrapping);
758  });
759  return;
760  }
761  Config.PrePrunePasses.push_back([this, &MR](jitlink::LinkGraph &G) {
762  return preserveInitializerSections(G, MR);
763  });
764  }
765 
766  if (!IsBootstrapping)
767  Config.PostFixupPasses.push_back(
768  [this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
769  return registerObjectPlatformSections(G, JD);
770  });
771  else
772  Config.PostFixupPasses.push_back(
773  [this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
774  return registerObjectPlatformSectionsInBootstrap(G, JD);
775  });
776 }
777 
779 COFFPlatform::COFFPlatformPlugin::getSyntheticSymbolDependencies(
781  std::lock_guard<std::mutex> Lock(PluginMutex);
782  auto I = InitSymbolDeps.find(&MR);
783  if (I != InitSymbolDeps.end()) {
784  SyntheticSymbolDependenciesMap Result;
785  Result[MR.getInitializerSymbol()] = std::move(I->second);
786  InitSymbolDeps.erase(&MR);
787  return Result;
788  }
789  return SyntheticSymbolDependenciesMap();
790 }
791 
792 Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
794  bool IsBootstraping) {
795  auto I = llvm::find_if(G.defined_symbols(), [this](jitlink::Symbol *Sym) {
796  return Sym->getName() == *CP.COFFHeaderStartSymbol;
797  });
798  assert(I != G.defined_symbols().end() && "Missing COFF header start symbol");
799 
800  auto &JD = MR.getTargetJITDylib();
801  std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
802  auto HeaderAddr = (*I)->getAddress();
803  CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
804  CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
805  if (!IsBootstraping) {
806  G.allocActions().push_back(
807  {cantFail(WrapperFunctionCall::Create<
809  CP.orc_rt_coff_register_jitdylib, JD.getName(), HeaderAddr)),
810  cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddr>>(
811  CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
812  } else {
813  G.allocActions().push_back(
814  {{},
815  cantFail(WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddr>>(
816  CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
817  JDBootstrapState BState;
818  BState.JD = &JD;
819  BState.JDName = JD.getName();
820  BState.HeaderAddr = HeaderAddr;
821  CP.JDBootstrapStates.emplace(&JD, BState);
822  }
823 
824  return Error::success();
825 }
826 
827 Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
828  jitlink::LinkGraph &G, JITDylib &JD) {
829  COFFObjectSectionsMap ObjSecs;
830  auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
831  assert(HeaderAddr && "Must be registered jitdylib");
832  for (auto &S : G.sections()) {
834  if (Range.getSize())
835  ObjSecs.push_back(std::make_pair(S.getName().str(), Range.getRange()));
836  }
837 
838  G.allocActions().push_back(
839  {cantFail(WrapperFunctionCall::Create<SPSCOFFRegisterObjectSectionsArgs>(
840  CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs, true)),
841  cantFail(
842  WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
843  CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
844  ObjSecs))});
845 
846  return Error::success();
847 }
848 
849 Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
851  JITLinkSymbolSet InitSectionSymbols;
852  for (auto &Sec : G.sections())
853  if (COFFPlatform::isInitializerSection(Sec.getName()))
854  for (auto *B : Sec.blocks())
855  if (!B->edges_empty())
856  InitSectionSymbols.insert(
857  &G.addAnonymousSymbol(*B, 0, 0, false, true));
858 
859  std::lock_guard<std::mutex> Lock(PluginMutex);
860  InitSymbolDeps[&MR] = InitSectionSymbols;
861  return Error::success();
862 }
863 
864 Error COFFPlatform::COFFPlatformPlugin::
865  registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &G,
866  JITDylib &JD) {
867  std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
868  auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
869  COFFObjectSectionsMap ObjSecs;
870  for (auto &S : G.sections()) {
872  if (Range.getSize())
873  ObjSecs.push_back(std::make_pair(S.getName().str(), Range.getRange()));
874  }
875 
876  G.allocActions().push_back(
877  {{},
878  cantFail(
879  WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
880  CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
881  ObjSecs))});
882 
883  auto &BState = CP.JDBootstrapStates[&JD];
884  BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
885 
886  // Collect static initializers
887  for (auto &S : G.sections())
888  if (COFFPlatform::isInitializerSection(S.getName()))
889  for (auto *B : S.blocks()) {
890  if (B->edges_empty())
891  continue;
892  for (auto &E : B->edges())
893  BState.Initializers.push_back(std::make_pair(
894  S.getName().str(),
895  ExecutorAddr(E.getTarget().getAddress() + E.getAddend())));
896  }
897 
898  return Error::success();
899 }
900 
901 } // End namespace orc.
902 } // End namespace llvm.
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:31
llvm::IntrusiveRefCntPtr::get
T * get() const
Definition: IntrusiveRefCntPtr.h:200
llvm::orc::MaterializationResponsibility
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:519
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:20
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::orc::COFFPlatform::setupJITDylib
Error setupJITDylib(JITDylib &JD) override
This method will be called outside the session lock each time a JITDylib is created (unless it is cre...
Definition: COFFPlatform.cpp:234
llvm::orc::JITDylib
Represents a JIT'd dynamic library.
Definition: Core.h:953
llvm::msgpack::Endianness
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
llvm::AArch64CC::AL
@ AL
Definition: AArch64BaseInfo.h:269
llvm::orc::shared::SPSSequence
SPS tag type for sequences.
Definition: SimplePackedSerialization.h:205
llvm::ARM::PredBlockMask::TT
@ TT
llvm::unique_function< Error(JITDylib &JD, StringRef DLLFileName)>
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::orc::JITDylib::addToLinkOrder
void addToLinkOrder(JITDylib &JD, JITDylibLookupFlags JDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Add the given JITDylib to the link order for definitions in this JITDylib.
Definition: Core.cpp:1331
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
DM
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
offsetof
#define offsetof(TYPE, MEMBER)
Definition: AMDHSAKernelDescriptor.h:23
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:175
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:57
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::COFF::IMAGE_FILE_MACHINE_AMD64
@ IMAGE_FILE_MACHINE_AMD64
Definition: COFF.h:97
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::orc::ExecutorAddr::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:105
llvm::orc::shared
Definition: ELFNixPlatform.h:245
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::orc::ResourceTracker
API to remove / transfer ownership of JIT resources.
Definition: Core.h:53
llvm::Optional
Definition: APInt.h:33
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
COFFPlatform.h
llvm::object::pe32plus_header
The 64-bit PE header that follows the COFF header.
Definition: COFF.h:140
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1042
llvm::orc::MaterializationUnit
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Definition: Core.h:665
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, Optional< Align > Alignment=None)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:244
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:265
llvm::orc::COFFPlatform::teardownJITDylib
Error teardownJITDylib(JITDylib &JD) override
This method will be called outside the session lock each time a JITDylib is removed to allow the Plat...
Definition: COFFPlatform.cpp:278
DebugUtils.h
llvm::COFF::PEMagic
static const char PEMagic[]
Definition: COFF.h:35
llvm::orc::MaterializationUnit::getName
virtual StringRef getName() const =0
Return the name of this materialization unit.
llvm::object::dos_header
The DOS compatible header at the front of all PE/COFF executables.
Definition: COFF.h:53
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::object::coff_file_header
Definition: COFF.h:75
llvm::orc::ResourceTracker::getJITDylib
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:68
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::orc::DLLImportDefinitionGenerator::Create
static std::unique_ptr< DLLImportDefinitionGenerator > Create(ExecutionSession &ES, ObjectLinkingLayer &L)
Creates a DLLImportDefinitionGenerator instance.
Definition: ExecutionUtils.cpp:434
llvm::orc::ExecutionSession::registerJITDispatchHandlers
Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
Definition: Core.cpp:2185
llvm::MemoryBuffer::getMemBuffer
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
Definition: MemoryBuffer.cpp:117
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1319
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::support::little
@ little
Definition: Endian.h:27
llvm::orc::SymbolsNotFound
Used to notify clients when symbols can not be found during a lookup.
Definition: Core.h:432
llvm::orc::MemProt::Read
@ Read
llvm::orc
Definition: COFFPlatform.h:30
llvm::orc::NoDependenciesToRegister
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Definition: Core.cpp:35
llvm::SubDirectoryType::Lib
@ Lib
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::orc::COFFPlatform::standardRuntimeUtilityAliases
static ArrayRef< std::pair< const char *, const char * > > standardRuntimeUtilityAliases()
Returns the array of standard runtime utility aliases for COFF.
Definition: COFFPlatform.cpp:328
llvm::orc::COFFPlatform
Mediates between COFF initialization and ExecutionSession state.
Definition: COFFPlatform.h:33
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::orc::ExecutionSession::intern
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1416
llvm::orc::JITDylib::addGenerator
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
Definition: Core.h:1789
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:228
llvm::orc::ExecutionSession::runSessionLocked
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1426
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition: Error.h:1096
llvm::orc::MaterializationUnit::Interface
Definition: Core.h:672
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
llvm::orc::ExecutionSession::createBareJITDylib
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
Definition: Core.cpp:1940
llvm::orc::MaterializationResponsibility::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
Definition: Core.h:552
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1682
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::object::data_directory
Definition: COFF.h:172
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::AMDGPU::Hwreg::Offset
Offset
Definition: SIDefines.h:416
llvm::orc::MaterializationResponsibility::getTargetJITDylib
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
Definition: Core.h:538
uint64_t
llvm::orc::MaterializationUnit::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
Definition: Core.h:698
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::orc::shared::SPSExpected
SPS tag type for expecteds, which are either a T or a string representing an error.
Definition: SimplePackedSerialization.h:548
llvm::DenseMap< SymbolStringPtr, JITSymbolFlags >
LookupAndRecordAddrs.h
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::orc::ExecutorProcessControl::runAsVoidFunction
virtual Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr)=0
Run function with a int (*)(void) signature.
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1861
EPCDynamicLibrarySearchGenerator.h
llvm::orc::ExecutionSession::callSPSWrapper
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1610
llvm::orc::JITDylibSearchOrder
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
Definition: Core.h:154
llvm::orc::ExecutionSession::getExecutorProcessControl
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition: Core.h:1408
llvm::orc::COFFPlatform::notifyAdding
Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) override
This method will be called under the ExecutionSession lock each time a MaterializationUnit is added t...
Definition: COFFPlatform.cpp:290
llvm::orc::COFFPlatform::Create
static Expected< std::unique_ptr< COFFPlatform > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, const char *OrcRuntimePath, LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime=false, const char *VCRuntimePath=nullptr, Optional< SymbolAliasMap > RuntimeAliases=None)
Try to create a COFFPlatform instance, adding the ORC runtime to the given JITDylib.
Definition: COFFPlatform.cpp:163
_
#define _
Definition: HexagonMCCodeEmitter.cpp:47
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::orc::COFFPlatform::notifyRemoving
Error notifyRemoving(ResourceTracker &RT) override
This method will be called under the ExecutionSession lock when a ResourceTracker is removed.
Definition: COFFPlatform.cpp:307
llvm::logicalview::LVAttributeKind::Range
@ Range
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:22
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:744
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::orc::StaticLibraryDefinitionGenerator::Load
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
Definition: ExecutionUtils.cpp:274
for
this could be done in SelectionDAGISel along with other special for
Definition: README.txt:104
x86_64.h
llvm::orc::ObjectLinkingLayer
An ObjectLayer implementation built on JITLink.
Definition: ObjectLinkingLayer.h:50
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1761
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
llvm::orc::COFFVCRuntimeBootstrapper::Create
static Expected< std::unique_ptr< COFFVCRuntimeBootstrapper > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, const char *RuntimePath=nullptr)
Try to create a COFFVCRuntimeBootstrapper instance.
Definition: COFFVCRuntimeSupport.cpp:23
llvm::AMDGPU::HSAMD::Kernel::Key::SymbolName
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Definition: AMDGPUMetadata.h:386
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:851
H
#define H(x, y, z)
Definition: MD5.cpp:57
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::COFF::NUM_DATA_DIRECTORIES
@ NUM_DATA_DIRECTORIES
Definition: COFF.h:599
llvm::orc::ObjectLinkingLayer::addPlugin
ObjectLinkingLayer & addPlugin(std::unique_ptr< Plugin > P)
Add a pass-config modifier.
Definition: ObjectLinkingLayer.h:126
llvm::orc::addAliases
static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases, ArrayRef< std::pair< const char *, const char * >> AL)
Definition: COFFPlatform.cpp:224
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1365
llvm::orc::symbolAliases
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
Definition: Core.h:809
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:763
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:596
llvm::orc::JITDylib::define
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition: Core.h:1806
COFF.h
llvm::COFF::PE32Header::PE32_PLUS
@ PE32_PLUS
Definition: COFF.h:541
llvm::orc::ExecutionSession::lookup
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Definition: Core.cpp:2076
llvm::orc::getObjectFileInterface
Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
Definition: ObjectFileInterface.cpp:274
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::orc::ExecutionSession::wrapAsyncWithSPS
static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H)
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produc...
Definition: Core.h:1624
llvm::orc::COFFPlatform::requiredCXXAliases
static ArrayRef< std::pair< const char *, const char * > > requiredCXXAliases()
Returns the array of required CXX aliases.
Definition: COFFPlatform.cpp:318
llvm::IntrusiveRefCntPtr
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
Definition: IntrusiveRefCntPtr.h:168
llvm::orc::shared::SPSArgList
A utility class for serializing to a blob from a variadic list.
Definition: SimplePackedSerialization.h:108
llvm::orc::makeJITDylibSearchOrder
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
Definition: Core.h:158
llvm::orc::COFFPlatform::standardPlatformAliases
static SymbolAliasMap standardPlatformAliases(ExecutionSession &ES)
Returns an AliasMap containing the default aliases for the COFFPlatform.
Definition: COFFPlatform.cpp:311
llvm::orc::lookupAndRecordAddrs
void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * >> Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
Definition: LookupAndRecordAddrs.cpp:16
ObjectFileInterface.h
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85