From 13007b2220cde5084e3b5e8bb7f0df4e0273eebd Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Thu, 16 Nov 2017 17:54:14 +0000 Subject: Implement GetTls() for NetBSD Summary: Reuse the existing code for FreeBSD that is compatible with NetBSD. Add NetBSD support in tests: tls_race.cc and tls_race2.cc. Sponsored by Reviewers: joerg, dvyukov, vitalybuka, kcc, eugenis Reviewed By: dvyukov Subscribers: srhines, emaste, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40105 llvm-svn: 318431 --- compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc | 12 +++++------- compiler-rt/test/tsan/tls_race.cc | 1 + compiler-rt/test/tsan/tls_race2.cc | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'compiler-rt') diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 3e64e90b53c..33f1dfb58a5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -312,7 +312,7 @@ uptr ThreadSelf() { } #endif // (x86_64 || i386 || MIPS) && SANITIZER_LINUX -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_NETBSD static void **ThreadSelfSegbase() { void **segbase = 0; # if defined(__i386__) @@ -322,7 +322,7 @@ static void **ThreadSelfSegbase() { // sysarch(AMD64_GET_FSBASE, segbase); __asm __volatile("movq %%fs:0, %0" : "=r" (segbase)); # else -# error "unsupported CPU arch for FreeBSD platform" +# error "unsupported CPU arch" # endif return segbase; } @@ -330,9 +330,7 @@ static void **ThreadSelfSegbase() { uptr ThreadSelf() { return (uptr)ThreadSelfSegbase()[2]; } -#elif SANITIZER_NETBSD -uptr ThreadSelf() { return (uptr)pthread_self(); } -#endif // SANITIZER_NETBSD +#endif // SANITIZER_FREEBSD || SANITIZER_NETBSD #if !SANITIZER_GO static void GetTls(uptr *addr, uptr *size) { @@ -350,7 +348,7 @@ static void GetTls(uptr *addr, uptr *size) { *addr = 0; *size = 0; # endif -#elif SANITIZER_FREEBSD +#elif SANITIZER_FREEBSD || SANITIZER_NETBSD void** segbase = ThreadSelfSegbase(); *addr = 0; *size = 0; @@ -363,7 +361,7 @@ static void GetTls(uptr *addr, uptr *size) { *addr = (uptr) dtv[2]; *size = (*addr == 0) ? 0 : ((uptr) segbase[0] - (uptr) dtv[2]); } -#elif SANITIZER_ANDROID || SANITIZER_NETBSD +#elif SANITIZER_ANDROID *addr = 0; *size = 0; #else diff --git a/compiler-rt/test/tsan/tls_race.cc b/compiler-rt/test/tsan/tls_race.cc index b43a514cc8a..dd37ff01d97 100644 --- a/compiler-rt/test/tsan/tls_race.cc +++ b/compiler-rt/test/tsan/tls_race.cc @@ -20,4 +20,5 @@ int main() { // CHECK: WARNING: ThreadSanitizer: data race // CHECK-Linux: Location is TLS of main thread. // CHECK-FreeBSD: Location is TLS of main thread. +// CHECK-NetBSD: Location is TLS of main thread. // CHECK-Darwin: Location is heap block of size 4 diff --git a/compiler-rt/test/tsan/tls_race2.cc b/compiler-rt/test/tsan/tls_race2.cc index b04ff678810..f3139b69fc0 100644 --- a/compiler-rt/test/tsan/tls_race2.cc +++ b/compiler-rt/test/tsan/tls_race2.cc @@ -27,4 +27,5 @@ int main() { // CHECK: WARNING: ThreadSanitizer: data race // CHECK-Linux: Location is TLS of thread T1. // CHECK-FreeBSD: Location is TLS of thread T1. +// CHECK-NetBSD: Location is TLS of thread T1. // CHECK-Darwin: Location is heap block of size 4 -- cgit v1.2.3