Module Name: xsrc Committed By: maya Date: Tue Apr 9 14:14:59 UTC 2019
Modified Files: xsrc/external/mit/MesaLib/dist/src/glx: glxclient.h glxcurrent.c xsrc/external/mit/MesaLib/dist/src/mapi: entry_x86-64_tls.h entry_x86_tls.h u_current.c u_current.h Log Message: Add workaround for non-zero initialized initial-exec TLS variables. NetBSD doesn't support these with dlopen. Ref: https://bugs.freedesktop.org/show_bug.cgi?id=35268 https://mail-index.netbsd.org/pkgsrc-users/2015/09/11/msg022180.html http://gnats.netbsd.org/50277 Fixes dlopen of libGL reported by prlw1 on current users. >From tnn, via pkgsrc/graphics/MesaLib*. To generate a diff of this commit: cvs rdiff -u -r1.1.1.4 -r1.2 \ xsrc/external/mit/MesaLib/dist/src/glx/glxclient.h \ xsrc/external/mit/MesaLib/dist/src/glx/glxcurrent.c cvs rdiff -u -r1.3 -r1.4 \ xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86-64_tls.h cvs rdiff -u -r1.4 -r1.5 \ xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86_tls.h cvs rdiff -u -r1.1.1.2 -r1.2 \ xsrc/external/mit/MesaLib/dist/src/mapi/u_current.c \ xsrc/external/mit/MesaLib/dist/src/mapi/u_current.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: xsrc/external/mit/MesaLib/dist/src/glx/glxclient.h diff -u xsrc/external/mit/MesaLib/dist/src/glx/glxclient.h:1.1.1.4 xsrc/external/mit/MesaLib/dist/src/glx/glxclient.h:1.2 --- xsrc/external/mit/MesaLib/dist/src/glx/glxclient.h:1.1.1.4 Sun Mar 10 03:42:32 2019 +++ xsrc/external/mit/MesaLib/dist/src/glx/glxclient.h Tue Apr 9 14:14:59 2019 @@ -659,7 +659,11 @@ extern void __glXSetCurrentContext(struc extern __thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec"))); +#if defined(__NetBSD__) +# define __glXGetCurrentContext() (likely(__glX_tls_Context) ? __glX_tls_Context : (void*)&dummyContext) +#else # define __glXGetCurrentContext() __glX_tls_Context +#endif # else Index: xsrc/external/mit/MesaLib/dist/src/glx/glxcurrent.c diff -u xsrc/external/mit/MesaLib/dist/src/glx/glxcurrent.c:1.1.1.4 xsrc/external/mit/MesaLib/dist/src/glx/glxcurrent.c:1.2 --- xsrc/external/mit/MesaLib/dist/src/glx/glxcurrent.c:1.1.1.4 Sun Mar 10 03:42:32 2019 +++ xsrc/external/mit/MesaLib/dist/src/glx/glxcurrent.c Tue Apr 9 14:14:59 2019 @@ -40,6 +40,18 @@ #include "glx_error.h" /* + * MASSIVE KLUDGE! + * We need these to not be extern in libGL.so because of + * PR toolchain/50277 + */ +#if defined(GLX_USE_TLS) && defined(__NetBSD__) +_X_EXPORT __thread struct _glapi_table * _glapi_tls_Dispatch + __attribute__((tls_model("initial-exec"))) = NULL; +_X_EXPORT __thread void * _glapi_tls_Context + __attribute__((tls_model("initial-exec"))); +#endif + +/* ** We setup some dummy structures here so that the API can be used ** even if no context is current. */ @@ -77,7 +89,11 @@ _X_HIDDEN pthread_mutex_t __glXmutex = P * \c __glXGetCurrentContext can be implemented as trivial macro. */ __thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec"))) +#if defined(__NetBSD__) + = NULL; /* non-zero initializers not supported with dlopen */ +#else = &dummyContext; +#endif _X_HIDDEN void __glXSetCurrentContext(struct glx_context * c) Index: xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86-64_tls.h diff -u xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86-64_tls.h:1.3 xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86-64_tls.h:1.4 --- xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86-64_tls.h:1.3 Sun Mar 10 04:15:51 2019 +++ xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86-64_tls.h Tue Apr 9 14:14:59 2019 @@ -43,10 +43,19 @@ __asm__(".text\n" #ifndef __ILP32__ +#if defined(__NetBSD__) && defined(MAPI_MODE_GLAPI) #define STUB_ASM_CODE(slot) \ "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t" \ "movq %fs:(%rax), %r11\n\t" \ + "testq %r11, %r11\n\t" \ + "cmoveq table_noop_array@GOTPCREL(%rip), %r11\n\t" \ "jmp *(8 * " slot ")(%r11)" +#else +#define STUB_ASM_CODE(slot) \ + "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t" \ + "movq %fs:(%rax), %r11\n\t" \ + "jmp *(8 * " slot ")(%r11)" +#endif #else Index: xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86_tls.h diff -u xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86_tls.h:1.4 xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86_tls.h:1.5 --- xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86_tls.h:1.4 Sun Mar 10 04:15:51 2019 +++ xsrc/external/mit/MesaLib/dist/src/mapi/entry_x86_tls.h Tue Apr 9 14:14:59 2019 @@ -56,10 +56,27 @@ __asm__(".balign 16\n" ".balign 16\n" \ func ":" +#if defined(__NetBSD__) && defined(MAPI_MODE_GLAPI) +extern const mapi_func table_noop_array[]; #define STUB_ASM_CODE(slot) \ "call x86_current_tls\n\t" \ "movl %gs:(%eax), %eax\n\t" \ + "testl %eax, %eax\n\t" \ + "je 1f\n\t" \ + "jmp *(4 * " slot ")(%eax)\n\t" \ + "1:\n\t" \ + "call 2f\n" \ + "2:\n\t" \ + "popl %eax\n\t" \ + "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" \ + "movl table_noop_array@GOT(%eax), %eax\n\t" \ "jmp *(4 * " slot ")(%eax)" +#else +#define STUB_ASM_CODE(slot) \ + "call x86_current_tls\n\t" \ + "movl %gs:(%eax), %eax\n\t" \ + "jmp *(4 * " slot ")(%eax)" +#endif #define MAPI_TMP_STUB_ASM_GCC #include "mapi_tmp.h" Index: xsrc/external/mit/MesaLib/dist/src/mapi/u_current.c diff -u xsrc/external/mit/MesaLib/dist/src/mapi/u_current.c:1.1.1.2 xsrc/external/mit/MesaLib/dist/src/mapi/u_current.c:1.2 --- xsrc/external/mit/MesaLib/dist/src/mapi/u_current.c:1.1.1.2 Sun Mar 10 03:42:32 2019 +++ xsrc/external/mit/MesaLib/dist/src/mapi/u_current.c Tue Apr 9 14:14:59 2019 @@ -101,7 +101,11 @@ extern void (*__glapi_noop_table[])(void __thread struct _glapi_table *u_current_table __attribute__((tls_model("initial-exec"))) +#if defined(__NetBSD__) + = NULL; /* non-zero initializers not supported with dlopen */ +#else = (struct _glapi_table *) table_noop_array; +#endif __thread void *u_current_context __attribute__((tls_model("initial-exec"))); @@ -283,7 +287,11 @@ struct _glapi_table * u_current_get_table_internal(void) { #if defined(GLX_USE_TLS) +# if defined(__NetBSD__) + return (likely(u_current_table) ? u_current_table : (struct _glapi_table *) table_noop_array); +# else return u_current_table; +# endif #else if (ThreadSafe) return (struct _glapi_table *) tss_get(u_current_table_tsd); Index: xsrc/external/mit/MesaLib/dist/src/mapi/u_current.h diff -u xsrc/external/mit/MesaLib/dist/src/mapi/u_current.h:1.1.1.2 xsrc/external/mit/MesaLib/dist/src/mapi/u_current.h:1.2 --- xsrc/external/mit/MesaLib/dist/src/mapi/u_current.h:1.1.1.2 Sun Mar 10 03:42:32 2019 +++ xsrc/external/mit/MesaLib/dist/src/mapi/u_current.h Tue Apr 9 14:14:59 2019 @@ -65,7 +65,7 @@ u_current_get_context_internal(void); static inline const struct _glapi_table * u_current_get_table(void) { -#ifdef GLX_USE_TLS +#if defined(GLX_USE_TLS) && !defined(__NetBSD__) return u_current_table; #else return (likely(u_current_table) ?