| 1 | //===--------- EHFrameRegistrationPlugin.cpp - Register eh-frames ---------===// |
| 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 | |
| 9 | #include "llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h" |
| 10 | |
| 11 | #include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h" |
| 12 | #include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h" |
| 13 | #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h" |
| 14 | |
| 15 | #define DEBUG_TYPE "orc" |
| 16 | |
| 17 | using namespace llvm::jitlink; |
| 18 | |
| 19 | namespace llvm::orc { |
| 20 | |
| 21 | Expected<std::unique_ptr<EHFrameRegistrationPlugin>> |
| 22 | EHFrameRegistrationPlugin::Create(ExecutionSession &ES) { |
| 23 | // Lookup addresseses of the registration/deregistration functions in the |
| 24 | // bootstrap map. |
| 25 | ExecutorAddr RegisterEHFrameSectionAllocAction; |
| 26 | ExecutorAddr DeregisterEHFrameSectionAllocAction; |
| 27 | if (auto Err = ES.getExecutorProcessControl().getBootstrapSymbols( |
| 28 | Pairs: {{RegisterEHFrameSectionAllocAction, |
| 29 | rt::RegisterEHFrameSectionAllocActionName}, |
| 30 | {DeregisterEHFrameSectionAllocAction, |
| 31 | rt::DeregisterEHFrameSectionAllocActionName}})) |
| 32 | return std::move(Err); |
| 33 | |
| 34 | return std::make_unique<EHFrameRegistrationPlugin>( |
| 35 | args&: RegisterEHFrameSectionAllocAction, args&: DeregisterEHFrameSectionAllocAction); |
| 36 | } |
| 37 | |
| 38 | void EHFrameRegistrationPlugin::modifyPassConfig( |
| 39 | MaterializationResponsibility &MR, LinkGraph &LG, |
| 40 | PassConfiguration &PassConfig) { |
| 41 | if (LG.getTargetTriple().isOSBinFormatMachO()) |
| 42 | PassConfig.PrePrunePasses.insert( |
| 43 | position: PassConfig.PrePrunePasses.begin(), x: [](LinkGraph &G) { |
| 44 | if (auto *CUSec = G.findSectionByName(Name: MachOCompactUnwindSectionName)) |
| 45 | G.removeSection(Sec&: *CUSec); |
| 46 | return Error::success(); |
| 47 | }); |
| 48 | |
| 49 | PassConfig.PostFixupPasses.push_back(x: [this](LinkGraph &G) -> Error { |
| 50 | if (auto *EHFrame = getEHFrameSection(G)) { |
| 51 | using namespace shared; |
| 52 | auto R = SectionRange(*EHFrame).getRange(); |
| 53 | G.allocActions().push_back( |
| 54 | x: {.Finalize: cantFail( |
| 55 | ValOrErr: WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>( |
| 56 | FnAddr: RegisterEHFrame, Args: R)), |
| 57 | .Dealloc: cantFail( |
| 58 | ValOrErr: WrapperFunctionCall::Create<SPSArgList<SPSExecutorAddrRange>>( |
| 59 | FnAddr: DeregisterEHFrame, Args: R))}); |
| 60 | } |
| 61 | return Error::success(); |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | } // namespace llvm::orc |
| 66 | |