SEHFrameSupport.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===------- SEHFrameSupport.h - JITLink seh-frame utils --------*- C++ -*-===//
  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. // SEHFrame utils for JITLink.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_EXECUTIONENGINE_JITLINK_SEHFRAMESUPPORT_H
  13. #define LLVM_EXECUTIONENGINE_JITLINK_SEHFRAMESUPPORT_H
  14. #include "llvm/ADT/Triple.h"
  15. #include "llvm/ExecutionEngine/JITLink/JITLink.h"
  16. #include "llvm/ExecutionEngine/JITSymbol.h"
  17. #include "llvm/Support/Error.h"
  18. namespace llvm {
  19. namespace jitlink {
  20. /// This pass adds keep-alive edge from SEH frame sections
  21. /// to the parent function content block.
  22. class SEHFrameKeepAlivePass {
  23. public:
  24. SEHFrameKeepAlivePass(StringRef SEHFrameSectionName)
  25. : SEHFrameSectionName(SEHFrameSectionName) {}
  26. Error operator()(LinkGraph &G) {
  27. auto *S = G.findSectionByName(SEHFrameSectionName);
  28. if (!S)
  29. return Error::success();
  30. // Simply consider every block pointed by seh frame block as parants.
  31. // This adds some unnecessary keep-alive edges to unwind info blocks,
  32. // (xdata) but these blocks are usually dead by default, so they wouldn't
  33. // count for the fate of seh frame block.
  34. for (auto *B : S->blocks()) {
  35. auto &DummySymbol = G.addAnonymousSymbol(*B, 0, 0, false, false);
  36. DenseSet<Block *> Children;
  37. for (auto &E : B->edges()) {
  38. auto &Sym = E.getTarget();
  39. if (!Sym.isDefined())
  40. continue;
  41. Children.insert(&Sym.getBlock());
  42. }
  43. for (auto *Child : Children)
  44. Child->addEdge(Edge(Edge::KeepAlive, 0, DummySymbol, 0));
  45. }
  46. return Error::success();
  47. }
  48. private:
  49. StringRef SEHFrameSectionName;
  50. };
  51. } // end namespace jitlink
  52. } // end namespace llvm
  53. #endif // LLVM_EXECUTIONENGINE_JITLINK_SEHFRAMESUPPORT_H