Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/JITLink/SEHFrameSupport.h
35271 views
//===------- SEHFrameSupport.h - JITLink seh-frame utils --------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// SEHFrame utils for JITLink.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_EXECUTIONENGINE_JITLINK_SEHFRAMESUPPORT_H13#define LLVM_EXECUTIONENGINE_JITLINK_SEHFRAMESUPPORT_H1415#include "llvm/ADT/SetVector.h"16#include "llvm/ExecutionEngine/JITLink/JITLink.h"17#include "llvm/ExecutionEngine/JITSymbol.h"18#include "llvm/Support/Error.h"19#include "llvm/TargetParser/Triple.h"2021namespace llvm {22namespace jitlink {23/// This pass adds keep-alive edge from SEH frame sections24/// to the parent function content block.25class SEHFrameKeepAlivePass {26public:27SEHFrameKeepAlivePass(StringRef SEHFrameSectionName)28: SEHFrameSectionName(SEHFrameSectionName) {}2930Error operator()(LinkGraph &G) {31auto *S = G.findSectionByName(SEHFrameSectionName);32if (!S)33return Error::success();3435// Simply consider every block pointed by seh frame block as parants.36// This adds some unnecessary keep-alive edges to unwind info blocks,37// (xdata) but these blocks are usually dead by default, so they wouldn't38// count for the fate of seh frame block.39for (auto *B : S->blocks()) {40auto &DummySymbol = G.addAnonymousSymbol(*B, 0, 0, false, false);41SetVector<Block *> Children;42for (auto &E : B->edges()) {43auto &Sym = E.getTarget();44if (!Sym.isDefined())45continue;46Children.insert(&Sym.getBlock());47}48for (auto *Child : Children)49Child->addEdge(Edge(Edge::KeepAlive, 0, DummySymbol, 0));50}51return Error::success();52}5354private:55StringRef SEHFrameSectionName;56};5758} // end namespace jitlink59} // end namespace llvm6061#endif // LLVM_EXECUTIONENGINE_JITLINK_SEHFRAMESUPPORT_H626364