EPCEHFrameRegistrar.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //===------ EPCEHFrameRegistrar.cpp - EPC-based eh-frame registration -----===//
  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. #include "llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h"
  9. #include "llvm/ExecutionEngine/Orc/Core.h"
  10. #include "llvm/Support/BinaryStreamWriter.h"
  11. using namespace llvm::orc::shared;
  12. namespace llvm {
  13. namespace orc {
  14. Expected<std::unique_ptr<EPCEHFrameRegistrar>> EPCEHFrameRegistrar::Create(
  15. ExecutionSession &ES,
  16. std::optional<ExecutorAddr> RegistrationFunctionsDylib) {
  17. // FIXME: Proper mangling here -- we really need to decouple linker mangling
  18. // from DataLayout.
  19. // Find the addresses of the registration/deregistration functions in the
  20. // executor process.
  21. auto &EPC = ES.getExecutorProcessControl();
  22. if (!RegistrationFunctionsDylib) {
  23. if (auto D = EPC.loadDylib(nullptr))
  24. RegistrationFunctionsDylib = *D;
  25. else
  26. return D.takeError();
  27. }
  28. std::string RegisterWrapperName, DeregisterWrapperName;
  29. if (EPC.getTargetTriple().isOSBinFormatMachO()) {
  30. RegisterWrapperName += '_';
  31. DeregisterWrapperName += '_';
  32. }
  33. RegisterWrapperName += "llvm_orc_registerEHFrameSectionWrapper";
  34. DeregisterWrapperName += "llvm_orc_deregisterEHFrameSectionWrapper";
  35. SymbolLookupSet RegistrationSymbols;
  36. RegistrationSymbols.add(EPC.intern(RegisterWrapperName));
  37. RegistrationSymbols.add(EPC.intern(DeregisterWrapperName));
  38. auto Result =
  39. EPC.lookupSymbols({{*RegistrationFunctionsDylib, RegistrationSymbols}});
  40. if (!Result)
  41. return Result.takeError();
  42. assert(Result->size() == 1 && "Unexpected number of dylibs in result");
  43. assert((*Result)[0].size() == 2 &&
  44. "Unexpected number of addresses in result");
  45. auto RegisterEHFrameWrapperFnAddr = (*Result)[0][0];
  46. auto DeregisterEHFrameWrapperFnAddr = (*Result)[0][1];
  47. return std::make_unique<EPCEHFrameRegistrar>(
  48. ES, ExecutorAddr(RegisterEHFrameWrapperFnAddr),
  49. ExecutorAddr(DeregisterEHFrameWrapperFnAddr));
  50. }
  51. Error EPCEHFrameRegistrar::registerEHFrames(ExecutorAddrRange EHFrameSection) {
  52. return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
  53. RegisterEHFrameWrapperFnAddr, EHFrameSection);
  54. }
  55. Error EPCEHFrameRegistrar::deregisterEHFrames(
  56. ExecutorAddrRange EHFrameSection) {
  57. return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
  58. DeregisterEHFrameWrapperFnAddr, EHFrameSection);
  59. }
  60. } // end namespace orc
  61. } // end namespace llvm