summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-10-25 23:03:29 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-10-25 23:03:29 +0000
commitc1a1ed62228288155459d39194995a36aca4a8a6 (patch)
tree4bb3144d74f7d3db0bcfcecc867ed7b13e83e3f0 /lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
parent8f0c5bdd9650256501bad9fc5dedc977f4ca2247 (diff)
downloadcompiler-rt-c1a1ed62228288155459d39194995a36aca4a8a6.tar.gz
compiler-rt-c1a1ed62228288155459d39194995a36aca4a8a6.tar.bz2
compiler-rt-c1a1ed62228288155459d39194995a36aca4a8a6.tar.xz
Overhaul the symbolizer interface.
This moves away from creating the symbolizer object and initializing the external symbolizer as separate steps. Those steps now always take place together. Sanitizers with a legacy requirement to specify their own symbolizer path should use InitSymbolizer to initialize the symbolizer with the desired path, and GetSymbolizer to access the symbolizer. Sanitizers with no such requirement (e.g. UBSan) can use GetOrInitSymbolizer with no need for initialization. The symbolizer interface has been made thread-safe (as far as I can tell) by protecting its member functions with mutexes. Finally, the symbolizer interface no longer relies on weak externals, the introduction of which was probably a mistake on my part. Differential Revision: http://llvm-reviews.chandlerc.com/D1985 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193448 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc b/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
new file mode 100644
index 00000000..ada7be15
--- /dev/null
+++ b/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
@@ -0,0 +1,47 @@
+//===-- sanitizer_symbolizer_libcdep.cc -----------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is shared between AddressSanitizer and ThreadSanitizer
+// run-time libraries.
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_platform.h"
+#include "sanitizer_internal_defs.h"
+#include "sanitizer_placement_new.h"
+#include "sanitizer_symbolizer.h"
+
+namespace __sanitizer {
+
+Symbolizer *Symbolizer::CreateAndStore(const char *path_to_external) {
+ Symbolizer *platform_symbolizer = PlatformInit(path_to_external);
+ if (!platform_symbolizer) return Disable();
+ atomic_store(&symbolizer_, reinterpret_cast<uptr>(platform_symbolizer),
+ memory_order_release);
+ return platform_symbolizer;
+}
+
+Symbolizer *Symbolizer::Init(const char *path_to_external) {
+ CHECK_EQ(0, atomic_load(&symbolizer_, memory_order_acquire));
+ return CreateAndStore(path_to_external);
+}
+
+Symbolizer *Symbolizer::GetOrInit() {
+ static StaticSpinMutex init_mu;
+
+ uptr sym = atomic_load(&symbolizer_, memory_order_acquire);
+ if (!sym) {
+ SpinMutexLock l(&init_mu);
+ sym = atomic_load(&symbolizer_, memory_order_relaxed);
+ if (!sym) return CreateAndStore(0);
+ }
+
+ return reinterpret_cast<Symbolizer *>(sym);
+}
+
+} // namespace __sanitizer