[llvm] r241877 - [WinEH] Make sure LSDA tables are 4 byte aligned

Reid Kleckner reid at kleckner.net
Thu Jul 9 17:08:49 PDT 2015


Author: rnk
Date: Thu Jul  9 19:08:49 2015
New Revision: 241877

URL: http://llvm.org/viewvc/llvm-project?rev=241877&view=rev
Log:
[WinEH] Make sure LSDA tables are 4 byte aligned

Apparently this is important, otherwise _except_handler3 assumes that
the registration node is corrupted and ignores it.

Also fix a bug in WinEHPrepare where we would insert code after a
terminator instruction.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
    llvm/trunk/lib/Target/X86/X86WinEHState.cpp
    llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll
    llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch.ll
    llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-cleanups.ll
    llvm/trunk/test/CodeGen/X86/seh-catch-all-win32.ll
    llvm/trunk/test/CodeGen/X86/win32-eh.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp Thu Jul  9 19:08:49 2015
@@ -350,6 +350,7 @@ void WinException::emitCXXFrameHandler3T
   // EHFlags & 1 -> Synchronous exceptions only, no async exceptions.
   // EHFlags & 2 -> ???
   // EHFlags & 4 -> The function is noexcept(true), unwinding can't continue.
+  OS.EmitValueToAlignment(4);
   OS.EmitLabel(FuncInfoXData);
   OS.EmitIntValue(0x19930522, 4);                      // MagicNumber
   OS.EmitIntValue(FuncInfo.UnwindMap.size(), 4);       // MaxState
@@ -578,6 +579,7 @@ void WinException::emitExceptHandlerTabl
 
   // Emit the __ehtable label that we use for llvm.x86.seh.lsda.
   MCSymbol *LSDALabel = Asm->OutContext.getOrCreateLSDASymbol(FLinkageName);
+  OS.EmitValueToAlignment(4);
   OS.EmitLabel(LSDALabel);
 
   const Function *Per = MMI->getPersonality();

Modified: llvm/trunk/lib/Target/X86/X86WinEHState.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86WinEHState.cpp?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86WinEHState.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86WinEHState.cpp Thu Jul  9 19:08:49 2015
@@ -440,8 +440,10 @@ int WinEHStatePass::escapeRegNode(Functi
 
   // Replace the call (if it exists) with new one. Otherwise, insert at the end
   // of the entry block.
-  IRBuilder<> Builder(&F.getEntryBlock(),
-                      EscapeCall ? EscapeCall : F.getEntryBlock().end());
+  Instruction *InsertPt = EscapeCall;
+  if (!EscapeCall)
+    InsertPt = F.getEntryBlock().getTerminator();
+  IRBuilder<> Builder(&F.getEntryBlock(), InsertPt);
   Builder.CreateCall(FrameEscape, Args);
   if (EscapeCall)
     EscapeCall->eraseFromParent();

Modified: llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll (original)
+++ llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch-reordered.ll Thu Jul  9 19:08:49 2015
@@ -114,6 +114,7 @@ stub:
 ; CHECK:        .seh_handlerdata
 ; CHECK:        .long   ($cppxdata$main)@IMGREL
 
+; CHECK: .align 4
 ; CHECK-NEXT: $cppxdata$main:
 ; CHECK-NEXT:         .long   429065506
 ; CHECK-NEXT:         .long   2

Modified: llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch.ll?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch.ll (original)
+++ llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-catch.ll Thu Jul  9 19:08:49 2015
@@ -121,6 +121,7 @@ try.cont8:
 ; CHECK-NOT: jmpq *
 ; CHECK:             .seh_handlerdata
 ; CHECK-NEXT:        .long   ("$cppxdata$?f@@YAXXZ")@IMGREL
+; CHECK-NEXT: .align 4
 ; CHECK-NEXT:"$cppxdata$?f@@YAXXZ":
 ; CHECK-NEXT:        .long   429065506
 ; CHECK-NEXT:        .long   4

Modified: llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-cleanups.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-cleanups.ll?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-cleanups.ll (original)
+++ llvm/trunk/test/CodeGen/WinEH/cppeh-prepared-cleanups.ll Thu Jul  9 19:08:49 2015
@@ -30,6 +30,7 @@ $_TI1H = comdat any
 ; CHECK-LABEL: "?test1@@YAXXZ":
 ; CHECK:             .seh_handlerdata
 ; CHECK-NEXT:        .long   ("$cppxdata$?test1@@YAXXZ")@IMGREL
+; CHECK-NEXT: .align 4
 ; CHECK-NEXT:"$cppxdata$?test1@@YAXXZ":
 ; CHECK-NEXT:        .long   429065506
 ; CHECK-NEXT:        .long   1
@@ -92,6 +93,7 @@ entry:
 ; CHECK-LABEL: "?test2@@YAX_N at Z":
 ; CHECK:             .seh_handlerdata
 ; CHECK-NEXT:        .long   ("$cppxdata$?test2@@YAX_N at Z")@IMGREL
+; CHECK-NEXT: .align 4
 ; CHECK-NEXT:"$cppxdata$?test2@@YAX_N at Z":
 ; CHECK-NEXT:        .long   429065506
 ; CHECK-NEXT:        .long   2

Modified: llvm/trunk/test/CodeGen/X86/seh-catch-all-win32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/seh-catch-all-win32.ll?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/seh-catch-all-win32.ll (original)
+++ llvm/trunk/test/CodeGen/X86/seh-catch-all-win32.ll Thu Jul  9 19:08:49 2015
@@ -90,6 +90,7 @@ entry:
 
 ; CHECK: .section .xdata,"dr"
 ; CHECK: Lmain$parent_frame_offset = Lmain$frame_escape_1
+; CHECK: .align 4
 ; CHECK: L__ehtable$main
 ; CHECK-NEXT: .long -1
 ; CHECK-NEXT: .long _filt$main

Modified: llvm/trunk/test/CodeGen/X86/win32-eh.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win32-eh.ll?rev=241877&r1=241876&r2=241877&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win32-eh.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win32-eh.ll Thu Jul  9 19:08:49 2015
@@ -132,6 +132,7 @@ catchall:
 ; CHECK: retl
 
 ; CHECK: .section .xdata,"dr"
+; CHECK: .align 4
 ; CHECK-LABEL: L__ehtable$use_CxxFrameHandler3:
 ; CHECK-NEXT:  .long   429065506
 ; CHECK-NEXT:  .long   2





More information about the llvm-commits mailing list