EPCEHFrameRegistrar.cpp 2.5 KB

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