diff options
author | Dean Michael Berris <dberris@google.com> | 2018-07-10 08:25:44 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2018-07-10 08:25:44 +0000 |
commit | 652950651ff6b1748fa97d152e670c2f92902e50 (patch) | |
tree | 38a172c80f4bb603a432b33d83af8bbefb2a18df /lib/xray/xray_profile_collector.cc | |
parent | a164037c709a816851d82be4643cacfafc4672f9 (diff) |
[XRay][compiler-rt] xray::Array Freelist and Iterator Updates
Summary:
We found a bug while working on a benchmark for the profiling mode which
manifests as a segmentation fault in the profiling handler's
implementation. This change adds unit tests which replicate the
issues in isolation.
We've tracked this down as a bug in the implementation of the Freelist
in the `xray::Array` type. This happens when we trim the array by a
number of elements, where we've been incorrectly assigning pointers for
the links in the freelist of chunk nodes. We've taken the chance to add
more debug-only assertions to the code path and allow us to verify these
assumptions in debug builds.
In the process, we also took the opportunity to use iterators to
implement both `front()` and `back()` which exposes a bug in the
iterator decrement operation. In particular, when we decrement past a
chunk size boundary, we end up moving too far back and reaching the
`SentinelChunk` prematurely.
This change unblocks us to allow for contributing the non-crashing
version of the benchmarks in the test-suite as well.
Reviewers: kpw
Subscribers: mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D48653
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@336644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/xray/xray_profile_collector.cc')
-rw-r--r-- | lib/xray/xray_profile_collector.cc | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/xray/xray_profile_collector.cc b/lib/xray/xray_profile_collector.cc index 9d057863e..5da8073f5 100644 --- a/lib/xray/xray_profile_collector.cc +++ b/lib/xray/xray_profile_collector.cc @@ -16,8 +16,8 @@ #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_vector.h" #include "xray_profiling_flags.h" -#include <pthread.h> #include <memory> +#include <pthread.h> #include <utility> namespace __xray { @@ -55,7 +55,8 @@ void post(const FunctionCallTrie &T, tid_t TId) { GlobalAllocators = reinterpret_cast<FunctionCallTrie::Allocators *>( InternalAlloc(sizeof(FunctionCallTrie::Allocators))); new (GlobalAllocators) FunctionCallTrie::Allocators(); - *GlobalAllocators = FunctionCallTrie::InitAllocators(); + *GlobalAllocators = FunctionCallTrie::InitAllocatorsCustom( + profilingFlags()->global_allocator_max); }); DCHECK_NE(GlobalAllocators, nullptr); @@ -83,12 +84,11 @@ void post(const FunctionCallTrie &T, tid_t TId) { // and is decoupled from the lifetime management required by the managed // allocator we have in XRay. // - Item->Trie = reinterpret_cast<FunctionCallTrie *>( - InternalAlloc(sizeof(FunctionCallTrie))); + Item->Trie = reinterpret_cast<FunctionCallTrie *>(InternalAlloc( + sizeof(FunctionCallTrie), nullptr, alignof(FunctionCallTrie))); DCHECK_NE(Item->Trie, nullptr); new (Item->Trie) FunctionCallTrie(*GlobalAllocators); } - DCHECK_NE(Item, nullptr); T.deepCopyInto(*Item->Trie); } |