From b3be7371d59b9b4262dd0a440580ce67a889d81a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 3 Aug 2014 18:51:17 +0000 Subject: [PATCH] MC: rename Win64EHFrameInfo to WinEH::FrameInfo The frame information stored in this structure is driven by the requirements for Windows NT unwinding rather than Windows 64 specifically. As a result, this type can be shared across multiple architectures (ARM, AXP, MIPS, PPC, SH). Rename this class in preparation for adding support for supporting unwinding information for Windows on ARM. Take the opportunity to constify the members as everything except the ChainedParent is read-only. This required some adjustment to the label handling. llvm-svn: 214663 --- llvm/include/llvm/MC/MCStreamer.h | 8 +++---- llvm/include/llvm/MC/MCWin64EH.h | 21 +----------------- llvm/include/llvm/MC/MCWinEH.h | 35 ++++++++++++++++++++++++++++++ llvm/lib/MC/MCAsmStreamer.cpp | 2 +- llvm/lib/MC/MCStreamer.cpp | 45 +++++++++++++++++++++++---------------- llvm/lib/MC/MCWin64EH.cpp | 17 +++++++++------ 6 files changed, 78 insertions(+), 50 deletions(-) diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index 63a43d0..698bb83 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -181,8 +181,8 @@ class MCStreamer { MCSymbol *EmitCFICommon(); - std::vector WinFrameInfos; - MCWinFrameInfo *CurrentWinFrameInfo; + std::vector WinFrameInfos; + WinEH::FrameInfo *CurrentWinFrameInfo; void EnsureValidWinFrameInfo(); // SymbolOrdering - Tracks an index to represent the order @@ -204,7 +204,7 @@ protected: virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame); virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame); - MCWinFrameInfo *getCurrentWinFrameInfo() { + WinEH::FrameInfo *getCurrentWinFrameInfo() { return CurrentWinFrameInfo; } @@ -238,7 +238,7 @@ public: } unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); } - ArrayRef getWinFrameInfos() const { + ArrayRef getWinFrameInfos() const { return WinFrameInfos; } diff --git a/llvm/include/llvm/MC/MCWin64EH.h b/llvm/include/llvm/MC/MCWin64EH.h index 3df0d0a..be510d6 100644 --- a/llvm/include/llvm/MC/MCWin64EH.h +++ b/llvm/include/llvm/MC/MCWin64EH.h @@ -54,25 +54,6 @@ struct Instruction { }; } - struct MCWinFrameInfo { - MCWinFrameInfo() - : Begin(nullptr), End(nullptr),ExceptionHandler(nullptr), - Function(nullptr), PrologEnd(nullptr), Symbol(nullptr), - HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1), - ChainedParent(nullptr), Instructions() {} - MCSymbol *Begin; - MCSymbol *End; - const MCSymbol *ExceptionHandler; - const MCSymbol *Function; - MCSymbol *PrologEnd; - MCSymbol *Symbol; - bool HandlesUnwind; - bool HandlesExceptions; - int LastFrameInst; - MCWinFrameInfo *ChainedParent; - std::vector Instructions; - }; - class MCWin64EHUnwindEmitter { public: static StringRef GetSectionSuffix(const MCSymbol *func); @@ -80,7 +61,7 @@ struct Instruction { // This emits the unwind info sections (.pdata and .xdata in PE/COFF). // static void Emit(MCStreamer &streamer); - static void EmitUnwindInfo(MCStreamer &streamer, MCWinFrameInfo *info); + static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info); }; } // end namespace llvm diff --git a/llvm/include/llvm/MC/MCWinEH.h b/llvm/include/llvm/MC/MCWinEH.h index 1cd1b0f..8510ae1 100644 --- a/llvm/include/llvm/MC/MCWinEH.h +++ b/llvm/include/llvm/MC/MCWinEH.h @@ -10,6 +10,8 @@ #ifndef LLVM_MC_MCWINEH_H #define LLVM_MC_MCWINEH_H +#include + namespace llvm { class MCSymbol; @@ -23,6 +25,39 @@ struct Instruction { Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off) : Label(L), Offset(Off), Register(Reg), Operation(Op) {} }; + +struct FrameInfo { + const MCSymbol *Begin; + const MCSymbol *End; + const MCSymbol *ExceptionHandler; + const MCSymbol *Function; + const MCSymbol *PrologEnd; + const MCSymbol *Symbol; + + bool HandlesUnwind; + bool HandlesExceptions; + + int LastFrameInst; + const FrameInfo *ChainedParent; + std::vector Instructions; + + FrameInfo() + : Begin(nullptr), End(nullptr), ExceptionHandler(nullptr), + Function(nullptr), PrologEnd(nullptr), Symbol(nullptr), + HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1), + ChainedParent(nullptr), Instructions() {} + FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel) + : Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr), + Function(Function), PrologEnd(nullptr), Symbol(nullptr), + HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1), + ChainedParent(nullptr), Instructions() {} + FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel, + const FrameInfo *ChainedParent) + : Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr), + Function(Function), PrologEnd(nullptr), Symbol(nullptr), + HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1), + ChainedParent(ChainedParent), Instructions() {} +}; } } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 14f0f05..11d6de8 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -1109,7 +1109,7 @@ void MCAsmStreamer::EmitWinEHHandlerData() { // cause the section switch to be visible in the emitted assembly. // We only do this so the section switch that terminates the handler // data block is visible. - MCWinFrameInfo *CurFrame = getCurrentWinFrameInfo(); + WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo(); StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function); const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext()); if (xdataSect) diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 46e80cc..f4a47b9 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -429,11 +429,11 @@ void MCStreamer::EnsureValidWinFrameInfo() { void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) { if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End) report_fatal_error("Starting a function before ending the previous one!"); - MCWinFrameInfo *Frame = new MCWinFrameInfo; - Frame->Begin = getContext().CreateTempSymbol(); - Frame->Function = Symbol; - EmitLabel(Frame->Begin); - WinFrameInfos.push_back(Frame); + + MCSymbol *StartProc = getContext().CreateTempSymbol(); + EmitLabel(StartProc); + + WinFrameInfos.push_back(new WinEH::FrameInfo(Symbol, StartProc)); CurrentWinFrameInfo = WinFrameInfos.back(); } @@ -441,18 +441,20 @@ void MCStreamer::EmitWinCFIEndProc() { EnsureValidWinFrameInfo(); if (CurrentWinFrameInfo->ChainedParent) report_fatal_error("Not all chained regions terminated!"); - CurrentWinFrameInfo->End = getContext().CreateTempSymbol(); - EmitLabel(CurrentWinFrameInfo->End); + + MCSymbol *Label = getContext().CreateTempSymbol(); + EmitLabel(Label); + CurrentWinFrameInfo->End = Label; } void MCStreamer::EmitWinCFIStartChained() { EnsureValidWinFrameInfo(); - MCWinFrameInfo *Frame = new MCWinFrameInfo; - Frame->Begin = getContext().CreateTempSymbol(); - Frame->Function = CurrentWinFrameInfo->Function; - Frame->ChainedParent = CurrentWinFrameInfo; - EmitLabel(Frame->Begin); - WinFrameInfos.push_back(Frame); + + MCSymbol *StartProc = getContext().CreateTempSymbol(); + EmitLabel(StartProc); + + WinFrameInfos.push_back(new WinEH::FrameInfo(CurrentWinFrameInfo->Function, + StartProc, CurrentWinFrameInfo)); CurrentWinFrameInfo = WinFrameInfos.back(); } @@ -460,9 +462,13 @@ void MCStreamer::EmitWinCFIEndChained() { EnsureValidWinFrameInfo(); if (!CurrentWinFrameInfo->ChainedParent) report_fatal_error("End of a chained region outside a chained region!"); - CurrentWinFrameInfo->End = getContext().CreateTempSymbol(); - EmitLabel(CurrentWinFrameInfo->End); - CurrentWinFrameInfo = CurrentWinFrameInfo->ChainedParent; + + MCSymbol *Label = getContext().CreateTempSymbol(); + EmitLabel(Label); + + CurrentWinFrameInfo->End = Label; + CurrentWinFrameInfo = + const_cast(CurrentWinFrameInfo->ChainedParent); } void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, @@ -567,8 +573,11 @@ void MCStreamer::EmitWinCFIPushFrame(bool Code) { void MCStreamer::EmitWinCFIEndProlog() { EnsureValidWinFrameInfo(); - CurrentWinFrameInfo->PrologEnd = getContext().CreateTempSymbol(); - EmitLabel(CurrentWinFrameInfo->PrologEnd); + + MCSymbol *Label = getContext().CreateTempSymbol(); + EmitLabel(Label); + + CurrentWinFrameInfo->PrologEnd = Label; } void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) { diff --git a/llvm/lib/MC/MCWin64EH.cpp b/llvm/lib/MC/MCWin64EH.cpp index 95e1983..e59854c 100644 --- a/llvm/lib/MC/MCWin64EH.cpp +++ b/llvm/lib/MC/MCWin64EH.cpp @@ -56,7 +56,7 @@ static void EmitAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS, Streamer.EmitAbsValue(Diff, 1); } -static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin, +static void EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin, WinEH::Instruction &inst) { uint8_t b2; uint16_t w; @@ -136,7 +136,7 @@ static void EmitSymbolRefWithOfs(MCStreamer &streamer, } static void EmitRuntimeFunction(MCStreamer &streamer, - const MCWinFrameInfo *info) { + const WinEH::FrameInfo *info) { MCContext &context = streamer.getContext(); streamer.EmitValueToAlignment(4); @@ -147,14 +147,17 @@ static void EmitRuntimeFunction(MCStreamer &streamer, context), 4); } -static void EmitUnwindInfo(MCStreamer &streamer, MCWinFrameInfo *info) { +static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) { // If this UNWIND_INFO already has a symbol, it's already been emitted. - if (info->Symbol) return; + if (info->Symbol) + return; MCContext &context = streamer.getContext(); + MCSymbol *Label = context.CreateTempSymbol(); + streamer.EmitValueToAlignment(4); - info->Symbol = context.CreateTempSymbol(); - streamer.EmitLabel(info->Symbol); + streamer.EmitLabel(Label); + info->Symbol = Label; // Upper 3 bits are the version number (currently 1). uint8_t flags = 0x01; @@ -256,7 +259,7 @@ static const MCSection *getWin64EHFuncTableSection(StringRef suffix, } void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer, - MCWinFrameInfo *info) { + WinEH::FrameInfo *info) { // Switch sections (the static function above is meant to be called from // here and from Emit(). MCContext &context = streamer.getContext(); -- 2.7.4