[PATCH] D40105: Implement GetTls() for NetBSD

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 15:34:37 PST 2017


krytarowski created this revision.
krytarowski added a project: Sanitizers.
Herald added subscribers: kubamracek, emaste, srhines.

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 <The NetBSD Foundation>


Repository:
  rL LLVM

https://reviews.llvm.org/D40105

Files:
  lib/sanitizer_common/sanitizer_linux_libcdep.cc
  test/tsan/tls_race.cc
  test/tsan/tls_race2.cc


Index: test/tsan/tls_race2.cc
===================================================================
--- test/tsan/tls_race2.cc
+++ test/tsan/tls_race2.cc
@@ -27,4 +27,5 @@
 // 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
Index: test/tsan/tls_race.cc
===================================================================
--- test/tsan/tls_race.cc
+++ test/tsan/tls_race.cc
@@ -20,4 +20,5 @@
 // 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
Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -316,7 +316,7 @@
 }
 #endif  // (x86_64 || i386 || MIPS) && SANITIZER_LINUX
 
-#if SANITIZER_FREEBSD
+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
 static void **ThreadSelfSegbase() {
   void **segbase = 0;
 # if defined(__i386__)
@@ -326,17 +326,15 @@
   // 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;
 }
 
 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) {
@@ -354,7 +352,7 @@
   *addr = 0;
   *size = 0;
 # endif
-#elif SANITIZER_FREEBSD
+#elif SANITIZER_FREEBSD || SANITIZER_NETBSD
   void** segbase = ThreadSelfSegbase();
   *addr = 0;
   *size = 0;
@@ -367,7 +365,7 @@
     *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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40105.123097.patch
Type: text/x-patch
Size: 2259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171115/fb8cbbb8/attachment.bin>


More information about the llvm-commits mailing list