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