Implement a workaround for thread_local on aarch64
Some versions of lld break thread_local on aarch64. There's a
minimally-painful workaround for it, so let's apply that.
Change-Id: I706de9e280cc15006e5767ee10d961cb2d99352c
diff --git a/aos/libc/BUILD b/aos/libc/BUILD
index 234c29a..35b6629 100644
--- a/aos/libc/BUILD
+++ b/aos/libc/BUILD
@@ -9,6 +9,7 @@
"aos_strsignal.h",
],
deps = [
+ "//aos:thread_local",
"@com_github_google_glog//:glog",
],
)
@@ -53,6 +54,9 @@
hdrs = [
"aos_strerror.h",
],
+ deps = [
+ "//aos:thread_local",
+ ],
)
cc_test(
diff --git a/aos/libc/aos_strerror.cc b/aos/libc/aos_strerror.cc
index 1353242..b045f24 100644
--- a/aos/libc/aos_strerror.cc
+++ b/aos/libc/aos_strerror.cc
@@ -1,9 +1,11 @@
#include "aos/libc/aos_strerror.h"
#include <assert.h>
-#include <sys/types.h>
-#include <string.h>
#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "aos/thread_local.h"
// This code uses an overloaded function to handle the result from either
// version of strerror_r correctly without needing a way to get the choice out
@@ -15,14 +17,15 @@
// Handle the result from the GNU version of strerror_r. It never fails, so
// that's pretty easy...
-__attribute__((unused))
-char *aos_strerror_handle_result(int /*error*/, char *ret, char * /*buffer*/) {
+__attribute__((unused)) char *aos_strerror_handle_result(int /*error*/,
+ char *ret,
+ char * /*buffer*/) {
return ret;
}
// Handle the result from the POSIX version of strerror_r.
-__attribute__((unused))
-char *aos_strerror_handle_result(int error, int ret, char *buffer) {
+__attribute__((unused)) char *aos_strerror_handle_result(int error, int ret,
+ char *buffer) {
if (ret != 0) {
#ifndef NDEBUG
// assert doesn't use the return value when building optimized.
@@ -37,7 +40,7 @@
} // namespace
const char *aos_strerror(int error) {
- static thread_local char buffer[kBufferSize];
+ AOS_THREAD_LOCAL char buffer[kBufferSize];
// Call the overload for whichever version we're using.
return aos_strerror_handle_result(
diff --git a/aos/libc/aos_strsignal.cc b/aos/libc/aos_strsignal.cc
index 9262ac6..91c2211 100644
--- a/aos/libc/aos_strsignal.cc
+++ b/aos/libc/aos_strsignal.cc
@@ -4,8 +4,10 @@
#include "glog/logging.h"
+#include "aos/thread_local.h"
+
const char *aos_strsignal(int signal) {
- static thread_local char buffer[512];
+ AOS_THREAD_LOCAL char buffer[512];
if (signal >= SIGRTMIN && signal <= SIGRTMAX) {
CHECK_GT(snprintf(buffer, sizeof(buffer), "Real-time signal %d",