LLVM  14.0.0git
MachOPlatform.cpp
Go to the documentation of this file.
1 //===------ MachOPlatform.cpp - Utilities for executing MachO 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 
10 
17 #include "llvm/Support/Debug.h"
18 
19 #define DEBUG_TYPE "orc"
20 
21 using namespace llvm;
22 using namespace llvm::orc;
23 using namespace llvm::orc::shared;
24 
25 namespace {
26 
27 class MachOHeaderMaterializationUnit : public MaterializationUnit {
28 public:
29  MachOHeaderMaterializationUnit(MachOPlatform &MOP,
30  const SymbolStringPtr &HeaderStartSymbol)
31  : MaterializationUnit(createHeaderSymbols(MOP, HeaderStartSymbol),
32  HeaderStartSymbol),
33  MOP(MOP) {}
34 
35  StringRef getName() const override { return "MachOHeaderMU"; }
36 
37  void materialize(std::unique_ptr<MaterializationResponsibility> R) override {
38  unsigned PointerSize;
40  const auto &TT =
42 
43  switch (TT.getArch()) {
44  case Triple::aarch64:
45  case Triple::x86_64:
46  PointerSize = 8;
48  break;
49  default:
50  llvm_unreachable("Unrecognized architecture");
51  }
52 
53  auto G = std::make_unique<jitlink::LinkGraph>(
54  "<MachOHeaderMU>", TT, PointerSize, Endianness,
56  auto &HeaderSection = G->createSection("__header", sys::Memory::MF_READ);
57  auto &HeaderBlock = createHeaderBlock(*G, HeaderSection);
58 
59  // Init symbol is header-start symbol.
60  G->addDefinedSymbol(HeaderBlock, 0, *R->getInitializerSymbol(),
61  HeaderBlock.getSize(), jitlink::Linkage::Strong,
62  jitlink::Scope::Default, false, true);
63  for (auto &HS : AdditionalHeaderSymbols)
64  G->addDefinedSymbol(HeaderBlock, HS.Offset, HS.Name,
65  HeaderBlock.getSize(), jitlink::Linkage::Strong,
66  jitlink::Scope::Default, false, true);
67 
69  }
70 
71  void discard(const JITDylib &JD, const SymbolStringPtr &Sym) override {}
72 
73 private:
74  struct HeaderSymbol {
75  const char *Name;
77  };
78 
79  static constexpr HeaderSymbol AdditionalHeaderSymbols[] = {
80  {"___mh_executable_header", 0}};
81 
82  static jitlink::Block &createHeaderBlock(jitlink::LinkGraph &G,
83  jitlink::Section &HeaderSection) {
86  switch (G.getTargetTriple().getArch()) {
87  case Triple::aarch64:
90  break;
91  case Triple::x86_64:
94  break;
95  default:
96  llvm_unreachable("Unrecognized architecture");
97  }
98  Hdr.filetype = MachO::MH_DYLIB; // Custom file type?
99  Hdr.ncmds = 0;
100  Hdr.sizeofcmds = 0;
101  Hdr.flags = 0;
102  Hdr.reserved = 0;
103 
104  if (G.getEndianness() != support::endian::system_endianness())
105  MachO::swapStruct(Hdr);
106 
107  auto HeaderContent = G.allocateString(
108  StringRef(reinterpret_cast<const char *>(&Hdr), sizeof(Hdr)));
109 
110  return G.createContentBlock(HeaderSection, HeaderContent, 0, 8, 0);
111  }
112 
113  static SymbolFlagsMap
114  createHeaderSymbols(MachOPlatform &MOP,
115  const SymbolStringPtr &HeaderStartSymbol) {
116  SymbolFlagsMap HeaderSymbolFlags;
117 
118  HeaderSymbolFlags[HeaderStartSymbol] = JITSymbolFlags::Exported;
119  for (auto &HS : AdditionalHeaderSymbols)
120  HeaderSymbolFlags[MOP.getExecutionSession().intern(HS.Name)] =
122 
123  return HeaderSymbolFlags;
124  }
125 
126  MachOPlatform &MOP;
127 };
128 
129 constexpr MachOHeaderMaterializationUnit::HeaderSymbol
130  MachOHeaderMaterializationUnit::AdditionalHeaderSymbols[];
131 
132 StringRef EHFrameSectionName = "__TEXT,__eh_frame";
133 StringRef ModInitFuncSectionName = "__DATA,__mod_init_func";
134 StringRef ObjCClassListSectionName = "__DATA,__objc_classlist";
135 StringRef ObjCImageInfoSectionName = "__DATA,__objc_image_info";
136 StringRef ObjCSelRefsSectionName = "__DATA,__objc_selrefs";
137 StringRef Swift5ProtoSectionName = "__TEXT,__swift5_proto";
138 StringRef Swift5ProtosSectionName = "__TEXT,__swift5_protos";
139 StringRef ThreadBSSSectionName = "__DATA,__thread_bss";
140 StringRef ThreadDataSectionName = "__DATA,__thread_data";
141 StringRef ThreadVarsSectionName = "__DATA,__thread_vars";
142 
143 StringRef InitSectionNames[] = {
144  ModInitFuncSectionName, ObjCSelRefsSectionName, ObjCClassListSectionName,
145  Swift5ProtosSectionName, Swift5ProtoSectionName};
146 
147 } // end anonymous namespace
148 
149 namespace llvm {
150 namespace orc {
151 
154  JITDylib &PlatformJD, const char *OrcRuntimePath,
155  Optional<SymbolAliasMap> RuntimeAliases) {
156 
157  auto &EPC = ES.getExecutorProcessControl();
158 
159  // If the target is not supported then bail out immediately.
160  if (!supportedTarget(EPC.getTargetTriple()))
161  return make_error<StringError>("Unsupported MachOPlatform triple: " +
162  EPC.getTargetTriple().str(),
164 
165  // Create default aliases if the caller didn't supply any.
166  if (!RuntimeAliases)
167  RuntimeAliases = standardPlatformAliases(ES);
168 
169  // Define the aliases.
170  if (auto Err = PlatformJD.define(symbolAliases(std::move(*RuntimeAliases))))
171  return std::move(Err);
172 
173  // Add JIT-dispatch function support symbols.
174  if (auto Err = PlatformJD.define(absoluteSymbols(
175  {{ES.intern("___orc_rt_jit_dispatch"),
176  {EPC.getJITDispatchInfo().JITDispatchFunctionAddress.getValue(),
178  {ES.intern("___orc_rt_jit_dispatch_ctx"),
179  {EPC.getJITDispatchInfo().JITDispatchContextAddress.getValue(),
181  return std::move(Err);
182 
183  // Create a generator for the ORC runtime archive.
184  auto OrcRuntimeArchiveGenerator = StaticLibraryDefinitionGenerator::Load(
185  ObjLinkingLayer, OrcRuntimePath, EPC.getTargetTriple());
186  if (!OrcRuntimeArchiveGenerator)
187  return OrcRuntimeArchiveGenerator.takeError();
188 
189  // Create the instance.
190  Error Err = Error::success();
191  auto P = std::unique_ptr<MachOPlatform>(
192  new MachOPlatform(ES, ObjLinkingLayer, PlatformJD,
193  std::move(*OrcRuntimeArchiveGenerator), Err));
194  if (Err)
195  return std::move(Err);
196  return std::move(P);
197 }
198 
200  return JD.define(std::make_unique<MachOHeaderMaterializationUnit>(
201  *this, MachOHeaderStartSymbol));
202 }
203 
205  const MaterializationUnit &MU) {
206  auto &JD = RT.getJITDylib();
207  const auto &InitSym = MU.getInitializerSymbol();
208  if (!InitSym)
209  return Error::success();
210 
211  RegisteredInitSymbols[&JD].add(InitSym,
213  LLVM_DEBUG({
214  dbgs() << "MachOPlatform: Registered init symbol " << *InitSym << " for MU "
215  << MU.getName() << "\n";
216  });
217  return Error::success();
218 }
219 
221  llvm_unreachable("Not supported yet");
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  SymbolAliasMap Aliases;
236  addAliases(ES, Aliases, requiredCXXAliases());
237  addAliases(ES, Aliases, standardRuntimeUtilityAliases());
238  return Aliases;
239 }
240 
243  static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
244  {"___cxa_atexit", "___orc_rt_macho_cxa_atexit"}};
245 
246  return ArrayRef<std::pair<const char *, const char *>>(RequiredCXXAliases);
247 }
248 
251  static const std::pair<const char *, const char *>
252  StandardRuntimeUtilityAliases[] = {
253  {"___orc_rt_run_program", "___orc_rt_macho_run_program"},
254  {"___orc_rt_log_error", "___orc_rt_log_error_to_stderr"}};
255 
257  StandardRuntimeUtilityAliases);
258 }
259 
261  StringRef SectName) {
262  for (auto &Name : InitSectionNames) {
263  if (Name.startswith(SegName) && Name.substr(7) == SectName)
264  return true;
265  }
266  return false;
267 }
268 
269 bool MachOPlatform::supportedTarget(const Triple &TT) {
270  switch (TT.getArch()) {
271  case Triple::x86_64:
272  return true;
273  default:
274  return false;
275  }
276 }
277 
278 MachOPlatform::MachOPlatform(
279  ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
280  JITDylib &PlatformJD,
281  std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator, Error &Err)
282  : ES(ES), ObjLinkingLayer(ObjLinkingLayer),
283  MachOHeaderStartSymbol(ES.intern("___dso_handle")) {
284  ErrorAsOutParameter _(&Err);
285 
286  ObjLinkingLayer.addPlugin(std::make_unique<MachOPlatformPlugin>(*this));
287 
288  PlatformJD.addGenerator(std::move(OrcRuntimeGenerator));
289 
290  // PlatformJD hasn't been 'set-up' by the platform yet (since we're creating
291  // the platform now), so set it up.
292  if (auto E2 = setupJITDylib(PlatformJD)) {
293  Err = std::move(E2);
294  return;
295  }
296 
297  RegisteredInitSymbols[&PlatformJD].add(
298  MachOHeaderStartSymbol, SymbolLookupFlags::WeaklyReferencedSymbol);
299 
300  // Associate wrapper function tags with JIT-side function implementations.
301  if (auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
302  Err = std::move(E2);
303  return;
304  }
305 
306  // Lookup addresses of runtime functions callable by the platform,
307  // call the platform bootstrap function to initialize the platform-state
308  // object in the executor.
309  if (auto E2 = bootstrapMachORuntime(PlatformJD)) {
310  Err = std::move(E2);
311  return;
312  }
313 }
314 
315 Error MachOPlatform::associateRuntimeSupportFunctions(JITDylib &PlatformJD) {
317 
318  using GetInitializersSPSSig =
320  WFs[ES.intern("___orc_rt_macho_get_initializers_tag")] =
321  ES.wrapAsyncWithSPS<GetInitializersSPSSig>(
322  this, &MachOPlatform::rt_getInitializers);
323 
324  using GetDeinitializersSPSSig =
326  WFs[ES.intern("___orc_rt_macho_get_deinitializers_tag")] =
327  ES.wrapAsyncWithSPS<GetDeinitializersSPSSig>(
328  this, &MachOPlatform::rt_getDeinitializers);
329 
330  using LookupSymbolSPSSig =
332  WFs[ES.intern("___orc_rt_macho_symbol_lookup_tag")] =
333  ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(this,
334  &MachOPlatform::rt_lookupSymbol);
335 
336  return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
337 }
338 
339 void MachOPlatform::getInitializersBuildSequencePhase(
340  SendInitializerSequenceFn SendResult, JITDylib &JD,
341  std::vector<JITDylibSP> DFSLinkOrder) {
343  {
344  std::lock_guard<std::mutex> Lock(PlatformMutex);
345  for (auto &InitJD : reverse(DFSLinkOrder)) {
346  LLVM_DEBUG({
347  dbgs() << "MachOPlatform: Appending inits for \"" << InitJD->getName()
348  << "\" to sequence\n";
349  });
350  auto ISItr = InitSeqs.find(InitJD.get());
351  if (ISItr != InitSeqs.end()) {
352  FullInitSeq.emplace_back(std::move(ISItr->second));
353  InitSeqs.erase(ISItr);
354  }
355  }
356  }
357 
358  SendResult(std::move(FullInitSeq));
359 }
360 
361 void MachOPlatform::getInitializersLookupPhase(
362  SendInitializerSequenceFn SendResult, JITDylib &JD) {
363 
364  auto DFSLinkOrder = JD.getDFSLinkOrder();
366  ES.runSessionLocked([&]() {
367  for (auto &InitJD : DFSLinkOrder) {
368  auto RISItr = RegisteredInitSymbols.find(InitJD.get());
369  if (RISItr != RegisteredInitSymbols.end()) {
370  NewInitSymbols[InitJD.get()] = std::move(RISItr->second);
371  RegisteredInitSymbols.erase(RISItr);
372  }
373  }
374  });
375 
376  // If there are no further init symbols to look up then move on to the next
377  // phase.
378  if (NewInitSymbols.empty()) {
379  getInitializersBuildSequencePhase(std::move(SendResult), JD,
380  std::move(DFSLinkOrder));
381  return;
382  }
383 
384  // Otherwise issue a lookup and re-run this phase when it completes.
386  [this, SendResult = std::move(SendResult), &JD](Error Err) mutable {
387  if (Err)
388  SendResult(std::move(Err));
389  else
390  getInitializersLookupPhase(std::move(SendResult), JD);
391  },
392  ES, std::move(NewInitSymbols));
393 }
394 
395 void MachOPlatform::rt_getInitializers(SendInitializerSequenceFn SendResult,
396  StringRef JDName) {
397  LLVM_DEBUG({
398  dbgs() << "MachOPlatform::rt_getInitializers(\"" << JDName << "\")\n";
399  });
400 
401  JITDylib *JD = ES.getJITDylibByName(JDName);
402  if (!JD) {
403  LLVM_DEBUG({
404  dbgs() << " No such JITDylib \"" << JDName << "\". Sending error.\n";
405  });
406  SendResult(make_error<StringError>("No JITDylib named " + JDName,
408  return;
409  }
410 
411  getInitializersLookupPhase(std::move(SendResult), *JD);
412 }
413 
414 void MachOPlatform::rt_getDeinitializers(SendDeinitializerSequenceFn SendResult,
415  ExecutorAddress Handle) {
416  LLVM_DEBUG({
417  dbgs() << "MachOPlatform::rt_getDeinitializers(\""
418  << formatv("{0:x}", Handle.getValue()) << "\")\n";
419  });
420 
421  JITDylib *JD = nullptr;
422 
423  {
424  std::lock_guard<std::mutex> Lock(PlatformMutex);
425  auto I = HeaderAddrToJITDylib.find(Handle.getValue());
426  if (I != HeaderAddrToJITDylib.end())
427  JD = I->second;
428  }
429 
430  if (!JD) {
431  LLVM_DEBUG({
432  dbgs() << " No JITDylib for handle "
433  << formatv("{0:x}", Handle.getValue()) << "\n";
434  });
435  SendResult(make_error<StringError>("No JITDylib associated with handle " +
436  formatv("{0:x}", Handle.getValue()),
438  return;
439  }
440 
442 }
443 
444 void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
445  ExecutorAddress Handle,
447  LLVM_DEBUG({
448  dbgs() << "MachOPlatform::rt_lookupSymbol(\""
449  << formatv("{0:x}", Handle.getValue()) << "\")\n";
450  });
451 
452  JITDylib *JD = nullptr;
453 
454  {
455  std::lock_guard<std::mutex> Lock(PlatformMutex);
456  auto I = HeaderAddrToJITDylib.find(Handle.getValue());
457  if (I != HeaderAddrToJITDylib.end())
458  JD = I->second;
459  }
460 
461  if (!JD) {
462  LLVM_DEBUG({
463  dbgs() << " No JITDylib for handle "
464  << formatv("{0:x}", Handle.getValue()) << "\n";
465  });
466  SendResult(make_error<StringError>("No JITDylib associated with handle " +
467  formatv("{0:x}", Handle.getValue()),
469  return;
470  }
471 
472  // Use functor class to work around XL build compiler issue on AIX.
473  class RtLookupNotifyComplete {
474  public:
475  RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
476  : SendResult(std::move(SendResult)) {}
477  void operator()(Expected<SymbolMap> Result) {
478  if (Result) {
479  assert(Result->size() == 1 && "Unexpected result map count");
480  SendResult(ExecutorAddress(Result->begin()->second.getAddress()));
481  } else {
482  SendResult(Result.takeError());
483  }
484  }
485 
486  private:
487  SendSymbolAddressFn SendResult;
488  };
489 
490  // FIXME: Proper mangling.
491  auto MangledName = ("_" + SymbolName).str();
492  ES.lookup(
494  SymbolLookupSet(ES.intern(MangledName)), SymbolState::Ready,
495  RtLookupNotifyComplete(std::move(SendResult)), NoDependenciesToRegister);
496 }
497 
498 Error MachOPlatform::bootstrapMachORuntime(JITDylib &PlatformJD) {
499 
500  if (auto Err = lookupAndRecordAddrs(
502  {{ES.intern("___orc_rt_macho_platform_bootstrap"),
503  &orc_rt_macho_platform_bootstrap},
504  {ES.intern("___orc_rt_macho_platform_shutdown"),
505  &orc_rt_macho_platform_shutdown},
506  {ES.intern("___orc_rt_macho_register_object_sections"),
507  &orc_rt_macho_register_object_sections},
508  {ES.intern("___orc_rt_macho_create_pthread_key"),
509  &orc_rt_macho_create_pthread_key}}))
510  return Err;
511 
512  if (auto Err =
513  ES.callSPSWrapper<void()>(orc_rt_macho_platform_bootstrap.getValue()))
514  return Err;
515 
516  // FIXME: Ordering is fuzzy here. We're probably best off saying
517  // "behavior is undefined if code that uses the runtime is added before
518  // the platform constructor returns", then move all this to the constructor.
519  RuntimeBootstrapped = true;
520  std::vector<MachOPerObjectSectionsToRegister> DeferredPOSRs;
521  {
522  std::lock_guard<std::mutex> Lock(PlatformMutex);
523  DeferredPOSRs = std::move(BootstrapPOSRs);
524  }
525 
526  for (auto &D : DeferredPOSRs)
527  if (auto Err = registerPerObjectSections(D))
528  return Err;
529 
530  return Error::success();
531 }
532 
533 Error MachOPlatform::registerInitInfo(
534  JITDylib &JD, ExecutorAddress ObjCImageInfoAddr,
535  ArrayRef<jitlink::Section *> InitSections) {
536 
537  std::unique_lock<std::mutex> Lock(PlatformMutex);
538 
539  MachOJITDylibInitializers *InitSeq = nullptr;
540  {
541  auto I = InitSeqs.find(&JD);
542  if (I == InitSeqs.end()) {
543  // If there's no init sequence entry yet then we need to look up the
544  // header symbol to force creation of one.
545  Lock.unlock();
546 
547  auto SearchOrder =
548  JD.withLinkOrderDo([](const JITDylibSearchOrder &SO) { return SO; });
549  if (auto Err = ES.lookup(SearchOrder, MachOHeaderStartSymbol).takeError())
550  return Err;
551 
552  Lock.lock();
553  I = InitSeqs.find(&JD);
554  assert(I != InitSeqs.end() &&
555  "Entry missing after header symbol lookup?");
556  }
557  InitSeq = &I->second;
558  }
559 
560  InitSeq->ObjCImageInfoAddress = ObjCImageInfoAddr;
561 
562  for (auto *Sec : InitSections) {
563  // FIXME: Avoid copy here.
564  jitlink::SectionRange R(*Sec);
565  InitSeq->InitSections[Sec->getName()].push_back(
566  {ExecutorAddress(R.getStart()), ExecutorAddress(R.getEnd())});
567  }
568 
569  return Error::success();
570 }
571 
572 Error MachOPlatform::registerPerObjectSections(
573  const MachOPerObjectSectionsToRegister &POSR) {
574 
575  if (!orc_rt_macho_register_object_sections)
576  return make_error<StringError>("Attempting to register per-object "
577  "sections, but runtime support has not "
578  "been loaded yet",
580 
581  Error ErrResult = Error::success();
582  if (auto Err = ES.callSPSWrapper<shared::SPSError(
584  orc_rt_macho_register_object_sections.getValue(), ErrResult, POSR))
585  return Err;
586  return ErrResult;
587 }
588 
589 Expected<uint64_t> MachOPlatform::createPThreadKey() {
590  if (!orc_rt_macho_create_pthread_key)
591  return make_error<StringError>(
592  "Attempting to create pthread key in target, but runtime support has "
593  "not been loaded yet",
595 
597  if (auto Err = ES.callSPSWrapper<SPSExpected<uint64_t>(void)>(
598  orc_rt_macho_create_pthread_key.getValue(), Result))
599  return std::move(Err);
600  return Result;
601 }
602 
603 void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
605  jitlink::PassConfiguration &Config) {
606 
607  // If the initializer symbol is the MachOHeader start symbol then just add
608  // the macho header support passes.
609  if (MR.getInitializerSymbol() == MP.MachOHeaderStartSymbol) {
610  addMachOHeaderSupportPasses(MR, Config);
611  // The header materialization unit doesn't require any other support, so we
612  // can bail out early.
613  return;
614  }
615 
616  // If the object contains initializers then add passes to record them.
617  if (MR.getInitializerSymbol())
618  addInitializerSupportPasses(MR, Config);
619 
620  // Add passes for eh-frame and TLV support.
621  addEHAndTLVSupportPasses(MR, Config);
622 }
623 
625 MachOPlatform::MachOPlatformPlugin::getSyntheticSymbolDependencies(
627  std::lock_guard<std::mutex> Lock(PluginMutex);
628  auto I = InitSymbolDeps.find(&MR);
629  if (I != InitSymbolDeps.end()) {
630  SyntheticSymbolDependenciesMap Result;
631  Result[MR.getInitializerSymbol()] = std::move(I->second);
632  InitSymbolDeps.erase(&MR);
633  return Result;
634  }
635  return SyntheticSymbolDependenciesMap();
636 }
637 
638 void MachOPlatform::MachOPlatformPlugin::addInitializerSupportPasses(
640 
641  /// Preserve init sections.
642  Config.PrePrunePasses.push_back([this, &MR](jitlink::LinkGraph &G) {
643  if (auto Err = preserveInitSections(G, MR))
644  return Err;
645  return processObjCImageInfo(G, MR);
646  });
647 
648  Config.PostFixupPasses.push_back(
649  [this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
650  return registerInitSections(G, JD);
651  });
652 }
653 
654 void MachOPlatform::MachOPlatformPlugin::addMachOHeaderSupportPasses(
656 
657  Config.PostAllocationPasses.push_back([this, &JD = MR.getTargetJITDylib()](
658  jitlink::LinkGraph &G) -> Error {
659  auto I = llvm::find_if(G.defined_symbols(), [this](jitlink::Symbol *Sym) {
660  return Sym->getName() == *MP.MachOHeaderStartSymbol;
661  });
662  assert(I != G.defined_symbols().end() &&
663  "Missing MachO header start symbol");
664  {
665  std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
666  JITTargetAddress HeaderAddr = (*I)->getAddress();
667  MP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
668  assert(!MP.InitSeqs.count(&JD) && "InitSeq entry for JD already exists");
669  MP.InitSeqs.insert(
670  std::make_pair(&JD, MachOJITDylibInitializers(
671  JD.getName(), ExecutorAddress(HeaderAddr))));
672  }
673  return Error::success();
674  });
675 }
676 
677 void MachOPlatform::MachOPlatformPlugin::addEHAndTLVSupportPasses(
679 
680  // Insert TLV lowering at the start of the PostPrunePasses, since we want
681  // it to run before GOT/PLT lowering.
682  Config.PostPrunePasses.insert(
683  Config.PostPrunePasses.begin(),
684  [this, &JD = MR.getTargetJITDylib()](jitlink::LinkGraph &G) {
685  return fixTLVSectionsAndEdges(G, JD);
686  });
687 
688  // Add a pass to register the final addresses of the eh-frame and TLV sections
689  // with the runtime.
690  Config.PostFixupPasses.push_back([this](jitlink::LinkGraph &G) -> Error {
692 
693  if (auto *EHFrameSection = G.findSectionByName(EHFrameSectionName)) {
694  jitlink::SectionRange R(*EHFrameSection);
695  if (!R.empty())
696  POSR.EHFrameSection = {ExecutorAddress(R.getStart()),
697  ExecutorAddress(R.getEnd())};
698  }
699 
700  // Get a pointer to the thread data section if there is one. It will be used
701  // below.
702  jitlink::Section *ThreadDataSection =
703  G.findSectionByName(ThreadDataSectionName);
704 
705  // Handle thread BSS section if there is one.
706  if (auto *ThreadBSSSection = G.findSectionByName(ThreadBSSSectionName)) {
707  // If there's already a thread data section in this graph then merge the
708  // thread BSS section content into it, otherwise just treat the thread
709  // BSS section as the thread data section.
710  if (ThreadDataSection)
711  G.mergeSections(*ThreadDataSection, *ThreadBSSSection);
712  else
713  ThreadDataSection = ThreadBSSSection;
714  }
715 
716  // Having merged thread BSS (if present) and thread data (if present),
717  // record the resulting section range.
718  if (ThreadDataSection) {
719  jitlink::SectionRange R(*ThreadDataSection);
720  if (!R.empty())
721  POSR.ThreadDataSection = {ExecutorAddress(R.getStart()),
722  ExecutorAddress(R.getEnd())};
723  }
724 
725  if (POSR.EHFrameSection.StartAddress ||
727 
728  // If we're still bootstrapping the runtime then just record this
729  // frame for now.
730  if (!MP.RuntimeBootstrapped) {
731  std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
732  MP.BootstrapPOSRs.push_back(POSR);
733  return Error::success();
734  }
735 
736  // Otherwise register it immediately.
737  if (auto Err = MP.registerPerObjectSections(POSR))
738  return Err;
739  }
740 
741  return Error::success();
742  });
743 }
744 
745 Error MachOPlatform::MachOPlatformPlugin::preserveInitSections(
747 
748  JITLinkSymbolSet InitSectionSymbols;
749  for (auto &InitSectionName : InitSectionNames) {
750  // Skip non-init sections.
751  auto *InitSection = G.findSectionByName(InitSectionName);
752  if (!InitSection)
753  continue;
754 
755  // Make a pass over live symbols in the section: those blocks are already
756  // preserved.
757  DenseSet<jitlink::Block *> AlreadyLiveBlocks;
758  for (auto &Sym : InitSection->symbols()) {
759  auto &B = Sym->getBlock();
760  if (Sym->isLive() && Sym->getOffset() == 0 &&
761  Sym->getSize() == B.getSize() && !AlreadyLiveBlocks.count(&B)) {
762  InitSectionSymbols.insert(Sym);
763  AlreadyLiveBlocks.insert(&B);
764  }
765  }
766 
767  // Add anonymous symbols to preserve any not-already-preserved blocks.
768  for (auto *B : InitSection->blocks())
769  if (!AlreadyLiveBlocks.count(B))
770  InitSectionSymbols.insert(
771  &G.addAnonymousSymbol(*B, 0, B->getSize(), false, true));
772  }
773 
774  if (!InitSectionSymbols.empty()) {
775  std::lock_guard<std::mutex> Lock(PluginMutex);
776  InitSymbolDeps[&MR] = std::move(InitSectionSymbols);
777  }
778 
779  return Error::success();
780 }
781 
782 Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
784 
785  // If there's an ObjC imagine info then either
786  // (1) It's the first __objc_imageinfo we've seen in this JITDylib. In
787  // this case we name and record it.
788  // OR
789  // (2) We already have a recorded __objc_imageinfo for this JITDylib,
790  // in which case we just verify it.
791  auto *ObjCImageInfo = G.findSectionByName(ObjCImageInfoSectionName);
792  if (!ObjCImageInfo)
793  return Error::success();
794 
795  auto ObjCImageInfoBlocks = ObjCImageInfo->blocks();
796 
797  // Check that the section is not empty if present.
798  if (llvm::empty(ObjCImageInfoBlocks))
799  return make_error<StringError>("Empty " + ObjCImageInfoSectionName +
800  " section in " + G.getName(),
802 
803  // Check that there's only one block in the section.
804  if (std::next(ObjCImageInfoBlocks.begin()) != ObjCImageInfoBlocks.end())
805  return make_error<StringError>("Multiple blocks in " +
806  ObjCImageInfoSectionName +
807  " section in " + G.getName(),
809 
810  // Check that the __objc_imageinfo section is unreferenced.
811  // FIXME: We could optimize this check if Symbols had a ref-count.
812  for (auto &Sec : G.sections()) {
813  if (&Sec != ObjCImageInfo)
814  for (auto *B : Sec.blocks())
815  for (auto &E : B->edges())
816  if (E.getTarget().isDefined() &&
817  &E.getTarget().getBlock().getSection() == ObjCImageInfo)
818  return make_error<StringError>(ObjCImageInfoSectionName +
819  " is referenced within file " +
820  G.getName(),
822  }
823 
824  auto &ObjCImageInfoBlock = **ObjCImageInfoBlocks.begin();
825  auto *ObjCImageInfoData = ObjCImageInfoBlock.getContent().data();
826  auto Version = support::endian::read32(ObjCImageInfoData, G.getEndianness());
827  auto Flags =
828  support::endian::read32(ObjCImageInfoData + 4, G.getEndianness());
829 
830  // Lock the mutex while we verify / update the ObjCImageInfos map.
831  std::lock_guard<std::mutex> Lock(PluginMutex);
832 
833  auto ObjCImageInfoItr = ObjCImageInfos.find(&MR.getTargetJITDylib());
834  if (ObjCImageInfoItr != ObjCImageInfos.end()) {
835  // We've already registered an __objc_imageinfo section. Verify the
836  // content of this new section matches, then delete it.
837  if (ObjCImageInfoItr->second.first != Version)
838  return make_error<StringError>(
839  "ObjC version in " + G.getName() +
840  " does not match first registered version",
842  if (ObjCImageInfoItr->second.second != Flags)
843  return make_error<StringError>("ObjC flags in " + G.getName() +
844  " do not match first registered flags",
846 
847  // __objc_imageinfo is valid. Delete the block.
848  for (auto *S : ObjCImageInfo->symbols())
849  G.removeDefinedSymbol(*S);
850  G.removeBlock(ObjCImageInfoBlock);
851  } else {
852  // We haven't registered an __objc_imageinfo section yet. Register and
853  // move on. The section should already be marked no-dead-strip.
854  ObjCImageInfos[&MR.getTargetJITDylib()] = std::make_pair(Version, Flags);
855  }
856 
857  return Error::success();
858 }
859 
860 Error MachOPlatform::MachOPlatformPlugin::registerInitSections(
861  jitlink::LinkGraph &G, JITDylib &JD) {
862 
863  ExecutorAddress ObjCImageInfoAddr;
864  SmallVector<jitlink::Section *> InitSections;
865 
866  if (auto *ObjCImageInfoSec = G.findSectionByName(ObjCImageInfoSectionName)) {
867  if (auto Addr = jitlink::SectionRange(*ObjCImageInfoSec).getStart())
868  ObjCImageInfoAddr.setValue(Addr);
869  }
870 
871  for (auto InitSectionName : InitSectionNames)
872  if (auto *Sec = G.findSectionByName(InitSectionName))
873  InitSections.push_back(Sec);
874 
875  // Dump the scraped inits.
876  LLVM_DEBUG({
877  dbgs() << "MachOPlatform: Scraped " << G.getName() << " init sections:\n";
878  if (ObjCImageInfoAddr)
879  dbgs() << " " << ObjCImageInfoSectionName << ": "
880  << formatv("{0:x}", ObjCImageInfoAddr.getValue()) << "\n";
881  for (auto *Sec : InitSections) {
882  jitlink::SectionRange R(*Sec);
883  dbgs() << " " << Sec->getName() << ": "
884  << formatv("[ {0:x} -- {1:x} ]", R.getStart(), R.getEnd()) << "\n";
885  }
886  });
887 
888  return MP.registerInitInfo(JD, ObjCImageInfoAddr, InitSections);
889 }
890 
891 Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
892  jitlink::LinkGraph &G, JITDylib &JD) {
893 
894  // Rename external references to __tlv_bootstrap to ___orc_rt_tlv_get_addr.
895  for (auto *Sym : G.external_symbols())
896  if (Sym->getName() == "__tlv_bootstrap") {
897  Sym->setName("___orc_rt_macho_tlv_get_addr");
898  break;
899  }
900 
901  // Store key in __thread_vars struct fields.
902  if (auto *ThreadDataSec = G.findSectionByName(ThreadVarsSectionName)) {
904  {
905  std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
906  auto I = MP.JITDylibToPThreadKey.find(&JD);
907  if (I != MP.JITDylibToPThreadKey.end())
908  Key = I->second;
909  }
910 
911  if (!Key) {
912  if (auto KeyOrErr = MP.createPThreadKey())
913  Key = *KeyOrErr;
914  else
915  return KeyOrErr.takeError();
916  }
917 
918  uint64_t PlatformKeyBits =
919  support::endian::byte_swap(*Key, G.getEndianness());
920 
921  for (auto *B : ThreadDataSec->blocks()) {
922  if (B->getSize() != 3 * G.getPointerSize())
923  return make_error<StringError>("__thread_vars block at " +
924  formatv("{0:x}", B->getAddress()) +
925  " has unexpected size",
927 
928  auto NewBlockContent = G.allocateBuffer(B->getSize());
929  llvm::copy(B->getContent(), NewBlockContent.data());
930  memcpy(NewBlockContent.data() + G.getPointerSize(), &PlatformKeyBits,
931  G.getPointerSize());
932  B->setContent(NewBlockContent);
933  }
934  }
935 
936  // Transform any TLV edges into GOT edges.
937  for (auto *B : G.blocks())
938  for (auto &E : B->edges())
939  if (E.getKind() ==
941  E.setKind(jitlink::x86_64::
943 
944  return Error::success();
945 }
946 
947 } // End namespace orc.
948 } // End namespace llvm.
llvm::orc::ObjectLinkingLayer::emit
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< MemoryBuffer > O) override
Emit an object file.
Definition: ObjectLinkingLayer.cpp:645
llvm::orc::MachOPlatform::notifyRemoving
Error notifyRemoving(ResourceTracker &RT) override
This method will be called under the ExecutionSession lock when a ResourceTracker is removed.
Definition: MachOPlatform.cpp:220
llvm::orc::MaterializationResponsibility
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:505
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
llvm::sys::Memory::MF_READ
@ MF_READ
Definition: Memory.h:55
llvm::orc::JITDylib::withLinkOrderDo
auto withLinkOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchOrder & >()))
Do something with the link order (run under the session lock).
Definition: Core.h:1686
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::orc::JITDylib
A symbol table that supports asynchoronous symbol queries.
Definition: Core.h:907
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:193
llvm::MachO::mach_header_64::flags
uint32_t flags
Definition: MachO.h:526
llvm::orc::ExecutorAddress
Represents an address in the executor process.
Definition: ExecutorAddress.h:37
llvm::support::endian::read32
uint32_t read32(const void *P, endianness E)
Definition: Endian.h:363
llvm::orc::ExecutionSession::getJITDylibByName
JITDylib * getJITDylibByName(StringRef Name)
Return a pointer to the "name" JITDylib.
Definition: Core.cpp:1847
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
BinaryByteStream.h
llvm::orc::MachOJITDylibInitializers
Definition: MachOPlatform.h:34
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::orc::SymbolLookupSet
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Definition: Core.h:174
llvm::orc::LookupKind::Static
@ Static
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:50
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::orc::StaticLibraryDefinitionGenerator::Load
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName)
Try to create a StaticLibraryDefinitionGenerator from the given path.
Definition: ExecutionUtils.cpp:272
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::orc::shared
Definition: ELFNixPlatform.h:243
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:331
llvm::orc::ResourceTracker
API to remove / transfer ownership of JIT resources.
Definition: Core.h:52
llvm::orc::MachOJITDylibDeinitializerSequence
std::vector< MachOJITDylibDeinitializers > MachOJITDylibDeinitializerSequence
Definition: MachOPlatform.h:54
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1600
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
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MachO::mach_header_64::ncmds
uint32_t ncmds
Definition: MachO.h:524
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::orc::MachOJITDylibInitializerSequence
std::vector< MachOJITDylibInitializers > MachOJITDylibInitializerSequence
Definition: MachOPlatform.h:51
llvm::orc::Platform::lookupInitSymbolsAsync
static void lookupInitSymbolsAsync(unique_function< void(Error)> OnComplete, ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
Performs an async lookup for the the given symbols in each of the given JITDylibs,...
Definition: Core.cpp:1753
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:183
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
llvm::orc::MaterializationUnit
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Definition: Core.h:649
llvm::MachO::CPU_TYPE_X86_64
@ CPU_TYPE_X86_64
Definition: MachO.h:1422
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
ExecutionUtils.h
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:193
DebugUtils.h
llvm::orc::MaterializationUnit::getName
virtual StringRef getName() const =0
Return the name of this materialization unit.
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::orc::MachOPlatform::Create
static Expected< std::unique_ptr< MachOPlatform > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, const char *OrcRuntimePath, Optional< SymbolAliasMap > RuntimeAliases=None)
Try to create a MachOPlatform instance, adding the ORC runtime to the given JITDylib.
Definition: MachOPlatform.cpp:153
llvm::orc::ResourceTracker::getJITDylib
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:67
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:250
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:2057
llvm::orc::MachOPlatform::requiredCXXAliases
static ArrayRef< std::pair< const char *, const char * > > requiredCXXAliases()
Returns the array of required CXX aliases.
Definition: MachOPlatform.cpp:242
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::support::little
@ little
Definition: Endian.h:27
llvm::orc::ExecutionSession::callSPSWrapper
Error callSPSWrapper(JITTargetAddress WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1498
llvm::orc
Definition: CompileOnDemandLayer.h:57
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::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::AArch64CC::HS
@ HS
Definition: AArch64BaseInfo.h:257
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MachO::mach_header_64::reserved
uint32_t reserved
Definition: MachO.h:527
llvm::orc::ExecutionSession::intern
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1314
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:1678
llvm::orc::ExecutionSession::runSessionLocked
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Definition: Core.h:1324
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition: Error.h:1089
llvm::orc::LookupKind::DLSym
@ DLSym
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::orc::MachOPlatform
Mediates between MachO initialization and ExecutionSession state.
Definition: MachOPlatform.h:57
llvm::MachO::mach_header_64::magic
uint32_t magic
Definition: MachO.h:520
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
llvm::orc::MachOPlatform::isInitializerSection
static bool isInitializerSection(StringRef SegName, StringRef SectName)
Returns true if the given section name is an initializer section.
Definition: MachOPlatform.cpp:260
llvm::orc::MaterializationResponsibility::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
Definition: Core.h:537
llvm::orc::MachOPlatform::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: MachOPlatform.cpp:204
llvm::MachO::mach_header_64
Definition: MachO.h:519
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::orc::ExecutorAddressRange::StartAddress
ExecutorAddress StartAddress
Definition: ExecutorAddress.h:147
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::orc::MaterializationResponsibility::getTargetJITDylib
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
Definition: Core.h:523
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::orc::MaterializationUnit::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
Definition: Core.h:674
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
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:505
llvm::DenseMap< SymbolStringPtr, JITSymbolFlags >
LookupAndRecordAddrs.h
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::orc::MachOPlatform::getObjectLinkingLayer
ObjectLinkingLayer & getObjectLinkingLayer() const
Definition: MachOPlatform.h:103
llvm::MachO::CPU_TYPE_ARM64
@ CPU_TYPE_ARM64
Definition: MachO.h:1426
llvm::MachO::CPU_SUBTYPE_ARM64_ALL
@ CPU_SUBTYPE_ARM64_ALL
Definition: MachO.h:1497
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:1607
llvm::sys::SmartMutex::unlock
bool unlock()
Definition: Mutex.h:46
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
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:153
llvm::orc::ExecutionSession::getExecutorProcessControl
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
Definition: Core.h:1311
_
#define _
Definition: HexagonMCCodeEmitter.cpp:47
llvm::orc::MachOPerObjectSectionsToRegister::EHFrameSection
ExecutorAddressRange EHFrameSection
Definition: MachOPlatform.h:30
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::orc::MachOPerObjectSectionsToRegister::ThreadDataSection
ExecutorAddressRange ThreadDataSection
Definition: MachOPlatform.h:31
llvm::orc::SymbolState::Ready
@ Ready
Emitted to memory, but waiting on transitive dependencies.
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
MachOPlatform.h
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::MachOPerObjectSectionsToRegister
Definition: MachOPlatform.h:29
llvm::orc::MachOJITDylibInitializers::ObjCImageInfoAddress
ExecutorAddress ObjCImageInfoAddress
Definition: MachOPlatform.h:44
llvm::orc::JITDylib::getDFSLinkOrder
static std::vector< JITDylibSP > getDFSLinkOrder(ArrayRef< JITDylibSP > JDs)
Returns the given JITDylibs and all of their transitive dependencies in DFS order (based on linkage r...
Definition: Core.cpp:1872
x86_64.h
llvm::orc::ObjectLinkingLayer
An ObjectLayer implementation built on JITLink.
Definition: ObjectLinkingLayer.h:54
llvm::orc::lookupAndRecordAddrs
void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddress * >> Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddresses.
Definition: LookupAndRecordAddrs.cpp:16
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::orc::MachOPlatform::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: MachOPlatform.cpp:199
llvm::sys::SmartMutex::lock
bool lock()
Definition: Mutex.h:33
llvm::AMDGPU::HSAMD::Kernel::Key::SymbolName
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Definition: AMDGPUMetadata.h:381
llvm::MachO::MH_DYLIB
@ MH_DYLIB
Definition: MachO.h:48
llvm::empty
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:254
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
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:77
llvm::orc::ObjectLinkingLayer::addPlugin
ObjectLinkingLayer & addPlugin(std::unique_ptr< Plugin > P)
Add a pass-config modifier.
Definition: ObjectLinkingLayer.h:130
llvm::orc::addAliases
static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases, ArrayRef< std::pair< const char *, const char * >> AL)
Definition: ELFNixPlatform.cpp:177
llvm::orc::ExecutorProcessControl::getTargetTriple
const Triple & getTargetTriple() const
Return the Triple for the target process.
Definition: ExecutorProcessControl.h:141
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1275
llvm::orc::JITDylibLookupFlags::MatchExportedSymbolsOnly
@ MatchExportedSymbolsOnly
llvm::support::endian::byte_swap
value_type byte_swap(value_type value, endianness endian)
Definition: Endian.h:49
llvm::orc::symbolAliases
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
Definition: Core.h:777
llvm::orc::shared::SPSExecutorAddress
SPS tag type for executor addresseses.
Definition: SimplePackedSerialization.h:199
llvm::orc::ExecutorAddress::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:59
llvm::orc::MachOPlatform::standardRuntimeUtilityAliases
static ArrayRef< std::pair< const char *, const char * > > standardRuntimeUtilityAliases()
Returns the array of standard runtime utility aliases for MachO.
Definition: MachOPlatform.cpp:250
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:732
llvm::support::endian::system_endianness
constexpr endianness system_endianness()
Definition: Endian.h:44
llvm::orc::ExecutorAddress::setValue
void setValue(uint64_t Addr)
Definition: ExecutorAddress.h:60
llvm::MachO::CPU_SUBTYPE_X86_64_ALL
@ CPU_SUBTYPE_X86_64_ALL
Definition: MachO.h:1467
llvm::MachO::mach_header_64::sizeofcmds
uint32_t sizeofcmds
Definition: MachO.h:525
llvm::orc::JITDylib::getName
const std::string & getName() const
Get the name for this JITDylib.
Definition: Core.h:924
llvm::orc::MachOJITDylibInitializers::InitSections
StringMap< SectionList > InitSections
Definition: MachOPlatform.h:46
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:1692
llvm::MachO::mach_header_64::cpusubtype
uint32_t cpusubtype
Definition: MachO.h:522
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:1948
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::orc::MachOPlatform::standardPlatformAliases
static SymbolAliasMap standardPlatformAliases(ExecutionSession &ES)
Returns an AliasMap containing the default aliases for the MachOPlatform.
Definition: MachOPlatform.cpp:234
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:1512
MachO.h
llvm::MachO::swapStruct
void swapStruct(fat_header &mh)
Definition: MachO.h:1005
llvm::MachO::MH_MAGIC_64
@ MH_MAGIC_64
Definition: MachO.h:32
llvm::MachO::mach_header_64::cputype
uint32_t cputype
Definition: MachO.h:521
Debug.h
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:157
llvm::MachO::mach_header_64::filetype
uint32_t filetype
Definition: MachO.h:523
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:52
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85
llvm::orc::MachOPlatform::getExecutionSession
ExecutionSession & getExecutionSession() const
Definition: MachOPlatform.h:102