Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/AIXException.cpp
35271 views
//===-- CodeGen/AsmPrinter/AIXException.cpp - AIX Exception Impl ----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains support for writing AIX exception info into asm files.9//10//===----------------------------------------------------------------------===//1112#include "DwarfException.h"13#include "llvm/CodeGen/AsmPrinter.h"14#include "llvm/CodeGen/MachineModuleInfo.h"15#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"16#include "llvm/IR/Module.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"2122namespace llvm {2324AIXException::AIXException(AsmPrinter *A) : EHStreamer(A) {}2526void AIXException::emitExceptionInfoTable(const MCSymbol *LSDA,27const MCSymbol *PerSym) {28// Generate EH Info Table.29// The EH Info Table, aka, 'compat unwind section' on AIX, have the following30// format: struct eh_info_t {31// unsigned version; /* EH info verion 0 */32// #if defined(__64BIT__)33// char _pad[4]; /* padding */34// #endif35// unsigned long lsda; /* Pointer to LSDA */36// unsigned long personality; /* Pointer to the personality routine */37// }3839auto *EHInfo =40cast<MCSectionXCOFF>(Asm->getObjFileLowering().getCompactUnwindSection());41if (Asm->TM.getFunctionSections()) {42// If option -ffunction-sections is on, append the function name to the43// name of EH Info Table csect so that each function has its own EH Info44// Table csect. This helps the linker to garbage-collect EH info of unused45// functions.46SmallString<128> NameStr = EHInfo->getName();47raw_svector_ostream(NameStr) << '.' << Asm->MF->getFunction().getName();48EHInfo = Asm->OutContext.getXCOFFSection(NameStr, EHInfo->getKind(),49EHInfo->getCsectProp());50}51Asm->OutStreamer->switchSection(EHInfo);52MCSymbol *EHInfoLabel =53TargetLoweringObjectFileXCOFF::getEHInfoTableSymbol(Asm->MF);54Asm->OutStreamer->emitLabel(EHInfoLabel);5556// Version number.57Asm->emitInt32(0);5859const DataLayout &DL = MMI->getModule()->getDataLayout();60const unsigned PointerSize = DL.getPointerSize();6162// Add necessary paddings in 64 bit mode.63Asm->OutStreamer->emitValueToAlignment(Align(PointerSize));6465// LSDA location.66Asm->OutStreamer->emitValue(MCSymbolRefExpr::create(LSDA, Asm->OutContext),67PointerSize);6869// Personality routine.70Asm->OutStreamer->emitValue(MCSymbolRefExpr::create(PerSym, Asm->OutContext),71PointerSize);72}7374void AIXException::endFunction(const MachineFunction *MF) {75// There is no easy way to access register information in `AIXException`76// class. when ShouldEmitEHBlock is false and VRs are saved, A dumy eh info77// table are emitted in PPCAIXAsmPrinter::emitFunctionBodyEnd.78if (!TargetLoweringObjectFileXCOFF::ShouldEmitEHBlock(MF))79return;8081const MCSymbol *LSDALabel = emitExceptionTable();8283const Function &F = MF->getFunction();84assert(F.hasPersonalityFn() &&85"Landingpads are presented, but no personality routine is found.");86const auto *Per =87cast<GlobalValue>(F.getPersonalityFn()->stripPointerCasts());88const MCSymbol *PerSym = Asm->TM.getSymbol(Per);8990emitExceptionInfoTable(LSDALabel, PerSym);91}9293} // End of namespace llvm949596