[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#536106: amd64 SEGVs due to dispatcher wrapper issue.



Julien Cristau wrote:
Hi Brian,

the following bug was reported against the mesa 7.0.3 package in Debian.
The relevant code doesn't seem to have changed in master.  Could you
take a look?

Thanks,
Julien

On Tue, Jul  7, 2009 at 17:50:06 +0100, roger wrote:

It appears that mesa 7.0.3, crashes with some application in amd64 mode.

Weh I traced this into mesa I found the wrapper was only fetching the
dispatch table thru _gl_DispatchTSD - although it had not been setup correctly
- (The magic was 0) .
I compared this gdb trace to the same application which does not crash on
i386 and found that this _gl_DispatchTSD was also not set up on entry to the
wrapper in i386 mode.

Comparing the i386 code and the dispatch documentation shows that the
wrapper ought to be testing _glapi_Dispatch for NULL before getting the
dispatch table from the TSD info.

The attached patch changes the wrapper generator script to create code
which this extra check - and avoids unnecessary calls to pthread_getspecific()

Obviously this root cause of the segv could be an OpenGL programming
issue but it is confusing that the behaviour changes between architectures.


--- a/src/mesa/glapi/gl_x86-64_asm.py	2009-07-06 20:51:52.000000000 +0100
+++ b/src/mesa/glapi/gl_x86-64_asm.py	2009-07-06 22:17:59.000000000 +0100
@@ -166,7 +166,11 @@
 		print ''
 		print '\t.p2align\t4,,15'
 		print '_x86_64_get_dispatch:'
-		print '\tmovq\t_gl_DispatchTSD(%rip), %rdi'
+		print '\tmovq\t_glapi_Dispatch(%rip), %rax'
+		print '\ttestq\t%rax,%rax'
+		print '\tje\t1f'
+		print '\tret'
+		print '1:\tmovq\t_gl_DispatchTSD(%rip), %rdi'
 		print '\tjmp\tpthread_getspecific@PLT'
 		print ''
 		print '#elif defined(THREADS)'


.

I don't know why, but with this patch and a re-generated x86-64/glapi_x86-64.S file, I get a run-time unresolved symbol:

glxinfo: symbol lookup error: /home/brian/mesa/lib64/libGL.so.1: undefined symbol: gl_dispatch_stub_776

Here's the local diff to my tree vs Mesa/git/master. Any ideas? I don't have time right now to investigate.

-Brian

diff --git a/src/mesa/glapi/gl_x86-64_asm.py b/src/mesa/glapi/gl_x86-64_asm.py
index f36ad3a..f5d30c9 100644
--- a/src/mesa/glapi/gl_x86-64_asm.py
+++ b/src/mesa/glapi/gl_x86-64_asm.py
@@ -166,7 +166,11 @@ class PrintGenericStubs(gl_XML.gl_print_base):
 		print ''
 		print '\t.p2align\t4,,15'
 		print '_x86_64_get_dispatch:'
-		print '\tmovq\t_gl_DispatchTSD(%rip), %rdi'
+		print '\tmovq\t_glapi_Dispatch(%rip), %rax'
+		print '\ttestq\t%rax,%rax'
+		print '\tje\t1f'
+		print '\tret'
+		print '1:\tmovq\t_gl_DispatchTSD(%rip), %rdi'
 		print '\tjmp\tpthread_getspecific@PLT'
 		print ''
 		print '#elif defined(THREADS)'
diff --git a/src/mesa/x86-64/glapi_x86-64.S b/src/mesa/x86-64/glapi_x86-64.S
index 44179ab..b65856c 100644
--- a/src/mesa/x86-64/glapi_x86-64.S
+++ b/src/mesa/x86-64/glapi_x86-64.S
@@ -73,7 +73,11 @@ _x86_64_get_dispatch:
 
 	.p2align	4,,15
 _x86_64_get_dispatch:
-	movq	_gl_DispatchTSD(%rip), %rdi
+	movq	_glapi_Dispatch(%rip), %rax
+	testq	%rax,%rax
+	je	1f
+	ret
+1:	movq	_gl_DispatchTSD(%rip), %rdi
 	jmp	pthread_getspecific@PLT
 
 #elif defined(THREADS)
@@ -29277,12 +29281,88 @@ GL_PREFIX(_dispatch_stub_773):
 	.size	GL_PREFIX(_dispatch_stub_773), .-GL_PREFIX(_dispatch_stub_773)
 
 	.p2align	4,,15
+	.globl	GL_PREFIX(_dispatch_stub_774)
+	.type	GL_PREFIX(_dispatch_stub_774), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_774))
+GL_PREFIX(_dispatch_stub_774):
+#if defined(GLX_USE_TLS)
+	call	_x86_64_get_dispatch@PLT
+	movq	6192(%rax), %r11
+	jmp	*%r11
+#elif defined(PTHREADS)
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_x86_64_get_dispatch@PLT
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6192(%rax), %r11
+	jmp	*%r11
+#else
+	movq	_glapi_Dispatch(%rip), %rax
+	testq	%rax, %rax
+	je	1f
+	movq	6192(%rax), %r11
+	jmp	*%r11
+1:
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_glapi_get_dispatch
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6192(%rax), %r11
+	jmp	*%r11
+#endif /* defined(GLX_USE_TLS) */
+	.size	GL_PREFIX(_dispatch_stub_774), .-GL_PREFIX(_dispatch_stub_774)
+
+	.p2align	4,,15
+	.globl	GL_PREFIX(_dispatch_stub_775)
+	.type	GL_PREFIX(_dispatch_stub_775), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_775))
+GL_PREFIX(_dispatch_stub_775):
+#if defined(GLX_USE_TLS)
+	call	_x86_64_get_dispatch@PLT
+	movq	6200(%rax), %r11
+	jmp	*%r11
+#elif defined(PTHREADS)
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_x86_64_get_dispatch@PLT
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6200(%rax), %r11
+	jmp	*%r11
+#else
+	movq	_glapi_Dispatch(%rip), %rax
+	testq	%rax, %rax
+	je	1f
+	movq	6200(%rax), %r11
+	jmp	*%r11
+1:
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_glapi_get_dispatch
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6200(%rax), %r11
+	jmp	*%r11
+#endif /* defined(GLX_USE_TLS) */
+	.size	GL_PREFIX(_dispatch_stub_775), .-GL_PREFIX(_dispatch_stub_775)
+
+	.p2align	4,,15
 	.globl	GL_PREFIX(FramebufferTextureLayerEXT)
 	.type	GL_PREFIX(FramebufferTextureLayerEXT), @function
 GL_PREFIX(FramebufferTextureLayerEXT):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6192(%rax), %r11
+	movq	6208(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
@@ -29296,13 +29376,13 @@ GL_PREFIX(FramebufferTextureLayerEXT):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6192(%rax), %r11
+	movq	6208(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6192(%rax), %r11
+	movq	6208(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
@@ -29316,7 +29396,7 @@ GL_PREFIX(FramebufferTextureLayerEXT):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6192(%rax), %r11
+	movq	6208(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
 	.size	GL_PREFIX(FramebufferTextureLayerEXT), .-GL_PREFIX(FramebufferTextureLayerEXT)
@@ -29327,37 +29407,113 @@ GL_PREFIX(FramebufferTextureLayerEXT):
 GL_PREFIX(ProvokingVertexEXT):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6200(%rax), %r11
+	movq	6216(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
 	call	_x86_64_get_dispatch@PLT
 	popq	%rdi
-	movq	6200(%rax), %r11
+	movq	6216(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6200(%rax), %r11
+	movq	6216(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
 	call	_glapi_get_dispatch
 	popq	%rdi
-	movq	6200(%rax), %r11
+	movq	6216(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
 	.size	GL_PREFIX(ProvokingVertexEXT), .-GL_PREFIX(ProvokingVertexEXT)
 
 	.p2align	4,,15
-	.globl	GL_PREFIX(_dispatch_stub_776)
-	.type	GL_PREFIX(_dispatch_stub_776), @function
-	HIDDEN(GL_PREFIX(_dispatch_stub_776))
-GL_PREFIX(_dispatch_stub_776):
+	.globl	GL_PREFIX(_dispatch_stub_778)
+	.type	GL_PREFIX(_dispatch_stub_778), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_778))
+GL_PREFIX(_dispatch_stub_778):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6208(%rax), %r11
+	movq	6224(%rax), %r11
+	jmp	*%r11
+#elif defined(PTHREADS)
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_x86_64_get_dispatch@PLT
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6224(%rax), %r11
+	jmp	*%r11
+#else
+	movq	_glapi_Dispatch(%rip), %rax
+	testq	%rax, %rax
+	je	1f
+	movq	6224(%rax), %r11
+	jmp	*%r11
+1:
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_glapi_get_dispatch
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6224(%rax), %r11
+	jmp	*%r11
+#endif /* defined(GLX_USE_TLS) */
+	.size	GL_PREFIX(_dispatch_stub_778), .-GL_PREFIX(_dispatch_stub_778)
+
+	.p2align	4,,15
+	.globl	GL_PREFIX(_dispatch_stub_779)
+	.type	GL_PREFIX(_dispatch_stub_779), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_779))
+GL_PREFIX(_dispatch_stub_779):
+#if defined(GLX_USE_TLS)
+	call	_x86_64_get_dispatch@PLT
+	movq	6232(%rax), %r11
+	jmp	*%r11
+#elif defined(PTHREADS)
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_x86_64_get_dispatch@PLT
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6232(%rax), %r11
+	jmp	*%r11
+#else
+	movq	_glapi_Dispatch(%rip), %rax
+	testq	%rax, %rax
+	je	1f
+	movq	6232(%rax), %r11
+	jmp	*%r11
+1:
+	pushq	%rdi
+	pushq	%rsi
+	pushq	%rdx
+	call	_glapi_get_dispatch
+	popq	%rdx
+	popq	%rsi
+	popq	%rdi
+	movq	6232(%rax), %r11
+	jmp	*%r11
+#endif /* defined(GLX_USE_TLS) */
+	.size	GL_PREFIX(_dispatch_stub_779), .-GL_PREFIX(_dispatch_stub_779)
+
+	.p2align	4,,15
+	.globl	GL_PREFIX(_dispatch_stub_780)
+	.type	GL_PREFIX(_dispatch_stub_780), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_780))
+GL_PREFIX(_dispatch_stub_780):
+#if defined(GLX_USE_TLS)
+	call	_x86_64_get_dispatch@PLT
+	movq	6240(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
@@ -29371,13 +29527,13 @@ GL_PREFIX(_dispatch_stub_776):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6208(%rax), %r11
+	movq	6240(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6208(%rax), %r11
+	movq	6240(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
@@ -29391,19 +29547,19 @@ GL_PREFIX(_dispatch_stub_776):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6208(%rax), %r11
+	movq	6240(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
-	.size	GL_PREFIX(_dispatch_stub_776), .-GL_PREFIX(_dispatch_stub_776)
+	.size	GL_PREFIX(_dispatch_stub_780), .-GL_PREFIX(_dispatch_stub_780)
 
 	.p2align	4,,15
-	.globl	GL_PREFIX(_dispatch_stub_777)
-	.type	GL_PREFIX(_dispatch_stub_777), @function
-	HIDDEN(GL_PREFIX(_dispatch_stub_777))
-GL_PREFIX(_dispatch_stub_777):
+	.globl	GL_PREFIX(_dispatch_stub_781)
+	.type	GL_PREFIX(_dispatch_stub_781), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_781))
+GL_PREFIX(_dispatch_stub_781):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6216(%rax), %r11
+	movq	6248(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
@@ -29417,13 +29573,13 @@ GL_PREFIX(_dispatch_stub_777):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6216(%rax), %r11
+	movq	6248(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6216(%rax), %r11
+	movq	6248(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
@@ -29437,19 +29593,19 @@ GL_PREFIX(_dispatch_stub_777):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6216(%rax), %r11
+	movq	6248(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
-	.size	GL_PREFIX(_dispatch_stub_777), .-GL_PREFIX(_dispatch_stub_777)
+	.size	GL_PREFIX(_dispatch_stub_781), .-GL_PREFIX(_dispatch_stub_781)
 
 	.p2align	4,,15
-	.globl	GL_PREFIX(_dispatch_stub_778)
-	.type	GL_PREFIX(_dispatch_stub_778), @function
-	HIDDEN(GL_PREFIX(_dispatch_stub_778))
-GL_PREFIX(_dispatch_stub_778):
+	.globl	GL_PREFIX(_dispatch_stub_782)
+	.type	GL_PREFIX(_dispatch_stub_782), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_782))
+GL_PREFIX(_dispatch_stub_782):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6224(%rax), %r11
+	movq	6256(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
@@ -29463,13 +29619,13 @@ GL_PREFIX(_dispatch_stub_778):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6224(%rax), %r11
+	movq	6256(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6224(%rax), %r11
+	movq	6256(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
@@ -29483,19 +29639,19 @@ GL_PREFIX(_dispatch_stub_778):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6224(%rax), %r11
+	movq	6256(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
-	.size	GL_PREFIX(_dispatch_stub_778), .-GL_PREFIX(_dispatch_stub_778)
+	.size	GL_PREFIX(_dispatch_stub_782), .-GL_PREFIX(_dispatch_stub_782)
 
 	.p2align	4,,15
-	.globl	GL_PREFIX(_dispatch_stub_779)
-	.type	GL_PREFIX(_dispatch_stub_779), @function
-	HIDDEN(GL_PREFIX(_dispatch_stub_779))
-GL_PREFIX(_dispatch_stub_779):
+	.globl	GL_PREFIX(_dispatch_stub_783)
+	.type	GL_PREFIX(_dispatch_stub_783), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_783))
+GL_PREFIX(_dispatch_stub_783):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6232(%rax), %r11
+	movq	6264(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
@@ -29505,13 +29661,13 @@ GL_PREFIX(_dispatch_stub_779):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6232(%rax), %r11
+	movq	6264(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6232(%rax), %r11
+	movq	6264(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
@@ -29521,19 +29677,19 @@ GL_PREFIX(_dispatch_stub_779):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6232(%rax), %r11
+	movq	6264(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
-	.size	GL_PREFIX(_dispatch_stub_779), .-GL_PREFIX(_dispatch_stub_779)
+	.size	GL_PREFIX(_dispatch_stub_783), .-GL_PREFIX(_dispatch_stub_783)
 
 	.p2align	4,,15
-	.globl	GL_PREFIX(_dispatch_stub_780)
-	.type	GL_PREFIX(_dispatch_stub_780), @function
-	HIDDEN(GL_PREFIX(_dispatch_stub_780))
-GL_PREFIX(_dispatch_stub_780):
+	.globl	GL_PREFIX(_dispatch_stub_784)
+	.type	GL_PREFIX(_dispatch_stub_784), @function
+	HIDDEN(GL_PREFIX(_dispatch_stub_784))
+GL_PREFIX(_dispatch_stub_784):
 #if defined(GLX_USE_TLS)
 	call	_x86_64_get_dispatch@PLT
-	movq	6240(%rax), %r11
+	movq	6272(%rax), %r11
 	jmp	*%r11
 #elif defined(PTHREADS)
 	pushq	%rdi
@@ -29543,13 +29699,13 @@ GL_PREFIX(_dispatch_stub_780):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6240(%rax), %r11
+	movq	6272(%rax), %r11
 	jmp	*%r11
 #else
 	movq	_glapi_Dispatch(%rip), %rax
 	testq	%rax, %rax
 	je	1f
-	movq	6240(%rax), %r11
+	movq	6272(%rax), %r11
 	jmp	*%r11
 1:
 	pushq	%rdi
@@ -29559,10 +29715,10 @@ GL_PREFIX(_dispatch_stub_780):
 	popq	%rdx
 	popq	%rsi
 	popq	%rdi
-	movq	6240(%rax), %r11
+	movq	6272(%rax), %r11
 	jmp	*%r11
 #endif /* defined(GLX_USE_TLS) */
-	.size	GL_PREFIX(_dispatch_stub_780), .-GL_PREFIX(_dispatch_stub_780)
+	.size	GL_PREFIX(_dispatch_stub_784), .-GL_PREFIX(_dispatch_stub_784)
 
 	.globl GL_PREFIX(ArrayElementEXT) ; .set GL_PREFIX(ArrayElementEXT), GL_PREFIX(ArrayElement)
 	.globl GL_PREFIX(BindTextureEXT) ; .set GL_PREFIX(BindTextureEXT), GL_PREFIX(BindTexture)

Reply to: