diff options
| author | Alexey Samsonov <samsonov@google.com> | 2012-08-27 14:51:36 +0000 |
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2012-08-27 14:51:36 +0000 |
| commit | d1d1a814b785cc28c3dac566423604ab7d66f54c (patch) | |
| tree | 9535488253769d0d980cdacd105974be3edf7177 /compiler-rt/lib | |
| parent | f72f08affc71970711b590eb6579be49e5aba25e (diff) | |
| download | bcm5719-llvm-d1d1a814b785cc28c3dac566423604ab7d66f54c.tar.gz bcm5719-llvm-d1d1a814b785cc28c3dac566423604ab7d66f54c.zip | |
[Sanitizer] align allocation sizes in low level allocator
llvm-svn: 162676
Diffstat (limited to 'compiler-rt/lib')
4 files changed, 9 insertions, 4 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc index b08434ad668..45fcb230c79 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.cc @@ -60,7 +60,8 @@ void *InternalAllocBlock(void *p) { static LowLevelAllocateCallback low_level_alloc_callback; void *LowLevelAllocator::Allocate(uptr size) { - CHECK((size & (size - 1)) == 0 && "size must be a power of two"); + // Align allocation size. + size = RoundUpTo(size, 8); if (allocated_end_ - allocated_current_ < (sptr)size) { uptr size_to_allocate = Max(size, kPageSize); allocated_current_ = diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 7c3930d8ec3..112de59b50a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -78,10 +78,12 @@ class InternalScopedBuffer { void operator=(const InternalScopedBuffer&); }; -// Simple low-level (mmap-based) allocator for internal use. +// Simple low-level (mmap-based) allocator for internal use. Doesn't have +// constructor, so all instances of LowLevelAllocator should be +// linker initialized. class LowLevelAllocator { public: - // 'size' must be a power of two. Requires an external lock. + // Requires an external lock. void *Allocate(uptr size); private: char *allocated_end_; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc index dd28d59670b..eca910c0809 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc @@ -86,7 +86,8 @@ void ParseFlag(const char *env, const char **flag, const char *name) { int value_length; if (!GetFlagValue(env, name, &value, &value_length)) return; - // Copy the flag value. + // Copy the flag value. Don't use locks here, as flags are parsed at + // tool startup. char *value_copy = (char*)(allocator_for_flags.Allocate(value_length + 1)); internal_memcpy(value_copy, value, value_length); value_copy[value_length] = '\0'; diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc index 4b273e5b9ce..f6b7a152df9 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc @@ -66,6 +66,7 @@ TEST(SanitizerCommon, StrFlags) { TestStrFlag("zzz", "--flag_name=", ""); TestStrFlag("", "--flag_name=abc", "abc"); TestStrFlag("", "--flag_name='abc zxc'", "abc zxc"); + TestStrFlag("", "--flag_name='abc zxcc'", "abc zxcc"); TestStrFlag("", "--flag_name=\"abc qwe\" asd", "abc qwe"); } |

