[compiler-rt] 2a9ce60 - [compiler-rt] [netbsd] Improve the portability of ThreadSelfTlsTcb
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 07:33:06 PDT 2020
Author: Kamil Rytarowski
Date: 2020-10-02T16:32:58+02:00
New Revision: 2a9ce60de98e53198047daaeeec3cf09ece4e693
URL: https://github.com/llvm/llvm-project/commit/2a9ce60de98e53198047daaeeec3cf09ece4e693
DIFF: https://github.com/llvm/llvm-project/commit/2a9ce60de98e53198047daaeeec3cf09ece4e693.diff
LOG: [compiler-rt] [netbsd] Improve the portability of ThreadSelfTlsTcb
Use __lwp_gettcb_fast() and __lwp_getprivate_fast(), as _lwp_getprivate()
can be a biased pointer and invalid for use in this function on all CPUs.
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index fe08ffc1bb4a..f95f03b089a3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -28,6 +28,10 @@
#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
+#if SANITIZER_NETBSD
+#define _RTLD_SOURCE // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
+#endif
+
#include <dlfcn.h> // for dlsym()
#include <link.h>
#include <pthread.h>
@@ -412,7 +416,13 @@ uptr ThreadSelf() {
#if SANITIZER_NETBSD
static struct tls_tcb * ThreadSelfTlsTcb() {
- return (struct tls_tcb *)_lwp_getprivate();
+ struct tls_tcb *tcb = nullptr;
+#ifdef __HAVE___LWP_GETTCB_FAST
+ tcb = (struct tls_tcb *)__lwp_gettcb_fast();
+#elif defined(__HAVE___LWP_GETPRIVATE_FAST)
+ tcb = (struct tls_tcb *)__lwp_getprivate_fast();
+#endif
+ return tcb;
}
uptr ThreadSelf() {
More information about the llvm-commits
mailing list