From f83e992c8b27111ab802fd7e5678592a0c717518 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 24 May 2018 11:46:57 -0700 Subject: [PATCH] Mark CrapPool thread_local Not sure if I like to keep it. For now, aim for correctness. --- src/dump-emoji.cc | 2 +- src/dump-fon.cc | 2 +- src/hb-ot-layout.cc | 2 +- src/hb-private.hh | 14 +++++++++++++- src/hb-subset.cc | 2 +- src/main.cc | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index 50a929bec..280c5c9be 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -48,7 +48,7 @@ #ifndef HB_NO_VISIBILITY const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; -void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif void cbdt_callback (const uint8_t* data, unsigned int length, diff --git a/src/dump-fon.cc b/src/dump-fon.cc index 827de4a3e..748de1ab6 100644 --- a/src/dump-fon.cc +++ b/src/dump-fon.cc @@ -28,7 +28,7 @@ #ifndef HB_NO_VISIBILITY const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; -void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif template struct LEInt; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 670495453..7f9b6be88 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -48,7 +48,7 @@ #ifndef HB_NO_VISIBILITY const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; -void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif diff --git a/src/hb-private.hh b/src/hb-private.hh index 4318eb972..45f699040 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -90,6 +90,14 @@ extern "C" void hb_free_impl(void *ptr); HB_UNUSED typedef int HB_PASTE(static_assertion_failed_at_line_, __LINE__) [(e) ? 1 : -1] #endif // static_assert +#ifdef __GNUC__ +#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)) +#define thread_local __thread +#endif +#else +#define thread_local +#endif + #endif // __cplusplus < 201103L #if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__) @@ -570,12 +578,16 @@ static_assert (Namespace::Type::min_size + 1 <= sizeof (_Null##Type), "Null pool /* Global writable pool. Enlarge as necessary. */ +/* To be fully correct, CrapPool must be thread_local. However, we do not rely on CrapPool + * for correct operation. It only exist to catch and divert program logic bugs instead of + * causing bad memory access. So, races there are not actually introducing incorrectness + * in the code. So maybe disable? Has ~12kb binary size overhead to have it. */ #ifdef HB_NO_VISIBILITY static #else extern HB_INTERNAL #endif -void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] +thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] #ifdef HB_NO_VISIBILITY = {} #endif diff --git a/src/hb-subset.cc b/src/hb-subset.cc index ad273d047..e974d0f4d 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -46,7 +46,7 @@ #if !defined(HB_NO_VISIBILITY) && !defined(HB_SUBSET_BUILTIN) const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; -void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif diff --git a/src/main.cc b/src/main.cc index f32490e76..2fec52f97 100644 --- a/src/main.cc +++ b/src/main.cc @@ -39,7 +39,7 @@ using namespace OT; #ifndef HB_NO_VISIBILITY const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; -void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +thread_local void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif int