[llvm-commits] [compiler-rt] r162676 - in /compiler-rt/trunk/lib/sanitizer_common: sanitizer_allocator.cc sanitizer_common.h sanitizer_flags.cc tests/sanitizer_flags_test.cc
Alexey Samsonov
samsonov at google.com
Mon Aug 27 07:51:36 PDT 2012
Author: samsonov
Date: Mon Aug 27 09:51:36 2012
New Revision: 162676
URL: http://llvm.org/viewvc/llvm-project?rev=162676&view=rev
Log:
[Sanitizer] align allocation sizes in low level allocator
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc?rev=162676&r1=162675&r2=162676&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.cc Mon Aug 27 09:51:36 2012
@@ -60,7 +60,8 @@
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_ =
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=162676&r1=162675&r2=162676&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Aug 27 09:51:36 2012
@@ -78,10 +78,12 @@
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_;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=162676&r1=162675&r2=162676&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Mon Aug 27 09:51:36 2012
@@ -86,7 +86,8 @@
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';
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc?rev=162676&r1=162675&r2=162676&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_flags_test.cc Mon Aug 27 09:51:36 2012
@@ -66,6 +66,7 @@
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");
}
More information about the llvm-commits
mailing list