2011-03-06 02:43:15 +08:00
|
|
|
//===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-03-06 02:43:15 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing DWARF exception info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DwarfException.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2011-03-06 02:43:15 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2011-03-06 02:43:15 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2011-03-06 02:43:15 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-03-10 02:29:12 +08:00
|
|
|
ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {}
|
2011-03-06 02:43:15 +08:00
|
|
|
|
|
|
|
ARMException::~ARMException() {}
|
|
|
|
|
2013-10-08 21:08:17 +08:00
|
|
|
ARMTargetStreamer &ARMException::getTargetStreamer() {
|
2015-04-25 03:11:51 +08:00
|
|
|
MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
|
2013-10-08 21:08:17 +08:00
|
|
|
return static_cast<ARMTargetStreamer &>(TS);
|
|
|
|
}
|
|
|
|
|
2013-11-26 21:34:55 +08:00
|
|
|
void ARMException::beginFunction(const MachineFunction *MF) {
|
2014-05-01 06:43:13 +08:00
|
|
|
if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
|
|
|
|
getTargetStreamer().emitFnStart();
|
2014-02-15 01:19:07 +08:00
|
|
|
// See if we need call frame info.
|
2021-04-28 08:27:29 +08:00
|
|
|
AsmPrinter::CFISection CFISecType = Asm->getFunctionCFISectionType(*MF);
|
|
|
|
assert(CFISecType != AsmPrinter::CFISection::EH &&
|
2014-02-15 01:19:07 +08:00
|
|
|
"non-EH CFI not yet supported in prologue with EHABI lowering");
|
2017-01-03 02:05:27 +08:00
|
|
|
|
2021-04-28 08:27:29 +08:00
|
|
|
if (CFISecType == AsmPrinter::CFISection::Debug) {
|
2017-01-03 02:05:27 +08:00
|
|
|
if (!hasEmittedCFISections) {
|
2021-04-28 08:27:29 +08:00
|
|
|
if (Asm->getModuleCFISectionType() == AsmPrinter::CFISection::Debug)
|
2020-02-14 13:58:16 +08:00
|
|
|
Asm->OutStreamer->emitCFISections(false, true);
|
2017-01-03 02:05:27 +08:00
|
|
|
hasEmittedCFISections = true;
|
|
|
|
}
|
|
|
|
|
2014-02-15 01:19:07 +08:00
|
|
|
shouldEmitCFI = true;
|
2020-02-14 13:58:16 +08:00
|
|
|
Asm->OutStreamer->emitCFIStartProc(false);
|
2014-02-15 01:19:07 +08:00
|
|
|
}
|
2011-03-06 02:43:15 +08:00
|
|
|
}
|
|
|
|
|
2013-11-26 21:34:55 +08:00
|
|
|
/// endFunction - Gather and emit post-function exception information.
|
2011-03-06 02:43:15 +08:00
|
|
|
///
|
2015-03-10 02:29:12 +08:00
|
|
|
void ARMException::endFunction(const MachineFunction *MF) {
|
2013-10-08 21:08:17 +08:00
|
|
|
ARMTargetStreamer &ATS = getTargetStreamer();
|
2017-12-16 06:22:58 +08:00
|
|
|
const Function &F = MF->getFunction();
|
2015-07-15 03:22:51 +08:00
|
|
|
const Function *Per = nullptr;
|
2017-12-16 06:22:58 +08:00
|
|
|
if (F.hasPersonalityFn())
|
|
|
|
Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
|
2015-07-15 03:22:51 +08:00
|
|
|
bool forceEmitPersonality =
|
2017-12-16 06:22:58 +08:00
|
|
|
F.hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) &&
|
|
|
|
F.needsUnwindTableEntry();
|
2015-07-15 03:22:51 +08:00
|
|
|
bool shouldEmitPersonality = forceEmitPersonality ||
|
2016-12-02 03:32:15 +08:00
|
|
|
!MF->getLandingPads().empty();
|
2017-12-16 06:22:58 +08:00
|
|
|
if (!Asm->MF->getFunction().needsUnwindTableEntry() &&
|
2015-07-15 03:22:51 +08:00
|
|
|
!shouldEmitPersonality)
|
2013-10-08 21:08:17 +08:00
|
|
|
ATS.emitCantUnwind();
|
2015-07-15 03:22:51 +08:00
|
|
|
else if (shouldEmitPersonality) {
|
|
|
|
// Emit references to personality.
|
|
|
|
if (Per) {
|
|
|
|
MCSymbol *PerSym = Asm->getSymbol(Per);
|
|
|
|
ATS.emitPersonality(PerSym);
|
|
|
|
}
|
2012-11-15 03:13:30 +08:00
|
|
|
|
2015-07-15 03:22:51 +08:00
|
|
|
// Emit .handlerdata directive.
|
|
|
|
ATS.emitHandlerData();
|
2011-03-06 02:43:15 +08:00
|
|
|
|
2015-07-15 03:22:51 +08:00
|
|
|
// Emit actual exception table
|
|
|
|
emitExceptionTable();
|
2011-03-06 02:43:15 +08:00
|
|
|
}
|
|
|
|
|
2014-05-01 06:43:13 +08:00
|
|
|
if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
|
|
|
|
ATS.emitFnEnd();
|
2011-03-06 02:43:15 +08:00
|
|
|
}
|
2012-11-20 05:06:26 +08:00
|
|
|
|
2018-02-10 01:00:25 +08:00
|
|
|
void ARMException::emitTypeInfos(unsigned TTypeEncoding,
|
|
|
|
MCSymbol *TTBaseLabel) {
|
2016-12-02 03:32:15 +08:00
|
|
|
const MachineFunction *MF = Asm->MF;
|
|
|
|
const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
|
|
|
|
const std::vector<unsigned> &FilterIds = MF->getFilterIds();
|
2012-11-20 05:06:26 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
|
2012-11-20 05:06:26 +08:00
|
|
|
|
|
|
|
int Entry = 0;
|
|
|
|
// Emit the Catch TypeInfos.
|
|
|
|
if (VerboseAsm && !TypeInfos.empty()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
|
|
|
|
Asm->OutStreamer->AddBlankLine();
|
2012-11-20 05:06:26 +08:00
|
|
|
Entry = TypeInfos.size();
|
|
|
|
}
|
|
|
|
|
2015-07-30 06:19:09 +08:00
|
|
|
for (const GlobalValue *GV : reverse(TypeInfos)) {
|
2012-11-20 05:06:26 +08:00
|
|
|
if (VerboseAsm)
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
|
2020-02-14 08:36:27 +08:00
|
|
|
Asm->emitTTypeReference(GV, TTypeEncoding);
|
2012-11-20 05:06:26 +08:00
|
|
|
}
|
|
|
|
|
2020-02-15 11:21:58 +08:00
|
|
|
Asm->OutStreamer->emitLabel(TTBaseLabel);
|
2018-02-10 01:00:25 +08:00
|
|
|
|
2012-11-20 05:06:26 +08:00
|
|
|
// Emit the Exception Specifications.
|
|
|
|
if (VerboseAsm && !FilterIds.empty()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
|
|
|
|
Asm->OutStreamer->AddBlankLine();
|
2012-11-20 05:06:26 +08:00
|
|
|
Entry = 0;
|
|
|
|
}
|
|
|
|
for (std::vector<unsigned>::const_iterator
|
|
|
|
I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
|
|
|
|
unsigned TypeID = *I;
|
|
|
|
if (VerboseAsm) {
|
|
|
|
--Entry;
|
|
|
|
if (TypeID != 0)
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
|
2012-11-20 05:06:26 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 08:36:27 +08:00
|
|
|
Asm->emitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
|
2012-11-20 05:17:20 +08:00
|
|
|
TTypeEncoding);
|
2012-11-20 05:06:26 +08:00
|
|
|
}
|
|
|
|
}
|