[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54357] trunk/lib/win64/llvm: Fixes #33829 , OSL crashing with image textures on Windows 8 64 bit.

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Feb 6 20:45:36 CET 2013


Revision: 54357
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54357
Author:   blendix
Date:     2013-02-06 19:45:36 +0000 (Wed, 06 Feb 2013)
Log Message:
-----------
Fixes #33829, OSL crashing with image textures on Windows 8 64 bit. The cause
is a bug in LLVM that makes the alloca operation fail in JIT compiled and
executed code, I used the patch from here to fix it:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120220/137532.html

Modified Paths:
--------------
    trunk/lib/win64/llvm/lib/LLVMX86CodeGen.lib
    trunk/lib/win64/llvm/readme.txt

Added Paths:
-----------
    trunk/lib/win64/llvm/llvm-alloca-fix.patch

Modified: trunk/lib/win64/llvm/lib/LLVMX86CodeGen.lib
===================================================================
(Binary files differ)

Added: trunk/lib/win64/llvm/llvm-alloca-fix.patch
===================================================================
--- trunk/lib/win64/llvm/llvm-alloca-fix.patch	                        (rev 0)
+++ trunk/lib/win64/llvm/llvm-alloca-fix.patch	2013-02-06 19:45:36 UTC (rev 54357)
@@ -0,0 +1,111 @@
+Index: lib/Target/X86/X86ISelLowering.cpp
+===================================================================
+--- lib/Target/X86/X86ISelLowering.cpp	(revision 150916)
++++ lib/Target/X86/X86ISelLowering.cpp	(working copy)
+@@ -12222,12 +12222,36 @@
+   // non-trivial part is impdef of ESP.
+ 
+   if (Subtarget->isTargetWin64()) {
++    const char *StackProbeSymbol = 
++      Subtarget->isTargetCygMing() ? "___chkstk" : "__chkstk";
++      
++    MachineInstrBuilder MIB;
++    
++    if (getTargetMachine().getCodeModel() == CodeModel::Large) {
++      // For large code model we need to do indirect call to __chkstk.
++    
++      // R11 will be used to contain the address of __chkstk.
++      // R11 is a volotiale register and assumed to be destoyed by the callee, 
++      // so there is no need to save and restore it.
++      BuildMI(*BB, MI, DL, TII->get(X86::MOV64ri), X86::R11)
++        .addExternalSymbol(StackProbeSymbol);
++      // Create a call to __chkstk function which address contained in R11.
++      MIB = BuildMI(*BB, MI, DL, TII->get(X86::CALL64r))
++                    .addReg(X86::R11, RegState::Kill);
++                  
++    } else {
++      
++      // For non-large code model we can do direct call to __chkstk.
++      
++      MIB = BuildMI(*BB, MI, DL, TII->get(X86::W64ALLOCA))
++              .addExternalSymbol(StackProbeSymbol);
++    }
++  
+     if (Subtarget->isTargetCygMing()) {
+       // ___chkstk(Mingw64):
+       // Clobbers R10, R11, RAX and EFLAGS.
+       // Updates RSP.
+-      BuildMI(*BB, MI, DL, TII->get(X86::W64ALLOCA))
+-        .addExternalSymbol("___chkstk")
++      MIB
+         .addReg(X86::RAX, RegState::Implicit)
+         .addReg(X86::RSP, RegState::Implicit)
+         .addReg(X86::RAX, RegState::Define | RegState::Implicit)
+@@ -12237,8 +12261,7 @@
+       // __chkstk(MSVCRT): does not update stack pointer.
+       // Clobbers R10, R11 and EFLAGS.
+       // FIXME: RAX(allocated size) might be reused and not killed.
+-      BuildMI(*BB, MI, DL, TII->get(X86::W64ALLOCA))
+-        .addExternalSymbol("__chkstk")
++      MIB
+         .addReg(X86::RAX, RegState::Implicit)
+         .addReg(X86::EFLAGS, RegState::Define | RegState::Implicit);
+       // RAX has the offset to subtracted from RSP.
+Index: lib/Target/X86/X86FrameLowering.cpp
+===================================================================
+--- lib/Target/X86/X86FrameLowering.cpp	(revision 150916)
++++ lib/Target/X86/X86FrameLowering.cpp	(working copy)
+@@ -873,25 +873,49 @@
+         .addReg(X86::EAX, RegState::Kill)
+         .setMIFlag(MachineInstr::FrameSetup);
+     }
++    
++    MachineInstrBuilder MIB;
+ 
+     if (Is64Bit) {
++           
+       // Handle the 64-bit Windows ABI case where we need to call __chkstk.
+       // Function prologue is responsible for adjusting the stack pointer.
+       BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64ri), X86::RAX)
+         .addImm(NumBytes)
+         .setMIFlag(MachineInstr::FrameSetup);
++        
++      if (TM.getCodeModel() == CodeModel::Large) {
++        // For large code model we need to do indirect call to __chkstk.
++      
++          
++        // R11 will be used to contain the address of __chkstk.
++        // R11 is a volotiale register and assumed to be destoyed by the callee, 
++        // so there is no need to save and restore it.
++        BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64ri), X86::R11)
++          .addExternalSymbol(StackProbeSymbol);
++        // Create a call to __chkstk function which address contained in R11.
++        MIB = BuildMI(MBB, MBBI, DL, TII.get(X86::CALL64r))
++                .addReg(X86::R11, RegState::Kill);
++      } else {
++      
++        // For non-large code model we can do direct call to __chkstk.
++              
++        MIB = BuildMI(MBB, MBBI, DL, TII.get(X86::W64ALLOCA))
++                .addExternalSymbol(StackProbeSymbol);
++      }
+     } else {
+       // Allocate NumBytes-4 bytes on stack in case of isEAXAlive.
+       // We'll also use 4 already allocated bytes for EAX.
+       BuildMI(MBB, MBBI, DL, TII.get(X86::MOV32ri), X86::EAX)
+         .addImm(isEAXAlive ? NumBytes - 4 : NumBytes)
+         .setMIFlag(MachineInstr::FrameSetup);
++        
++      MIB = BuildMI(MBB, MBBI, DL, TII.get(X86::CALLpcrel32))
++              .addExternalSymbol(StackProbeSymbol);
+     }
+ 
+-    BuildMI(MBB, MBBI, DL,
+-            TII.get(Is64Bit ? X86::W64ALLOCA : X86::CALLpcrel32))
+-      .addExternalSymbol(StackProbeSymbol)
+-      .addReg(StackPtr,    RegState::Define | RegState::Implicit)
++    
++    MIB.addReg(StackPtr,    RegState::Define | RegState::Implicit)
+       .addReg(X86::EFLAGS, RegState::Define | RegState::Implicit)
+       .setMIFlag(MachineInstr::FrameSetup);
+ 

Modified: trunk/lib/win64/llvm/readme.txt
===================================================================
--- trunk/lib/win64/llvm/readme.txt	2013-02-06 15:57:12 UTC (rev 54356)
+++ trunk/lib/win64/llvm/readme.txt	2013-02-06 19:45:36 UTC (rev 54357)
@@ -4,8 +4,9 @@
 * Download LLVM and Clang 3.1 source code
 * Extract llvm in lib/windows/llvm/llvm-3.1.src
 * Extract clang in lib/windows/llvm/llvm-3.1.src/tools/clang
+* Apply llvm-alloca-fix.patch
 * Install Python 2.7
 * Open Visual Studio 2008 x64 Command Prompt
-* cd into lib/windows/llvm
+* cd into lib/win64/llvm
 * build.bat
 




More information about the Bf-blender-cvs mailing list