Allocate thread local buffers in __init_tls.
Thread local buffers were using pthread_setspecific for storage with
lazy initialization. pthread_setspecific shares TLS slots between the
linker and libc.so, so thread local buffers being initialized in a
different order between libc.so and the linker meant that bad things
would happen (manifesting as snprintf not working because the
locale was mangled)
Bug: http://b/20464031
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests
everything passes
Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests
thread_local tests are failing both before and after (KUSER_HELPERS?)
Test: /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
no additional failures
Change-Id: I9f445a77c6e86979f3fa49c4a5feecf6ec2b0c3f
diff --git a/libc/bionic/strerror.cpp b/libc/bionic/strerror.cpp
index f74194f..99692ca 100644
--- a/libc/bionic/strerror.cpp
+++ b/libc/bionic/strerror.cpp
@@ -27,12 +27,11 @@
*/
#include <string.h>
-#include "private/ThreadLocalBuffer.h"
+
+#include "bionic/pthread_internal.h"
extern "C" const char* __strerror_lookup(int);
-static ThreadLocalBuffer<char, NL_TEXTMAX> g_strerror_tls_buffer;
-
char* strerror(int error_number) {
// Just return the original constant in the easy cases.
char* result = const_cast<char*>(__strerror_lookup(error_number));
@@ -40,7 +39,8 @@
return result;
}
- result = g_strerror_tls_buffer.get();
- strerror_r(error_number, result, g_strerror_tls_buffer.size());
+ bionic_tls& tls = __get_bionic_tls();
+ result = tls.strerror_buf;
+ strerror_r(error_number, result, sizeof(tls.strerror_buf));
return result;
}