LLVM  16.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/MC/MCSectionXCOFF.h"
18 #include "llvm/MC/MCStreamer.h"
21 
22 namespace llvm {
23 
25 
26 // This overrides 'DwarfCFIExceptionBase::markFunctionEnd', to avoid the call to
27 // tidyLandingPads. This is necessary, because the
28 // 'PPCAIXAsmPrinter::emitFunctionBodyEnd' function already checked whether we
29 // need ehinfo, and emitted a traceback table with the bits set to indicate that
30 // we will be emitting it, if so. Thus, if we remove it now -- so late in the
31 // process -- we'll end up having emitted a reference to __ehinfo.N symbol, but
32 // not emitting a definition for said symbol.
34 
35 void AIXException::emitExceptionInfoTable(const MCSymbol *LSDA,
36  const MCSymbol *PerSym) {
37  // Generate EH Info Table.
38  // The EH Info Table, aka, 'compat unwind section' on AIX, have the following
39  // format: struct eh_info_t {
40  // unsigned version; /* EH info verion 0 */
41  // #if defined(__64BIT__)
42  // char _pad[4]; /* padding */
43  // #endif
44  // unsigned long lsda; /* Pointer to LSDA */
45  // unsigned long personality; /* Pointer to the personality routine */
46  // }
47 
48  auto *EHInfo =
49  cast<MCSectionXCOFF>(Asm->getObjFileLowering().getCompactUnwindSection());
50  if (Asm->TM.getFunctionSections()) {
51  // If option -ffunction-sections is on, append the function name to the
52  // name of EH Info Table csect so that each function has its own EH Info
53  // Table csect. This helps the linker to garbage-collect EH info of unused
54  // functions.
55  SmallString<128> NameStr = EHInfo->getName();
56  raw_svector_ostream(NameStr) << '.' << Asm->MF->getFunction().getName();
57  EHInfo = Asm->OutContext.getXCOFFSection(NameStr, EHInfo->getKind(),
58  EHInfo->getCsectProp());
59  }
60  Asm->OutStreamer->switchSection(EHInfo);
61  MCSymbol *EHInfoLabel =
63  Asm->OutStreamer->emitLabel(EHInfoLabel);
64 
65  // Version number.
66  Asm->emitInt32(0);
67 
68  const DataLayout &DL = MMI->getModule()->getDataLayout();
69  const unsigned PointerSize = DL.getPointerSize();
70 
71  // Add necessary paddings in 64 bit mode.
72  Asm->OutStreamer->emitValueToAlignment(Align(PointerSize));
73 
74  // LSDA location.
76  PointerSize);
77 
78  // Personality routine.
80  PointerSize);
81 }
82 
84  // There is no easy way to access register information in `AIXException`
85  // class. when ShouldEmitEHBlock is false and VRs are saved, A dumy eh info
86  // table are emitted in PPCAIXAsmPrinter::emitFunctionBodyEnd.
88  return;
89 
90  const MCSymbol *LSDALabel = emitExceptionTable();
91 
92  const Function &F = MF->getFunction();
93  assert(F.hasPersonalityFn() &&
94  "Landingpads are presented, but no personality routine is found.");
95  const auto *Per =
96  cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());
97  const MCSymbol *PerSym = Asm->TM.getSymbol(Per);
98 
99  emitExceptionInfoTable(LSDALabel, PerSym);
100 }
101 
102 } // End of namespace llvm
AsmPrinter.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::Function
Definition: Function.h:60
llvm::AIXException::endFunction
void endFunction(const MachineFunction *MF) override
Gather post-function debug information.
Definition: AIXException.cpp:83
llvm::TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2278
llvm::EHStreamer::MMI
MachineModuleInfo * MMI
Collected machine module information.
Definition: EHStreamer.h:36
llvm::TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock
static bool ShouldEmitEHBlock(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2248
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::AIXException::AIXException
AIXException(AsmPrinter *A)
Definition: AIXException.cpp:24
TargetMachine.h
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:99
llvm::TargetMachine::getFunctionSections
bool getFunctionSections() const
Return true if functions should be emitted into their own section, corresponding to -ffunction-sectio...
Definition: TargetMachine.h:283
llvm::EHStreamer::emitExceptionTable
MCSymbol * emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:375
llvm::MCObjectFileInfo::getCompactUnwindSection
MCSection * getCompactUnwindSection() const
Definition: MCObjectFileInfo.h:268
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: TargetMachine.cpp:204
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
MCSectionXCOFF.h
llvm::SmallString< 128 >
llvm::DwarfCFIExceptionBase
Definition: DwarfException.h:24
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:102
llvm::AsmPrinter::OutContext
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:94
MachineModuleInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::EHStreamer::Asm
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:33
llvm::MCContext::getXCOFFSection
MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, const char *BeginSymName=nullptr, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)
Definition: MCContext.cpp:771
TargetLoweringObjectFile.h
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:623
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
llvm::AsmPrinter::emitInt32
void emitInt32(int Value) const
Emit a long directive and value.
Definition: AsmPrinter.cpp:2786
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:87
llvm::AsmPrinter::getObjFileLowering
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:384
MCStreamer.h
DwarfException.h
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
llvm::AIXException::markFunctionEnd
void markFunctionEnd() override
Definition: AIXException.cpp:33
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:398
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:150
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
TargetLoweringObjectFileImpl.h