diff options
| author | Alexey Samsonov <vonosmas@gmail.com> | 2014-10-27 03:10:27 +0000 |
|---|---|---|
| committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-10-27 03:10:27 +0000 |
| commit | e853b4f2e42d80156272ebca58a8e92c79d2082a (patch) | |
| tree | fb027654970ec7a66d4e3bdaadd80315bbd092a5 /compiler-rt/lib/sanitizer_common | |
| parent | 18c89411b8c24883bc2d7e86a4ec40ebc8957b54 (diff) | |
| download | bcm5719-llvm-e853b4f2e42d80156272ebca58a8e92c79d2082a.tar.gz bcm5719-llvm-e853b4f2e42d80156272ebca58a8e92c79d2082a.zip | |
[Sanitizer] Return code that calculates hash for stacktrace back to StackDepot implementation
llvm-svn: 220663
Diffstat (limited to 'compiler-rt/lib/sanitizer_common')
3 files changed, 24 insertions, 23 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc index afd45ddd2e1..f10f1f973fd 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc @@ -47,6 +47,28 @@ struct StackDepotNode { static uptr storage_size(const args_type &args) { return sizeof(StackDepotNode) + (args.size - 1) * sizeof(uptr); } + static u32 hash(const args_type &args) { + // murmur2 + const u32 m = 0x5bd1e995; + const u32 seed = 0x9747b28c; + const u32 r = 24; + u32 h = seed ^ (args.size * sizeof(uptr)); + for (uptr i = 0; i < args.size; i++) { + u32 k = args.trace[i]; + k *= m; + k ^= k >> r; + k *= m; + h *= m; + h ^= k; + } + h ^= h >> 13; + h *= m; + h ^= h >> 15; + return h; + } + static bool is_valid(const args_type &args) { + return args.size > 0 && args.trace; + } void store(const args_type &args, u32 hash) { atomic_store(&hash_and_use_count, hash & kHashMask, memory_order_relaxed); size = args.size; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h index d2d3d34980c..5de2e711fe4 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h @@ -97,8 +97,8 @@ typename StackDepotBase<Node, kReservedBits, kTabSizeLog>::handle_type StackDepotBase<Node, kReservedBits, kTabSizeLog>::Put(args_type args, bool *inserted) { if (inserted) *inserted = false; - if (!args.is_valid()) return handle_type(); - uptr h = args.hash(); + if (!Node::is_valid(args)) return handle_type(); + uptr h = Node::hash(args); atomic_uintptr_t *p = &tab[h % kTabSize]; uptr v = atomic_load(p, memory_order_consume); Node *s = (Node *)(v & ~1); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index a3d548804f9..4f613fad164 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -39,27 +39,6 @@ struct StackTrace { // Prints a symbolized stacktrace, followed by an empty line. void Print() const; - u32 hash() const { - // murmur2 - const u32 m = 0x5bd1e995; - const u32 seed = 0x9747b28c; - const u32 r = 24; - u32 h = seed ^ (size * sizeof(uptr)); - for (uptr i = 0; i < size; i++) { - u32 k = trace[i]; - k *= m; - k ^= k >> r; - k *= m; - h *= m; - h ^= k; - } - h ^= h >> 13; - h *= m; - h ^= h >> 15; - return h; - } - bool is_valid() const { return size > 0 && trace; } - static bool WillUseFastUnwind(bool request_fast_unwind) { // Check if fast unwind is available. Fast unwind is the only option on Mac. // It is also the only option on FreeBSD as the slow unwinding that |

