[llvm] r370540 - [MC] Avoid crashes from improperly nested or wrong target .seh_handlerdata directives
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 15:25:55 PDT 2019
Author: rnk
Date: Fri Aug 30 15:25:55 2019
New Revision: 370540
URL: http://llvm.org/viewvc/llvm-project?rev=370540&view=rev
Log:
[MC] Avoid crashes from improperly nested or wrong target .seh_handlerdata directives
Modified:
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp
llvm/trunk/test/MC/AsmParser/seh-directive-errors.s
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=370540&r1=370539&r2=370540&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Aug 30 15:25:55 2019
@@ -1748,6 +1748,12 @@ void MCAsmStreamer::EmitWinEHHandlerData
// We only do this so the section switch that terminates the handler
// data block is visible.
WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
+
+ // Do nothing if no frame is open. MCStreamer should've already reported an
+ // error.
+ if (!CurFrame)
+ return;
+
MCSection *TextSec = &CurFrame->Function->getSection();
MCSection *XData = getAssociatedXDataSection(TextSec);
SwitchSectionNoChange(XData);
Modified: llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp?rev=370540&r1=370539&r2=370540&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/COFFAsmParser.cpp Fri Aug 30 15:25:55 2019
@@ -69,6 +69,7 @@ class COFFAsmParser : public MCAsmParser
addDirectiveHandler<&COFFAsmParser::ParseDirectiveSecIdx>(".secidx");
addDirectiveHandler<&COFFAsmParser::ParseDirectiveLinkOnce>(".linkonce");
addDirectiveHandler<&COFFAsmParser::ParseDirectiveRVA>(".rva");
+ addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
// Win64 EH directives.
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveStartProc>(
@@ -87,7 +88,6 @@ class COFFAsmParser : public MCAsmParser
".seh_stackalloc");
addDirectiveHandler<&COFFAsmParser::ParseSEHDirectiveEndProlog>(
".seh_endprologue");
- addDirectiveHandler<&COFFAsmParser::ParseDirectiveSymbolAttribute>(".weak");
}
bool ParseSectionDirectiveText(StringRef, SMLoc) {
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp?rev=370540&r1=370539&r2=370540&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86WinCOFFStreamer.cpp Fri Aug 30 15:25:55 2019
@@ -35,8 +35,9 @@ void X86WinCOFFStreamer::EmitWinEHHandle
MCStreamer::EmitWinEHHandlerData(Loc);
// We have to emit the unwind info now, because this directive
- // actually switches to the .xdata section!
- EHStreamer.EmitUnwindInfo(*this, getCurrentWinFrameInfo());
+ // actually switches to the .xdata section.
+ if (WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo())
+ EHStreamer.EmitUnwindInfo(*this, CurFrame);
}
void X86WinCOFFStreamer::EmitWindowsUnwindTables() {
Modified: llvm/trunk/test/MC/AsmParser/seh-directive-errors.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/seh-directive-errors.s?rev=370540&r1=370539&r2=370540&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/seh-directive-errors.s (original)
+++ llvm/trunk/test/MC/AsmParser/seh-directive-errors.s Fri Aug 30 15:25:55 2019
@@ -1,6 +1,10 @@
# RUN: not llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
+# RUN: not llvm-mc -triple x86_64-windows-msvc %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
.text
+# CHECK: error: .seh_ directive must appear within an active frame
+ .seh_handlerdata
+
.seh_pushreg %rsi
# CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: .seh_ directive must appear within an active frame
More information about the llvm-commits
mailing list