Mesa (master): glapi: Force frame pointer elimination on Windows.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed Jan 7 20:09:07 UTC 2015


Module: Mesa
Branch: master
Commit: fd1f79f7dda3cbe1b677a74ad1b242603646ffd5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd1f79f7dda3cbe1b677a74ad1b242603646ffd5

Author: José Fonseca <jfonseca at vmware.com>
Date:   Wed Jan  7 14:24:07 2015 +0000

glapi: Force frame pointer elimination on Windows.

To catch mismatches in cdecl vs stdcall calling convention.  See code
comment for more detailed explanation.

Tested with piglit gl-1.0-beginend-coverage (it now also crashes on
debug builds.)

VMware PR1350505.

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mapi/glapi/glapi_dispatch.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/mapi/glapi/glapi_dispatch.c b/src/mapi/glapi/glapi_dispatch.c
index d2dd965..df907ff 100644
--- a/src/mapi/glapi/glapi_dispatch.c
+++ b/src/mapi/glapi/glapi_dispatch.c
@@ -144,6 +144,28 @@ GL_API void GL_APIENTRY glTexParameterxv (GLenum target, GLenum pname, const GLf
 GL_API void GL_APIENTRY glTranslatex (GLfixed x, GLfixed y, GLfixed z);
 GL_API void GL_APIENTRY glPointSizePointerOES (GLenum type, GLsizei stride, const GLvoid *pointer);
 
+/* Enable frame pointer elimination on Windows, otherwise forgetting to add
+ * APIENTRY to _mesa_* entrypoints will not cause crashes on debug builds, as
+ * the initial ESP value is saved in the EBP in the function prologue, then
+ * restored on the epilogue, clobbering any corruption in the ESP pointer due
+ * to mismatch in the callee calling convention.
+ *
+ * On MSVC it's not sufficient to enable /Oy -- other optimizations must be
+ * enabled or frame pointer will be used regardless.
+ *
+ * We don't do this when NDEBUG is defined since, frame pointer omission
+ * optimization compiler flag are already specified on release builds, and
+ * because on profile builds we must have frame pointers or certain profilers
+ * might fail to unwind the stack.
+ */
+#if defined(_WIN32) && !defined(NDEBUG)
+#  if defined(_MSC_VER)
+#    pragma optimize( "gty", on )
+#  elif defined(__GNUC__)
+#    pragma GCC optimize ("omit-frame-pointer")
+#  endif
+#endif
+
 #include "glapi/glapitemp.h"
 
 #endif /* USE_X86_ASM */




More information about the mesa-commit mailing list