LLVM  14.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 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 */
34  // #endif
35  // unsigned long lsda; /* Pointer to LSDA */
36  // unsigned long personality; /* Pointer to the personality routine */
37  // }
38 
39  Asm->OutStreamer->SwitchSection(
41  MCSymbol *EHInfoLabel =
43  Asm->OutStreamer->emitLabel(EHInfoLabel);
44 
45  // Version number.
46  Asm->emitInt32(0);
47 
48  const DataLayout &DL = MMI->getModule()->getDataLayout();
49  const unsigned PointerSize = DL.getPointerSize();
50 
51  // Add necessary paddings in 64 bit mode.
52  Asm->OutStreamer->emitValueToAlignment(PointerSize);
53 
54  // LSDA location.
56  PointerSize);
57 
58  // Personality routine.
60  PointerSize);
61 }
62 
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.
68  return;
69 
70  const MCSymbol *LSDALabel = emitExceptionTable();
71 
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);
78 
79  emitExceptionInfoTable(LSDALabel, PerSym);
80 }
81 
82 } // End of namespace llvm
AsmPrinter.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::Function
Definition: Function.h:61
llvm::AIXException::endFunction
void endFunction(const MachineFunction *MF) override
Gather post-function debug information.
Definition: AIXException.cpp:63
llvm::TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
Definition: TargetLoweringObjectFileImpl.cpp:2206
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:2176
F
#define F(x, y, z)
Definition: MD5.cpp:56
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:97
llvm::EHStreamer::emitExceptionTable
MCSymbol * emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:378
llvm::MCObjectFileInfo::getCompactUnwindSection
MCSection * getCompactUnwindSection() const
Definition: MCObjectFileInfo.h:263
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: TargetMachine.cpp:206
MCSectionXCOFF.h
llvm::DwarfCFIExceptionBase
Definition: DwarfException.h:24
llvm::GlobalValue
Definition: GlobalValue.h:44
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:100
llvm::AsmPrinter::OutContext
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:92
MachineModuleInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::EHStreamer::Asm
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:33
TargetLoweringObjectFile.h
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:592
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
llvm::AsmPrinter::emitInt32
void emitInt32(int Value) const
Emit a long directive and value.
Definition: AsmPrinter.cpp:2407
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:85
llvm::AsmPrinter::getObjFileLowering
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:224
MCStreamer.h
DwarfException.h
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:401
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:174
TargetLoweringObjectFileImpl.h