From d82adbb78a246d68d67a951cdfc81b757fac2453 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Mon, 10 May 2021 23:02:21 +0200
Subject: [PATCH] lower optimization for dispatch code when using C + tsb

there appears to be some bug in the code which causes crashes
with threaded opengl setups; this manifests at least on ppc64(le)
with musl (where one must set `-Dtls=enabled`). I haven't been
able to track it down yet, but this workaround at least makes it
stop happening.
---
 src/GLdispatch/vnd-glapi/meson.build | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git src/GLdispatch/vnd-glapi/meson.build src/GLdispatch/vnd-glapi/meson.build
index 615cdff..94310b3 100644
--- a/src/GLdispatch/vnd-glapi/meson.build
+++ b/src/GLdispatch/vnd-glapi/meson.build
@@ -35,8 +35,12 @@ else
 endif
 
 _entry_files = []
+_extra_cflags = []
 if gl_dispatch_type == 'pure_c'
   _entry_files += 'entry_pure_c.c'
+  if not have_tls
+    _extra_cflags += '-O0'
+  endif
 else
   _entry_files += 'entry_common.c'
   if gl_dispatch_type != 'armv7_tsd'
@@ -73,7 +77,7 @@ libglapi = static_library(
     glapi_mapi_tmp_h,
     _entry_files,
   ],
-  c_args : ['-DMAPI_ABI_HEADER="@0@"'.format(glapi_mapi_tmp_h.full_path())],
+  c_args : ['-DMAPI_ABI_HEADER="@0@"'.format(glapi_mapi_tmp_h.full_path())] + _extra_cflags,
   include_directories : inc_include,
   dependencies : idep_utils_misc,
   gnu_symbol_visibility : 'hidden',
@@ -89,7 +93,7 @@ foreach g : ['gl', 'opengl', 'glesv1', 'glesv2']
     c_args : [
       '-DSTATIC_DISPATCH_ONLY',
       '-DMAPI_ABI_HEADER="@0@"'.format(header.full_path()),
-    ],
+    ] + _extra_cflags,
     include_directories : [inc_include, inc_util],
     gnu_symbol_visibility : 'hidden',
   )
-- 
2.31.1

