LLVM 20.0.0git
AIXException.cpp
Go to the documentation of this file.
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
13#include "DwarfException.h"
17#include "llvm/IR/Module.h"
19#include "llvm/MC/MCStreamer.h"
22
23namespace llvm {
24
26
27void AIXException::emitExceptionInfoTable(const MCSymbol *LSDA,
28 const MCSymbol *PerSym) {
29 // Generate EH Info Table.
30 // The EH Info Table, aka, 'compat unwind section' on AIX, have the following
31 // format: struct eh_info_t {
32 // unsigned version; /* EH info verion 0 */
33 // #if defined(__64BIT__)
34 // char _pad[4]; /* padding */
35 // #endif
36 // unsigned long lsda; /* Pointer to LSDA */
37 // unsigned long personality; /* Pointer to the personality routine */
38 // }
39
40 auto *EHInfo =
41 cast<MCSectionXCOFF>(Asm->getObjFileLowering().getCompactUnwindSection());
42 if (Asm->TM.getFunctionSections()) {
43 // If option -ffunction-sections is on, append the function name to the
44 // name of EH Info Table csect so that each function has its own EH Info
45 // Table csect. This helps the linker to garbage-collect EH info of unused
46 // functions.
47 SmallString<128> NameStr = EHInfo->getName();
48 raw_svector_ostream(NameStr) << '.' << Asm->MF->getFunction().getName();
49 EHInfo = Asm->OutContext.getXCOFFSection(NameStr, EHInfo->getKind(),
50 EHInfo->getCsectProp());
51 }
52 Asm->OutStreamer->switchSection(EHInfo);
53 MCSymbol *EHInfoLabel =
55 Asm->OutStreamer->emitLabel(EHInfoLabel);
56
57 // Version number.
58 Asm->emitInt32(0);
59
60 const DataLayout &DL = MMI->getModule()->getDataLayout();
61 const unsigned PointerSize = DL.getPointerSize();
62
63 // Add necessary paddings in 64 bit mode.
64 Asm->OutStreamer->emitValueToAlignment(Align(PointerSize));
65
66 // LSDA location.
68 PointerSize);
69
70 // Personality routine.
72 PointerSize);
73}
74
76 // There is no easy way to access register information in `AIXException`
77 // class. when ShouldEmitEHBlock is false and VRs are saved, A dumy eh info
78 // table are emitted in PPCAIXAsmPrinter::emitFunctionBodyEnd.
80 return;
81
82 const MCSymbol *LSDALabel = emitExceptionTable();
83
84 const Function &F = MF->getFunction();
85 assert(F.hasPersonalityFn() &&
86 "Landingpads are presented, but no personality routine is found.");
87 const auto *Per =
88 cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
89 const MCSymbol *PerSym = Asm->TM.getSymbol(Per);
90
91 emitExceptionInfoTable(LSDALabel, PerSym);
92}
93
94} // End of namespace llvm
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void endFunction(const MachineFunction *MF) override
Gather post-function debug information.
AIXException(AsmPrinter *A)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:86
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:408
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:89
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:104
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:96
void emitInt32(int Value) const
Emit a long directive and value.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:101
Emits exception handling directives.
Definition: EHStreamer.h:30
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:33
MCSymbol * emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:380
MachineModuleInfo * MMI
Collected machine module information.
Definition: EHStreamer.h:36
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
Definition: MCContext.cpp:805
MCSection * getCompactUnwindSection() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:398
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Function & getFunction()
Return the LLVM function that this machine code represents.
const Module * getModule() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:294
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
static bool ShouldEmitEHBlock(const MachineFunction *MF)
MCSymbol * getSymbol(const GlobalValue *GV) const
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:691
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18