AIXException.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //===-- CodeGen/AsmPrinter/AIXException.cpp - AIX Exception Impl ----------===//
  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. // This file contains support for writing AIX exception info into asm files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "DwarfException.h"
  13. #include "llvm/CodeGen/AsmPrinter.h"
  14. #include "llvm/CodeGen/MachineModuleInfo.h"
  15. #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
  16. #include "llvm/MC/MCSectionXCOFF.h"
  17. #include "llvm/MC/MCStreamer.h"
  18. #include "llvm/Target/TargetLoweringObjectFile.h"
  19. #include "llvm/Target/TargetMachine.h"
  20. namespace llvm {
  21. AIXException::AIXException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {}
  22. void AIXException::markFunctionEnd() { endFragment(); }
  23. void AIXException::emitExceptionInfoTable(const MCSymbol *LSDA,
  24. const MCSymbol *PerSym) {
  25. // Generate EH Info Table.
  26. // The EH Info Table, aka, 'compat unwind section' on AIX, have the following
  27. // format: struct eh_info_t {
  28. // unsigned version; /* EH info verion 0 */
  29. // #if defined(__64BIT__)
  30. // char _pad[4]; /* padding */
  31. // #endif
  32. // unsigned long lsda; /* Pointer to LSDA */
  33. // unsigned long personality; /* Pointer to the personality routine */
  34. // }
  35. Asm->OutStreamer->SwitchSection(
  36. Asm->getObjFileLowering().getCompactUnwindSection());
  37. MCSymbol *EHInfoLabel =
  38. TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(Asm->MF);
  39. Asm->OutStreamer->emitLabel(EHInfoLabel);
  40. // Version number.
  41. Asm->emitInt32(0);
  42. const DataLayout &DL = MMI->getModule()->getDataLayout();
  43. const unsigned PointerSize = DL.getPointerSize();
  44. // Add necessary paddings in 64 bit mode.
  45. Asm->OutStreamer->emitValueToAlignment(PointerSize);
  46. // LSDA location.
  47. Asm->OutStreamer->emitValue(MCSymbolRefExpr::create(LSDA, Asm->OutContext),
  48. PointerSize);
  49. // Personality routine.
  50. Asm->OutStreamer->emitValue(MCSymbolRefExpr::create(PerSym, Asm->OutContext),
  51. PointerSize);
  52. }
  53. void AIXException::endFunction(const MachineFunction *MF) {
  54. // There is no easy way to access register information in `AIXException`
  55. // class. when ShouldEmitEHBlock is false and VRs are saved, A dumy eh info
  56. // table are emitted in PPCAIXAsmPrinter::emitFunctionBodyEnd.
  57. if (!TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock(MF))
  58. return;
  59. const MCSymbol *LSDALabel = emitExceptionTable();
  60. const Function &F = MF->getFunction();
  61. assert(F.hasPersonalityFn() &&
  62. "Landingpads are presented, but no personality routine is found.");
  63. const GlobalValue *Per =
  64. dyn_cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
  65. const MCSymbol *PerSym = Asm->TM.getSymbol(Per);
  66. emitExceptionInfoTable(LSDALabel, PerSym);
  67. }
  68. } // End of namespace llvm