[Mesa-dev] [PATCH 3/4] mapi: Fix x86 asm for global-dynamic TLS model.

christopher.halse.rogers at canonical.com christopher.halse.rogers at canonical.com
Wed Mar 23 16:33:38 PDT 2011


From: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

Because the address of a thread-local variable is no longer
a known fixed offset from the TCB it is not possible to run-time
patch the dispatch table to load _glapi_tls_Dispatch with an
immediate instruction.
---
 src/mapi/glapi/gen/gl_x86_asm.py  |   19 ++++++++-----------
 src/mapi/glapi/glapi_entrypoint.c |   15 ---------------
 2 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/src/mapi/glapi/gen/gl_x86_asm.py b/src/mapi/glapi/gen/gl_x86_asm.py
index 4ef4acb..cafc0c0 100644
--- a/src/mapi/glapi/gen/gl_x86_asm.py
+++ b/src/mapi/glapi/gen/gl_x86_asm.py
@@ -84,18 +84,11 @@ 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 '\tCTX_INSNS ;					\\'
 		print '\tJMP(GL_OFFSET(off))'
 		print ''
 		print '#elif defined(PTHREADS)'
@@ -146,10 +139,14 @@ class PrintGenericStubs(gl_XML.gl_print_base):
 		print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
 		print 'ALIGNTEXT16'
 		print 'GLNAME(_x86_get_dispatch):'
-		print '\tcall	1f'
-		print '1:\tpopl	%eax'
-		print '\taddl	$_GLOBAL_OFFSET_TABLE_+[.-1b], %eax'
-		print '\tmovl	_glapi_tls_Dispatch at GOTNTPOFF(%eax), %eax'
+		print '\tpushl\t%ebx'
+		print '\tcall\t1f'
+		print '1:\tpopl\t%ebx'
+		print '\taddl\t$_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx'
+		print '\tleal\t_glapi_tls_Dispatch at tlsgd(,%ebx,1), %eax'
+		print '\tcall\t___tls_get_addr at plt'
+		print '\tmovl\t(%eax),%eax'
+		print '\tpopl\t%ebx'
 		print '\tret'
 		print ''
 		print '#elif defined(PTHREADS)'
diff --git a/src/mapi/glapi/glapi_entrypoint.c b/src/mapi/glapi/glapi_entrypoint.c
index 993ccb94..d3fdb81 100644
--- a/src/mapi/glapi/glapi_entrypoint.c
+++ b/src/mapi/glapi/glapi_entrypoint.c
@@ -65,21 +65,6 @@ get_entrypoint_address(unsigned int functionOffset)
 static void
 init_glapi_relocs( void )
 {
-#if 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, sizeof(run_time_patch));
-	curr_func += DISPATCH_FUNCTION_SIZE;
-    }
-#endif
 }
 
 
-- 
1.7.4.1



More information about the mesa-dev mailing list