2009-05-15 09:12:28 +08:00
|
|
|
//===-- DwarfException.h - Dwarf Exception Framework -----------*- C++ -*--===//
|
|
|
|
//
|
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
|
2009-05-15 09:12:28 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing dwarf exception info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
|
2009-05-15 09:12:28 +08:00
|
|
|
|
2014-06-11 09:19:03 +08:00
|
|
|
#include "EHStreamer.h"
|
2011-05-11 02:39:09 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2016-02-27 04:30:37 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2009-05-15 09:12:28 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2010-04-05 13:28:23 +08:00
|
|
|
class MachineFunction;
|
2013-10-08 21:08:17 +08:00
|
|
|
class ARMTargetStreamer;
|
2011-01-15 05:57:45 +08:00
|
|
|
|
2015-07-02 00:18:16 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY DwarfCFIExceptionBase : public EHStreamer {
|
2015-03-10 02:29:12 +08:00
|
|
|
protected:
|
|
|
|
DwarfCFIExceptionBase(AsmPrinter *A);
|
|
|
|
|
|
|
|
/// Per-function flag to indicate if frame CFI info should be emitted.
|
|
|
|
bool shouldEmitCFI;
|
2017-01-03 02:05:27 +08:00
|
|
|
/// Per-module flag to indicate if .cfi_section has beeen emitted.
|
|
|
|
bool hasEmittedCFISections;
|
2015-03-10 02:29:12 +08:00
|
|
|
|
|
|
|
void markFunctionEnd() override;
|
2016-02-27 04:30:37 +08:00
|
|
|
void endFragment() override;
|
2015-03-10 02:29:12 +08:00
|
|
|
};
|
|
|
|
|
2015-07-02 00:18:16 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public DwarfCFIExceptionBase {
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Per-function flag to indicate if .cfi_personality should be emitted.
|
2011-04-29 22:48:51 +08:00
|
|
|
bool shouldEmitPersonality;
|
|
|
|
|
2016-02-27 04:30:37 +08:00
|
|
|
/// Per-function flag to indicate if .cfi_personality must be emitted.
|
|
|
|
bool forceEmitPersonality;
|
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Per-function flag to indicate if .cfi_lsda should be emitted.
|
2011-04-29 22:48:51 +08:00
|
|
|
bool shouldEmitLSDA;
|
2011-01-15 05:57:53 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Main entry points.
|
|
|
|
//
|
|
|
|
DwarfCFIException(AsmPrinter *A);
|
2015-04-11 10:11:45 +08:00
|
|
|
~DwarfCFIException() override;
|
2011-01-15 05:57:53 +08:00
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Emit all exception information that should come after the content.
|
2014-03-08 14:31:39 +08:00
|
|
|
void endModule() override;
|
2009-05-15 09:12:28 +08:00
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Gather pre-function exception information. Assumes being emitted
|
|
|
|
/// immediately after the function entry point.
|
2014-03-08 14:31:39 +08:00
|
|
|
void beginFunction(const MachineFunction *MF) override;
|
2009-05-15 09:12:28 +08:00
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Gather and emit post-function exception information.
|
2014-03-08 14:31:39 +08:00
|
|
|
void endFunction(const MachineFunction *) override;
|
2016-02-27 04:30:37 +08:00
|
|
|
|
|
|
|
void beginFragment(const MachineBasicBlock *MBB,
|
|
|
|
ExceptionSymbolProvider ESP) override;
|
Call Frame Information (CFI) Handling for Basic Block Sections
This patch handles CFI with basic block sections, which unlike DebugInfo does
not support ranges. The DWARF standard explicitly requires emitting separate
CFI Frame Descriptor Entries for each contiguous fragment of a function. Thus,
the CFI information for all callee-saved registers (possibly including the
frame pointer, if necessary) have to be emitted along with redefining the
Call Frame Address (CFA), viz. where the current frame starts.
CFI directives are emitted in FDE’s in the object file with a low_pc, high_pc
specification. So, a single FDE must point to a contiguous code region unlike
debug info which has the support for ranges. This is what complicates CFI for
basic block sections.
Now, what happens when we start placing individual basic blocks in unique
sections:
* Basic block sections allow the linker to randomly reorder basic blocks in the
address space such that a given basic block can become non-contiguous with the
original function.
* The different basic block sections can no longer share the cfi_startproc and
cfi_endproc directives. So, each basic block section should emit this
independently.
* Each (cfi_startproc, cfi_endproc) directive will result in a new FDE that
caters to that basic block section.
* Now, this basic block section needs to duplicate the information from the
entry block to compute the CFA as it is an independent entity. It cannot refer
to the FDE of the original function and hence must duplicate all the stuff that
is needed to compute the CFA on its own.
* We are working on a de-duplication patch that can share common information in
FDEs in a CIE (Common Information Entry) and we will present this as a follow up
patch. This can significantly reduce the duplication overhead and is
particularly useful when several basic block sections are created.
* The CFI directives are emitted similarly for registers that are pushed onto
the stack, like callee saved registers in the prologue. There are cfi
directives that emit how to retrieve the value of the register at that point
when the push happened. This has to be duplicated too in a basic block that is
floated as a separate section.
Differential Revision: https://reviews.llvm.org/D79978
2020-07-15 02:55:41 +08:00
|
|
|
|
|
|
|
void beginBasicBlock(const MachineBasicBlock &MBB) override;
|
|
|
|
void endBasicBlock(const MachineBasicBlock &MBB) override;
|
2009-05-15 09:12:28 +08:00
|
|
|
};
|
|
|
|
|
2015-07-02 00:18:16 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY ARMException : public DwarfCFIExceptionBase {
|
2018-02-10 01:00:25 +08:00
|
|
|
void emitTypeInfos(unsigned TTypeEncoding, MCSymbol *TTBaseLabel) override;
|
2013-10-08 21:08:17 +08:00
|
|
|
ARMTargetStreamer &getTargetStreamer();
|
|
|
|
|
2011-03-06 02:43:15 +08:00
|
|
|
public:
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Main entry points.
|
|
|
|
//
|
|
|
|
ARMException(AsmPrinter *A);
|
2015-04-11 10:11:45 +08:00
|
|
|
~ARMException() override;
|
2011-03-06 02:43:15 +08:00
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Emit all exception information that should come after the content.
|
2017-01-03 02:05:27 +08:00
|
|
|
void endModule() override {}
|
2011-03-06 02:43:15 +08:00
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Gather pre-function exception information. Assumes being emitted
|
|
|
|
/// immediately after the function entry point.
|
2014-03-08 14:31:39 +08:00
|
|
|
void beginFunction(const MachineFunction *MF) override;
|
2011-03-06 02:43:15 +08:00
|
|
|
|
2015-03-10 02:11:42 +08:00
|
|
|
/// Gather and emit post-function exception information.
|
2014-03-08 14:31:39 +08:00
|
|
|
void endFunction(const MachineFunction *) override;
|
2011-03-06 02:43:15 +08:00
|
|
|
};
|
2020-12-02 22:48:52 +08:00
|
|
|
|
|
|
|
class LLVM_LIBRARY_VISIBILITY AIXException : public DwarfCFIExceptionBase {
|
|
|
|
/// This is AIX's compat unwind section, which unwinder would use
|
|
|
|
/// to find the location of LSDA area and personality rountine.
|
|
|
|
void emitExceptionInfoTable(const MCSymbol *LSDA, const MCSymbol *PerSym);
|
|
|
|
|
|
|
|
public:
|
|
|
|
AIXException(AsmPrinter *A);
|
|
|
|
|
|
|
|
void endModule() override {}
|
|
|
|
void beginFunction(const MachineFunction *MF) override {}
|
|
|
|
|
|
|
|
void endFunction(const MachineFunction *MF) override;
|
|
|
|
};
|
2009-05-15 09:12:28 +08:00
|
|
|
} // End of namespace llvm
|
|
|
|
|
|
|
|
#endif
|