[Mesa-dev] [PATCH 1/1] gallium/gallivm: code generation options for LLVM 3.1+

Alexander V. Nikolaev avn at daemon.hole.ru
Sat Sep 22 19:28:39 PDT 2012


From: "Alexander V. Nikolaev" <avn at daemon.hole.ru>

LLVM 3.1+ haven't more "extern unsigned llvm::StackAlignmentOverride"
and friends for configuring code generation options, like stack
alignment.

So I restrict assiging of lvm::StackAlignmentOverride and other
variables to LLVM 3.0 only, and wrote similiar code using
TargetOptions.

This patch fix segfaulting of WINE using llvmpipe built with LLVM 3.1

Signed-off-by: Alexander V. Nikolaev <avn at daemon.hole.ru>
---
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index dd2c612..8410f84 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -109,7 +109,7 @@ lp_set_target_options(void)
     * to only assume a 4 bytes alignment for backwards compatibility.
     */
 #if defined(PIPE_ARCH_X86)
-#if HAVE_LLVM >= 0x0300
+#if HAVE_LLVM == 0x0300
    llvm::StackAlignmentOverride = 4;
 #else
    llvm::StackAlignment = 4;
@@ -251,8 +251,27 @@ lp_build_create_mcjit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
 
    std::string Error;
    EngineBuilder builder(unwrap(M));
+
+   /**
+    *  Set proper stack alignment for backward compatibility with old binaries
+    *  and WINE.
+    */
+   TargetOptions options;
+   options.StackAlignmentOverride = 4;
+   options.RealignStack = true;
+
+#if defined(DEBUG)
+   options.JITEmitDebugInfo = true;
+#endif
+
+#if defined(DEBUG) || defined(PROFILE)
+   options.NoFramePointerElimNonLeaf = true;
+   options.NoFramePointerElim = true;
+#endif
+
    builder.setEngineKind(EngineKind::JIT)
           .setErrorStr(&Error)
+          .setTargetOptions(options)
           .setOptLevel((CodeGenOpt::Level)OptLevel);
 
    builder.setUseMCJIT(true);
-- 
1.7.10



More information about the mesa-dev mailing list