2011-01-14 21:57:53 +00:00
|
|
|
//===-- CodeGen/AsmPrinter/DwarfException.cpp - Dwarf Exception Impl ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing DWARF exception info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DwarfException.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2011-07-18 22:29:13 +00:00
|
|
|
#include "llvm/MC/MachineLocation.h"
|
2011-01-14 21:57:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/Target/Mangler.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Support/Dwarf.h"
|
2011-04-15 15:11:06 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-01-14 21:57:53 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
DwarfCFIException::DwarfCFIException(AsmPrinter *A)
|
|
|
|
: DwarfException(A),
|
2011-05-10 21:54:59 +00:00
|
|
|
shouldEmitPersonality(false), shouldEmitLSDA(false), shouldEmitMoves(false),
|
|
|
|
moveTypeModule(AsmPrinter::CFI_M_None) {}
|
2011-01-14 21:57:53 +00:00
|
|
|
|
|
|
|
DwarfCFIException::~DwarfCFIException() {}
|
|
|
|
|
|
|
|
/// EndModule - Emit all exception information that should come after the
|
|
|
|
/// content.
|
|
|
|
void DwarfCFIException::EndModule() {
|
2011-05-10 18:39:09 +00:00
|
|
|
if (moveTypeModule == AsmPrinter::CFI_M_Debug)
|
|
|
|
Asm->OutStreamer.EmitCFISections(false, true);
|
|
|
|
|
2011-01-14 21:58:08 +00:00
|
|
|
if (!Asm->MAI->isExceptionHandlingDwarf())
|
2011-01-14 21:57:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
2011-04-29 15:09:53 +00:00
|
|
|
|
2011-01-14 21:57:53 +00:00
|
|
|
unsigned PerEncoding = TLOF.getPersonalityEncoding();
|
|
|
|
|
2011-04-15 15:11:06 +00:00
|
|
|
if ((PerEncoding & 0x70) != dwarf::DW_EH_PE_pcrel)
|
|
|
|
return;
|
|
|
|
|
2011-01-14 21:57:53 +00:00
|
|
|
// Emit references to all used personality functions
|
2011-05-02 15:49:52 +00:00
|
|
|
bool AtLeastOne = false;
|
2011-01-14 21:57:53 +00:00
|
|
|
const std::vector<const Function*> &Personalities = MMI->getPersonalities();
|
|
|
|
for (size_t i = 0, e = Personalities.size(); i != e; ++i) {
|
2011-04-29 14:48:51 +00:00
|
|
|
if (!Personalities[i])
|
|
|
|
continue;
|
|
|
|
MCSymbol *Sym = Asm->Mang->getSymbol(Personalities[i]);
|
2011-04-16 03:51:21 +00:00
|
|
|
TLOF.emitPersonalityValue(Asm->OutStreamer, Asm->TM, Sym);
|
2011-05-02 15:49:52 +00:00
|
|
|
AtLeastOne = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AtLeastOne && !TLOF.isFunctionEHFrameSymbolPrivate()) {
|
|
|
|
// This is a temporary hack to keep sections in the same order they
|
|
|
|
// were before. This lets us produce bit identical outputs while
|
|
|
|
// transitioning to CFI.
|
2011-07-20 05:58:47 +00:00
|
|
|
Asm->OutStreamer.SwitchSection(
|
|
|
|
const_cast<TargetLoweringObjectFile&>(TLOF).getEHFrameSection());
|
2011-01-14 21:57:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// BeginFunction - Gather pre-function exception information. Assumes it's
|
|
|
|
/// being emitted immediately after the function entry point.
|
|
|
|
void DwarfCFIException::BeginFunction(const MachineFunction *MF) {
|
2011-04-29 14:48:51 +00:00
|
|
|
shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
|
2011-01-14 21:57:53 +00:00
|
|
|
|
|
|
|
// If any landing pads survive, we need an EH table.
|
2011-04-29 14:48:51 +00:00
|
|
|
bool hasLandingPads = !MMI->getLandingPads().empty();
|
2011-01-14 21:57:53 +00:00
|
|
|
|
|
|
|
// See if we need frame move info.
|
2011-05-10 18:39:09 +00:00
|
|
|
AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
|
|
|
|
if (MoveType == AsmPrinter::CFI_M_EH ||
|
|
|
|
(MoveType == AsmPrinter::CFI_M_Debug &&
|
|
|
|
moveTypeModule == AsmPrinter::CFI_M_None))
|
|
|
|
moveTypeModule = MoveType;
|
|
|
|
|
|
|
|
shouldEmitMoves = MoveType != AsmPrinter::CFI_M_None;
|
2011-01-14 21:57:53 +00:00
|
|
|
|
2011-04-29 14:48:51 +00:00
|
|
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
|
|
|
unsigned PerEncoding = TLOF.getPersonalityEncoding();
|
|
|
|
const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()];
|
2011-01-14 21:57:53 +00:00
|
|
|
|
2011-04-29 14:48:51 +00:00
|
|
|
shouldEmitPersonality = hasLandingPads &&
|
|
|
|
PerEncoding != dwarf::DW_EH_PE_omit && Per;
|
2011-01-14 21:57:53 +00:00
|
|
|
|
2011-04-29 14:48:51 +00:00
|
|
|
unsigned LSDAEncoding = TLOF.getLSDAEncoding();
|
|
|
|
shouldEmitLSDA = shouldEmitPersonality &&
|
|
|
|
LSDAEncoding != dwarf::DW_EH_PE_omit;
|
2011-01-14 21:57:53 +00:00
|
|
|
|
2011-04-29 14:48:51 +00:00
|
|
|
if (!shouldEmitPersonality && !shouldEmitMoves)
|
2011-01-14 21:57:53 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-29 14:48:51 +00:00
|
|
|
Asm->OutStreamer.EmitCFIStartProc();
|
2011-01-14 21:57:53 +00:00
|
|
|
|
|
|
|
// Indicate personality routine, if any.
|
2011-04-29 14:48:51 +00:00
|
|
|
if (!shouldEmitPersonality)
|
2011-04-15 15:11:06 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-27 23:17:57 +00:00
|
|
|
const MCSymbol *Sym = TLOF.getCFIPersonalitySymbol(Per, Asm->Mang, MMI);
|
2011-04-15 15:11:06 +00:00
|
|
|
Asm->OutStreamer.EmitCFIPersonality(Sym, PerEncoding);
|
2011-04-29 14:48:51 +00:00
|
|
|
|
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
|
|
|
|
Asm->getFunctionNumber()));
|
|
|
|
|
|
|
|
// Provide LSDA information.
|
|
|
|
if (!shouldEmitLSDA)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Asm->OutStreamer.EmitCFILsda(Asm->GetTempSymbol("exception",
|
|
|
|
Asm->getFunctionNumber()),
|
|
|
|
LSDAEncoding);
|
2011-01-14 21:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EndFunction - Gather and emit post-function exception information.
|
|
|
|
///
|
|
|
|
void DwarfCFIException::EndFunction() {
|
2011-04-29 14:48:51 +00:00
|
|
|
if (!shouldEmitPersonality && !shouldEmitMoves)
|
|
|
|
return;
|
2011-01-14 21:57:53 +00:00
|
|
|
|
2011-04-24 19:55:34 +00:00
|
|
|
Asm->OutStreamer.EmitCFIEndProc();
|
2011-01-14 21:57:53 +00:00
|
|
|
|
2012-01-17 04:19:20 +00:00
|
|
|
if (!shouldEmitPersonality)
|
|
|
|
return;
|
|
|
|
|
2012-01-13 23:28:50 +00:00
|
|
|
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
|
|
|
|
Asm->getFunctionNumber()));
|
|
|
|
|
2011-01-14 21:57:53 +00:00
|
|
|
// Map all labels and get rid of any dead landing pads.
|
|
|
|
MMI->TidyLandingPads();
|
|
|
|
|
2012-01-17 04:19:20 +00:00
|
|
|
EmitExceptionTable();
|
2011-01-14 21:57:53 +00:00
|
|
|
}
|