MC: rename EmitWin64EH routines

Rename the routines to reflect the reality that they are more related to call
frame information than to Win64 EH. Although EH is implemented in an intertwined
manner by augmenting with an exception handler and an associated parameter, the
majority of these routines emit information required to unwind the frames. This
also helps identify that these routines are generic for most windows platforms
(they apply equally to nearly all architectures except x86) although the
encoding of the information is architecture dependent.

Unwinding data is emitted via EmitWinCFI* and exception handling information via
EmitWinEH*.

llvm-svn: 211994
This commit is contained in:
Saleem Abdulrasool 2014-06-29 01:52:01 +00:00
parent 66e588be09
commit 7206a52522
9 changed files with 101 additions and 103 deletions

View File

@ -695,20 +695,20 @@ public:
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
virtual void EmitCFIWindowSave();
virtual void EmitWin64EHStartProc(const MCSymbol *Symbol);
virtual void EmitWin64EHEndProc();
virtual void EmitWin64EHStartChained();
virtual void EmitWin64EHEndChained();
virtual void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
bool Except);
virtual void EmitWin64EHHandlerData();
virtual void EmitWin64EHPushReg(unsigned Register);
virtual void EmitWin64EHSetFrame(unsigned Register, unsigned Offset);
virtual void EmitWin64EHAllocStack(unsigned Size);
virtual void EmitWin64EHSaveReg(unsigned Register, unsigned Offset);
virtual void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset);
virtual void EmitWin64EHPushFrame(bool Code);
virtual void EmitWin64EHEndProlog();
virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
virtual void EmitWinCFIEndProc();
virtual void EmitWinCFIStartChained();
virtual void EmitWinCFIEndChained();
virtual void EmitWinCFIPushReg(unsigned Register);
virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
virtual void EmitWinCFIAllocStack(unsigned Size);
virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
virtual void EmitWinCFIPushFrame(bool Code);
virtual void EmitWinCFIEndProlog();
virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
virtual void EmitWinEHHandlerData();
/// EmitInstruction - Emit the given @p Instruction into the current
/// section.

View File

@ -56,7 +56,7 @@ public:
unsigned ByteAlignment) override;
void EmitFileDirective(StringRef Filename) override;
void EmitIdent(StringRef IdentString) override;
void EmitWin64EHHandlerData() override;
void EmitWinEHHandlerData() override;
void FinishImpl() override;
/// \}

View File

@ -72,14 +72,14 @@ void Win64Exception::beginFunction(const MachineFunction *MF) {
if (!shouldEmitPersonality && !shouldEmitMoves)
return;
Asm->OutStreamer.EmitWin64EHStartProc(Asm->CurrentFnSym);
Asm->OutStreamer.EmitWinCFIStartProc(Asm->CurrentFnSym);
if (!shouldEmitPersonality)
return;
const MCSymbol *PersHandlerSym =
TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, Asm->TM, MMI);
Asm->OutStreamer.EmitWin64EHHandler(PersHandlerSym, true, true);
Asm->OutStreamer.EmitWinEHHandler(PersHandlerSym, true, true);
Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
Asm->getFunctionNumber()));
@ -99,9 +99,9 @@ void Win64Exception::endFunction(const MachineFunction *) {
if (shouldEmitPersonality) {
Asm->OutStreamer.PushSection();
Asm->OutStreamer.EmitWin64EHHandlerData();
Asm->OutStreamer.EmitWinEHHandlerData();
emitExceptionTable();
Asm->OutStreamer.PopSection();
}
Asm->OutStreamer.EmitWin64EHEndProc();
Asm->OutStreamer.EmitWinCFIEndProc();
}

View File

@ -212,20 +212,20 @@ public:
void EmitCFIRegister(int64_t Register1, int64_t Register2) override;
void EmitCFIWindowSave() override;
void EmitWin64EHStartProc(const MCSymbol *Symbol) override;
void EmitWin64EHEndProc() override;
void EmitWin64EHStartChained() override;
void EmitWin64EHEndChained() override;
void EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
bool Except) override;
void EmitWin64EHHandlerData() override;
void EmitWin64EHPushReg(unsigned Register) override;
void EmitWin64EHSetFrame(unsigned Register, unsigned Offset) override;
void EmitWin64EHAllocStack(unsigned Size) override;
void EmitWin64EHSaveReg(unsigned Register, unsigned Offset) override;
void EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) override;
void EmitWin64EHPushFrame(bool Code) override;
void EmitWin64EHEndProlog() override;
void EmitWinCFIStartProc(const MCSymbol *Symbol) override;
void EmitWinCFIEndProc() override;
void EmitWinCFIStartChained() override;
void EmitWinCFIEndChained() override;
void EmitWinCFIPushReg(unsigned Register) override;
void EmitWinCFISetFrame(unsigned Register, unsigned Offset) override;
void EmitWinCFIAllocStack(unsigned Size) override;
void EmitWinCFISaveReg(unsigned Register, unsigned Offset) override;
void EmitWinCFISaveXMM(unsigned Register, unsigned Offset) override;
void EmitWinCFIPushFrame(bool Code) override;
void EmitWinCFIEndProlog() override;
void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except) override;
void EmitWinEHHandlerData() override;
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
@ -1049,37 +1049,37 @@ void MCAsmStreamer::EmitCFIWindowSave() {
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) {
MCStreamer::EmitWin64EHStartProc(Symbol);
void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
MCStreamer::EmitWinCFIStartProc(Symbol);
OS << ".seh_proc " << *Symbol;
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHEndProc() {
MCStreamer::EmitWin64EHEndProc();
void MCAsmStreamer::EmitWinCFIEndProc() {
MCStreamer::EmitWinCFIEndProc();
OS << "\t.seh_endproc";
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHStartChained() {
MCStreamer::EmitWin64EHStartChained();
void MCAsmStreamer::EmitWinCFIStartChained() {
MCStreamer::EmitWinCFIStartChained();
OS << "\t.seh_startchained";
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHEndChained() {
MCStreamer::EmitWin64EHEndChained();
void MCAsmStreamer::EmitWinCFIEndChained() {
MCStreamer::EmitWinCFIEndChained();
OS << "\t.seh_endchained";
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
void MCAsmStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
bool Except) {
MCStreamer::EmitWin64EHHandler(Sym, Unwind, Except);
MCStreamer::EmitWinEHHandler(Sym, Unwind, Except);
OS << "\t.seh_handler " << *Sym;
if (Unwind)
@ -1102,8 +1102,8 @@ static const MCSection *getWin64EHTableSection(StringRef suffix,
SectionKind::getDataRel());
}
void MCAsmStreamer::EmitWin64EHHandlerData() {
MCStreamer::EmitWin64EHHandlerData();
void MCAsmStreamer::EmitWinEHHandlerData() {
MCStreamer::EmitWinEHHandlerData();
// Switch sections. Don't call SwitchSection directly, because that will
// cause the section switch to be visible in the emitted assembly.
@ -1119,43 +1119,43 @@ void MCAsmStreamer::EmitWin64EHHandlerData() {
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHPushReg(unsigned Register) {
MCStreamer::EmitWin64EHPushReg(Register);
void MCAsmStreamer::EmitWinCFIPushReg(unsigned Register) {
MCStreamer::EmitWinCFIPushReg(Register);
OS << "\t.seh_pushreg " << Register;
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
MCStreamer::EmitWin64EHSetFrame(Register, Offset);
void MCAsmStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
MCStreamer::EmitWinCFISetFrame(Register, Offset);
OS << "\t.seh_setframe " << Register << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHAllocStack(unsigned Size) {
MCStreamer::EmitWin64EHAllocStack(Size);
void MCAsmStreamer::EmitWinCFIAllocStack(unsigned Size) {
MCStreamer::EmitWinCFIAllocStack(Size);
OS << "\t.seh_stackalloc " << Size;
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
MCStreamer::EmitWin64EHSaveReg(Register, Offset);
void MCAsmStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) {
MCStreamer::EmitWinCFISaveReg(Register, Offset);
OS << "\t.seh_savereg " << Register << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
MCStreamer::EmitWin64EHSaveXMM(Register, Offset);
void MCAsmStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) {
MCStreamer::EmitWinCFISaveXMM(Register, Offset);
OS << "\t.seh_savexmm " << Register << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHPushFrame(bool Code) {
MCStreamer::EmitWin64EHPushFrame(Code);
void MCAsmStreamer::EmitWinCFIPushFrame(bool Code) {
MCStreamer::EmitWinCFIPushFrame(Code);
OS << "\t.seh_pushframe";
if (Code)
@ -1163,8 +1163,8 @@ void MCAsmStreamer::EmitWin64EHPushFrame(bool Code) {
EmitEOL();
}
void MCAsmStreamer::EmitWin64EHEndProlog(void) {
MCStreamer::EmitWin64EHEndProlog();
void MCAsmStreamer::EmitWinCFIEndProlog(void) {
MCStreamer::EmitWinCFIEndProlog();
OS << "\t.seh_endprologue";
EmitEOL();

View File

@ -523,25 +523,25 @@ bool COFFAsmParser::ParseSEHDirectiveStartProc(StringRef, SMLoc) {
MCSymbol *Symbol = getContext().GetOrCreateSymbol(SymbolID);
Lex();
getStreamer().EmitWin64EHStartProc(Symbol);
getStreamer().EmitWinCFIStartProc(Symbol);
return false;
}
bool COFFAsmParser::ParseSEHDirectiveEndProc(StringRef, SMLoc) {
Lex();
getStreamer().EmitWin64EHEndProc();
getStreamer().EmitWinCFIEndProc();
return false;
}
bool COFFAsmParser::ParseSEHDirectiveStartChained(StringRef, SMLoc) {
Lex();
getStreamer().EmitWin64EHStartChained();
getStreamer().EmitWinCFIStartChained();
return false;
}
bool COFFAsmParser::ParseSEHDirectiveEndChained(StringRef, SMLoc) {
Lex();
getStreamer().EmitWin64EHEndChained();
getStreamer().EmitWinCFIEndChained();
return false;
}
@ -567,13 +567,13 @@ bool COFFAsmParser::ParseSEHDirectiveHandler(StringRef, SMLoc) {
MCSymbol *handler = getContext().GetOrCreateSymbol(SymbolID);
Lex();
getStreamer().EmitWin64EHHandler(handler, unwind, except);
getStreamer().EmitWinEHHandler(handler, unwind, except);
return false;
}
bool COFFAsmParser::ParseSEHDirectiveHandlerData(StringRef, SMLoc) {
Lex();
getStreamer().EmitWin64EHHandlerData();
getStreamer().EmitWinEHHandlerData();
return false;
}
@ -586,7 +586,7 @@ bool COFFAsmParser::ParseSEHDirectivePushReg(StringRef, SMLoc L) {
return TokError("unexpected token in directive");
Lex();
getStreamer().EmitWin64EHPushReg(Reg);
getStreamer().EmitWinCFIPushReg(Reg);
return false;
}
@ -610,7 +610,7 @@ bool COFFAsmParser::ParseSEHDirectiveSetFrame(StringRef, SMLoc L) {
return TokError("unexpected token in directive");
Lex();
getStreamer().EmitWin64EHSetFrame(Reg, Off);
getStreamer().EmitWinCFISetFrame(Reg, Off);
return false;
}
@ -627,7 +627,7 @@ bool COFFAsmParser::ParseSEHDirectiveAllocStack(StringRef, SMLoc) {
return TokError("unexpected token in directive");
Lex();
getStreamer().EmitWin64EHAllocStack(Size);
getStreamer().EmitWinCFIAllocStack(Size);
return false;
}
@ -652,7 +652,7 @@ bool COFFAsmParser::ParseSEHDirectiveSaveReg(StringRef, SMLoc L) {
Lex();
// FIXME: Err on %xmm* registers
getStreamer().EmitWin64EHSaveReg(Reg, Off);
getStreamer().EmitWinCFISaveReg(Reg, Off);
return false;
}
@ -679,7 +679,7 @@ bool COFFAsmParser::ParseSEHDirectiveSaveXMM(StringRef, SMLoc L) {
Lex();
// FIXME: Err on non-%xmm* registers
getStreamer().EmitWin64EHSaveXMM(Reg, Off);
getStreamer().EmitWinCFISaveXMM(Reg, Off);
return false;
}
@ -700,13 +700,13 @@ bool COFFAsmParser::ParseSEHDirectivePushFrame(StringRef, SMLoc) {
return TokError("unexpected token in directive");
Lex();
getStreamer().EmitWin64EHPushFrame(Code);
getStreamer().EmitWinCFIPushFrame(Code);
return false;
}
bool COFFAsmParser::ParseSEHDirectiveEndProlog(StringRef, SMLoc) {
Lex();
getStreamer().EmitWin64EHEndProlog();
getStreamer().EmitWinCFIEndProlog();
return false;
}

View File

@ -425,7 +425,7 @@ void MCStreamer::EnsureValidW64UnwindInfo() {
report_fatal_error("No open Win64 EH frame function!");
}
void MCStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) {
void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame && !CurFrame->End)
report_fatal_error("Starting a function before ending the previous one!");
@ -436,7 +436,7 @@ void MCStreamer::EmitWin64EHStartProc(const MCSymbol *Symbol) {
setCurrentW64UnwindInfo(Frame);
}
void MCStreamer::EmitWin64EHEndProc() {
void MCStreamer::EmitWinCFIEndProc() {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame->ChainedParent)
@ -445,7 +445,7 @@ void MCStreamer::EmitWin64EHEndProc() {
EmitLabel(CurFrame->End);
}
void MCStreamer::EmitWin64EHStartChained() {
void MCStreamer::EmitWinCFIStartChained() {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *Frame = new MCWin64EHUnwindInfo;
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
@ -456,7 +456,7 @@ void MCStreamer::EmitWin64EHStartChained() {
setCurrentW64UnwindInfo(Frame);
}
void MCStreamer::EmitWin64EHEndChained() {
void MCStreamer::EmitWinCFIEndChained() {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (!CurFrame->ChainedParent)
@ -466,7 +466,7 @@ void MCStreamer::EmitWin64EHEndChained() {
CurrentW64UnwindInfo = CurFrame->ChainedParent;
}
void MCStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
bool Except) {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
@ -481,14 +481,14 @@ void MCStreamer::EmitWin64EHHandler(const MCSymbol *Sym, bool Unwind,
CurFrame->HandlesExceptions = true;
}
void MCStreamer::EmitWin64EHHandlerData() {
void MCStreamer::EmitWinEHHandlerData() {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame->ChainedParent)
report_fatal_error("Chained unwind areas can't have handlers!");
}
void MCStreamer::EmitWin64EHPushReg(unsigned Register) {
void MCStreamer::EmitWinCFIPushReg(unsigned Register) {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
MCSymbol *Label = getContext().CreateTempSymbol();
@ -497,7 +497,7 @@ void MCStreamer::EmitWin64EHPushReg(unsigned Register) {
CurFrame->Instructions.push_back(Inst);
}
void MCStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
void MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame->LastFrameInst >= 0)
@ -513,7 +513,7 @@ void MCStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
CurFrame->Instructions.push_back(Inst);
}
void MCStreamer::EmitWin64EHAllocStack(unsigned Size) {
void MCStreamer::EmitWinCFIAllocStack(unsigned Size) {
EnsureValidW64UnwindInfo();
if (Size & 7)
report_fatal_error("Misaligned stack allocation!");
@ -524,7 +524,7 @@ void MCStreamer::EmitWin64EHAllocStack(unsigned Size) {
CurFrame->Instructions.push_back(Inst);
}
void MCStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
void MCStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) {
EnsureValidW64UnwindInfo();
if (Offset & 7)
report_fatal_error("Misaligned saved register offset!");
@ -537,7 +537,7 @@ void MCStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
CurFrame->Instructions.push_back(Inst);
}
void MCStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
void MCStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) {
EnsureValidW64UnwindInfo();
if (Offset & 0x0F)
report_fatal_error("Misaligned saved vector register offset!");
@ -550,7 +550,7 @@ void MCStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
CurFrame->Instructions.push_back(Inst);
}
void MCStreamer::EmitWin64EHPushFrame(bool Code) {
void MCStreamer::EmitWinCFIPushFrame(bool Code) {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame->Instructions.size() > 0)
@ -561,7 +561,7 @@ void MCStreamer::EmitWin64EHPushFrame(bool Code) {
CurFrame->Instructions.push_back(Inst);
}
void MCStreamer::EmitWin64EHEndProlog() {
void MCStreamer::EmitWinCFIEndProlog() {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
CurFrame->PrologEnd = getContext().CreateTempSymbol();

View File

@ -238,7 +238,7 @@ void MCWinCOFFStreamer::EmitIdent(StringRef IdentString) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::EmitWin64EHHandlerData() {
void MCWinCOFFStreamer::EmitWinEHHandlerData() {
llvm_unreachable("not implemented");
}

View File

@ -19,12 +19,12 @@ public:
raw_ostream &OS)
: MCWinCOFFStreamer(C, AB, *CE, OS) { }
void EmitWin64EHHandlerData() override;
void EmitWinEHHandlerData() override;
void FinishImpl() override;
};
void X86WinCOFFStreamer::EmitWin64EHHandlerData() {
MCStreamer::EmitWin64EHHandlerData();
void X86WinCOFFStreamer::EmitWinEHHandlerData() {
MCStreamer::EmitWinEHHandlerData();
// We have to emit the unwind info now, because this directive
// actually switches to the .xdata section!

View File

@ -889,36 +889,34 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
return;
case X86::SEH_PushReg:
OutStreamer.EmitWin64EHPushReg(
RI->getSEHRegNum(MI->getOperand(0).getImm()));
OutStreamer.EmitWinCFIPushReg(RI->getSEHRegNum(MI->getOperand(0).getImm()));
return;
case X86::SEH_SaveReg:
OutStreamer.EmitWin64EHSaveReg(RI->getSEHRegNum(MI->getOperand(0).getImm()),
OutStreamer.EmitWinCFISaveReg(RI->getSEHRegNum(MI->getOperand(0).getImm()),
MI->getOperand(1).getImm());
return;
case X86::SEH_SaveXMM:
OutStreamer.EmitWin64EHSaveXMM(RI->getSEHRegNum(MI->getOperand(0).getImm()),
OutStreamer.EmitWinCFISaveXMM(RI->getSEHRegNum(MI->getOperand(0).getImm()),
MI->getOperand(1).getImm());
return;
case X86::SEH_StackAlloc:
OutStreamer.EmitWin64EHAllocStack(MI->getOperand(0).getImm());
OutStreamer.EmitWinCFIAllocStack(MI->getOperand(0).getImm());
return;
case X86::SEH_SetFrame:
OutStreamer.EmitWin64EHSetFrame(
RI->getSEHRegNum(MI->getOperand(0).getImm()),
OutStreamer.EmitWinCFISetFrame(RI->getSEHRegNum(MI->getOperand(0).getImm()),
MI->getOperand(1).getImm());
return;
case X86::SEH_PushFrame:
OutStreamer.EmitWin64EHPushFrame(MI->getOperand(0).getImm());
OutStreamer.EmitWinCFIPushFrame(MI->getOperand(0).getImm());
return;
case X86::SEH_EndPrologue:
OutStreamer.EmitWin64EHEndProlog();
OutStreamer.EmitWinCFIEndProlog();
return;
}