diff --git a/compiler-rt/lib/builtins/emutls.c b/compiler-rt/lib/builtins/emutls.c index 390ffb25f6cf0..ca18da2fffe6f 100644 --- a/compiler-rt/lib/builtins/emutls.c +++ b/compiler-rt/lib/builtins/emutls.c @@ -392,8 +392,12 @@ __attribute__((visibility("default"), weak)) void *__emutls_get_address(__emutls_control *control) { uintptr_t index = emutls_get_index(control); emutls_address_array *array = emutls_get_address_array(index--); - if (array->data[index] == NULL) - array->data[index] = emutls_allocate_object(control); + if (array->data[index] == NULL) { + emutls_lock(); + if (array->data[index] == NULL) + array->data[index] = emutls_allocate_object(control); + emutls_unlock(); + } return array->data[index]; }