Fix TEXREL issues when using GLX_USE_TLS (see bug 7459).
authorBrian <brian.paul@tungstengraphics.com>
Tue, 12 Jun 2007 15:47:03 +0000 (09:47 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 12 Jun 2007 15:47:03 +0000 (09:47 -0600)
src/mesa/glapi/gl_x86_asm.py
src/mesa/glapi/glapi.c
src/mesa/x86/glapi_x86.S

index 650331a0c5ab9fa88ea789ed44358c237b737c2e..403e87261b09d3b223de9d2ff90b0d214d0adc3f 100644 (file)
@@ -82,12 +82,18 @@ class PrintGenericStubs(gl_XML.gl_print_base):
                print ''
                print '#ifdef GLX_USE_TLS'
                print ''
+               print '#ifdef GLX_X86_READONLY_TEXT'
+               print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)'
+               print '#else'
+               print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */'
+               print '#endif'
+               print ''
                print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
                print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
                print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
                print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
                print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
-               print '\tNOP ;\t\t\t\t\t\t\\'
+               print '\tCTX_INSNS ;                                    \\'
                print '\tJMP(GL_OFFSET(off))'
                print ''
                print '#elif defined(PTHREADS)'
@@ -138,7 +144,10 @@ class PrintGenericStubs(gl_XML.gl_print_base):
                print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
                print 'ALIGNTEXT16'
                print 'GLNAME(_x86_get_dispatch):'
-               print '\tmovl\t%gs:_glapi_tls_Dispatch@NTPOFF, %eax'
+               print '\tcall   1f'
+               print '1:\tpopl %eax'
+               print '\taddl   $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax'
+               print '\tmovl   _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax'
                print '\tret'
                print ''
                print '#elif defined(PTHREADS)'
@@ -158,7 +167,7 @@ class PrintGenericStubs(gl_XML.gl_print_base):
                print '#endif'
                print ''
 
-               print '#if defined( GLX_USE_TLS )'
+               print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )'
                print '\t\t.section\twtext, "awx", @progbits'
                print '#endif /* defined( GLX_USE_TLS ) */'
 
index 5815dbff842eb1a097119496d8ebc60bb5bd637a..47c57822732e7f15f8c57500f014a4eaf6ebf632 100644 (file)
@@ -1028,22 +1028,24 @@ _glapi_check_table(const struct _glapi_table *table)
 #if defined(PTHREADS) || defined(GLX_USE_TLS)
 /**
  * Perform platform-specific GL API entry-point fixups.
- * 
- * 
  */
 static void
 init_glapi_relocs( void )
 {
-#if defined( USE_X86_ASM ) && defined( GLX_USE_TLS )
-    extern void * _x86_get_dispatch(void);
-    const GLubyte * const get_disp = (const GLubyte *) _x86_get_dispatch;
+#if defined(USE_X86_ASM) && defined(GLX_USE_TLS) && !defined(GLX_X86_READONLY_TEXT)
+    extern unsigned long _x86_get_dispatch(void);
+    char run_time_patch[] = {
+       0x65, 0xa1, 0, 0, 0, 0 /* movl %gs:0,%eax */
+    };
+    GLuint *offset = (GLuint *) &run_time_patch[2]; /* 32-bits for x86/32 */
+    const GLubyte * const get_disp = (const GLubyte *) run_time_patch;
     GLubyte * curr_func = (GLubyte *) gl_dispatch_functions_start;
 
-
+    *offset = _x86_get_dispatch();
     while ( curr_func != (GLubyte *) gl_dispatch_functions_end ) {
-       (void) memcpy( curr_func, get_disp, );
+       (void) memcpy( curr_func, get_disp, sizeof(run_time_patch));
        curr_func += DISPATCH_FUNCTION_SIZE;
     }
-#endif /* defined( USE_X86_ASM ) && defined( GLX_USE_TLS ) */
-}
 #endif
+}
+#endif /* defined(PTHREADS) || defined(GLX_USE_TLS) */
index bdf42ac0887970502d609c89206394dd0b40e8af..74e93721bc314fe971872917b2b7790ba4ccc74a 100644 (file)
 
 #ifdef GLX_USE_TLS
 
+#ifdef GLX_X86_READONLY_TEXT
+# define CTX_INSNS MOV_L(GS:(EAX), EAX)
+#else
+# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */
+#endif
 #  define GL_STUB(fn,off,fn_alt)                       \
 ALIGNTEXT16;                                           \
 GLOBL_FN(GL_PREFIX(fn, fn_alt));                       \
 GL_PREFIX(fn, fn_alt):                                 \
        CALL(_x86_get_dispatch) ;                       \
-       NOP ;                                           \
+       CTX_INSNS ;                                     \
        JMP(GL_OFFSET(off))
 
 #elif defined(PTHREADS)
@@ -114,7 +119,10 @@ SEG_TEXT
        HIDDEN(GLNAME(_x86_get_dispatch))
 ALIGNTEXT16
 GLNAME(_x86_get_dispatch):
-       movl    %gs:_glapi_tls_Dispatch@NTPOFF, %eax
+       call    1f
+1:     popl    %eax
+       addl    $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax
+       movl    _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax
        ret
 
 #elif defined(PTHREADS)
@@ -133,7 +141,7 @@ GLNAME(_x86_get_dispatch):
 EXTERN GLNAME(_glapi_get_dispatch)
 #endif
 
-#if defined( GLX_USE_TLS )
+#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )
                .section        wtext, "awx", @progbits
 #endif /* defined( GLX_USE_TLS ) */