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.0 +0100
+++ b/src/mesa/glapi/gl_x86-64_asm.py 2009-07-06 22:17:59.0 +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_getspeci...@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_getspeci...@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:
.p2align4,,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_getspeci...@plt
#elif defined(THREADS)
@@ -29277,12 +29281,88 @@ GL_PREFIX(_dispatch_stub_773):
.size GL_PREFIX(_dispatch_stub_773), .-GL_PREFIX(_dispatch_stub_773)
.p2align4,,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_dispa...@plt
+ movq6192(%rax), %r11
+ jmp *%r11
+#elif defined(PTHREADS)
+ pushq %rdi
+ pushq %rsi
+ pushq %rdx
+ call_x86_64_get_dispa...@plt
+ popq%rdx
+ popq%rsi
+ popq%rdi
+ movq6192(%rax), %r11
+ jmp *%r11
+#else
+ movq_glapi_Dispatch(%rip), %rax
+ testq %rax, %rax
+ je 1f
+ movq6192(%rax), %r11
+ jmp *%r11
+1:
+ pushq %rdi
+ pushq %rsi
+ pushq %rdx
+ call_glapi_get_dispatch
+ popq%rdx
+ popq%rsi
+ popq%rdi
+ movq6192(%rax), %r11
+ jmp *%r11
+#endif /* defined(GLX_USE_TLS) */
+ .size GL_PREFIX(_dispatch_stub_774), .-GL_PREFIX(_dispatch_stub_774)
+
+ .p2align4,,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