This is an archive of the discontinued LLVM Phabricator instance.

Reimplement Thread Static Data MSan routines with TLS
ClosedPublic

Authored by krytarowski on Dec 14 2018, 5:23 AM.

Details

Summary

Thread Static Data cannot be used in early init on NetBSD
and FreeBSD. Reuse the MSan TSD API for compatibility with
existing code with an alternative implementation using Thread
Local Storage.

New version uses Thread Local Storage to store a pointer
with thread specific data. The destructor from TSD has been
replaced with a TLS destrucutor that is called upon thread
exit.

Diff Detail

Event Timeline

krytarowski created this revision.Dec 14 2018, 5:23 AM

On Fri, Dec 14, 2018 at 01:23:20PM +0000, Kamil Rytarowski via Phabricator wrote:

Index: lib/msan/msan_linux.cc

  • lib/msan/msan_linux.cc

+++ lib/msan/msan_linux.cc
@@ -34,6 +34,13 @@
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_procmaps.h"

+#if SANITIZER_NETBSD
+#include <sys/cdefs.h>
+extern "C" {
+int cxa_thread_atexit(void (*)(void *), void *, void *) weak;
+}
+#endif
+

What's the point of declaring it weak when it is used unconditionally?

Joerg

For some reason, without __weak it didn't build.

[100%] Built target c-arcmt-test
CMakeFiles/RTAsan_dynamic.i386.dir/asan_posix.cc.o: In function `__asan::AsanTSDSet(void*)':
/public/llvm/projects/compiler-rt/lib/asan/asan_posix.cc:78: undefined reference to `__cxa_thread_atexit(void (*)(void*), void*, void*)'
CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_posix.cc.o: In function `__asan::AsanTSDSet(void*)':
/public/llvm/projects/compiler-rt/lib/asan/asan_posix.cc:78: undefined reference to `__cxa_thread_atexit(void (*)(void*), void*, void*)'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
--- lib/clang/8.0.0/lib/netbsd/libclang_rt.asan-i386.so ---
*** [lib/clang/8.0.0/lib/netbsd/libclang_rt.asan-i386.so] Error code 1
krytarowski retitled this revision from Reimplement Thread Static Data MSan routines for NetBSD to Reimplement Thread Static Data MSan routines with TLS.
krytarowski edited the summary of this revision. (Show Details)

Ping? This is an important patch pending in review.

This revision is now accepted and ready to land.Dec 27 2018, 1:29 PM
This revision was automatically updated to reflect the committed changes.