[llvm-commits] [compiler-rt] r153177 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_globals.cc asan_malloc_linux.cc asan_printf.cc asan_rtl.cc asan_stack.cc asan_stats.cc asan_thread.cc
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Wed Mar 21 04:32:48 PDT 2012
Author: eugenis
Date: Wed Mar 21 06:32:46 2012
New Revision: 153177
URL: http://llvm.org/viewvc/llvm-project?rev=153177&view=rev
Log:
[asan] Support for %z to Printf()
At the moment, asan internal Printf() uses %l modifier for printing
values of size_t and related types. This works, because we control
both the implementation of Printf and all its uses, but can be a
little misleading.
This change adds support for %z to Printf(). All callers that print
sizes and pointers as integers are switched to %zu / %zx.
Modified:
compiler-rt/trunk/lib/asan/asan_allocator.cc
compiler-rt/trunk/lib/asan/asan_globals.cc
compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
compiler-rt/trunk/lib/asan/asan_printf.cc
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/asan/asan_stack.cc
compiler-rt/trunk/lib/asan/asan_stats.cc
compiler-rt/trunk/lib/asan/asan_thread.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Wed Mar 21 06:32:46 2012
@@ -219,15 +219,15 @@
size_t offset;
Printf("%p is located ", addr);
if (AddrIsInside(addr, access_size, &offset)) {
- Printf("%ld bytes inside of", offset);
+ Printf("%zu bytes inside of", offset);
} else if (AddrIsAtLeft(addr, access_size, &offset)) {
- Printf("%ld bytes to the left of", offset);
+ Printf("%zu bytes to the left of", offset);
} else if (AddrIsAtRight(addr, access_size, &offset)) {
- Printf("%ld bytes to the right of", offset);
+ Printf("%zu bytes to the right of", offset);
} else {
Printf(" somewhere around (this is AddressSanitizer bug!)");
}
- Printf(" %lu-byte region [%p,%p)\n",
+ Printf(" %zu-byte region [%p,%p)\n",
used_size, beg(), beg() + used_size);
}
};
@@ -389,7 +389,7 @@
ScopedLock lock(&mu_);
size_t malloced = 0;
- Printf(" MallocInfo: in quarantine: %ld malloced: %ld; ",
+ Printf(" MallocInfo: in quarantine: %zu malloced: %zu; ",
quarantine_.size() >> 20, malloced >> 20);
for (size_t j = 1; j < kNumberOfSizeClasses; j++) {
AsanChunk *i = free_lists_[j];
@@ -398,7 +398,7 @@
for (; i; i = i->next) {
t += i->Size();
}
- Printf("%ld:%ld ", j, t >> 20);
+ Printf("%zu:%zu ", j, t >> 20);
}
Printf("\n");
}
@@ -632,7 +632,7 @@
CHECK(IsAligned(size_to_allocate, REDZONE));
if (FLAG_v >= 2) {
- Printf("Allocate align: %ld size: %ld class: %d real: %ld\n",
+ Printf("Allocate align: %zu size: %zu class: %u real: %zu\n",
alignment, size, size_class, size_to_allocate);
}
@@ -912,7 +912,7 @@
size_t log = Log2(rounded_size);
CHECK(alloc_size <= (1UL << log));
if (!(alloc_size > (1UL << (log-1)))) {
- Printf("alloc_size %ld log %ld\n", alloc_size, log);
+ Printf("alloc_size %zu log %zu\n", alloc_size, log);
}
CHECK(alloc_size > (1UL << (log-1)));
size_t res = log < kMinStackFrameSizeLog ? 0 : log - kMinStackFrameSizeLog;
@@ -972,7 +972,7 @@
CHECK(ClassMmapSize(size_class) >= kPageSize);
uintptr_t new_mem = (uintptr_t)AsanMmapSomewhereOrDie(
ClassMmapSize(size_class), __FUNCTION__);
- // Printf("T%d new_mem[%ld]: %p-%p mmap %ld\n",
+ // Printf("T%d new_mem[%zu]: %p-%p mmap %zu\n",
// asanThreadRegistry().GetCurrent()->tid(),
// size_class, new_mem, new_mem + ClassMmapSize(size_class),
// ClassMmapSize(size_class));
@@ -1039,7 +1039,7 @@
return real_stack;
}
size_t ptr = t->fake_stack().AllocateStack(size, real_stack);
- // Printf("__asan_stack_malloc %p %ld %p\n", ptr, size, real_stack);
+ // Printf("__asan_stack_malloc %p %zu %p\n", ptr, size, real_stack);
return ptr;
}
Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Wed Mar 21 06:32:46 2012
@@ -74,13 +74,13 @@
if (addr >= g.beg + g.size_with_redzone) return false;
Printf("%p is located ", addr);
if (addr < g.beg) {
- Printf("%d bytes to the left", g.beg - addr);
+ Printf("%zd bytes to the left", g.beg - addr);
} else if (addr >= g.beg + g.size) {
- Printf("%d bytes to the right", addr - (g.beg + g.size));
+ Printf("%zd bytes to the right", addr - (g.beg + g.size));
} else {
- Printf("%d bytes inside", addr - g.beg); // Can it happen?
+ Printf("%zd bytes inside", addr - g.beg); // Can it happen?
}
- Printf(" of global variable '%s' (0x%lx) of size %ld\n",
+ Printf(" of global variable '%s' (0x%zx) of size %zu\n",
g.name, g.beg, g.size);
PrintIfASCII(g);
return true;
@@ -94,7 +94,7 @@
for (ListOfGlobals *l = list_of_globals; l; l = l->next) {
const Global &g = *l->g;
if (FLAG_report_globals >= 2)
- Printf("Search Global: beg=%p size=%ld name=%s\n",
+ Printf("Search Global: beg=%p size=%zu name=%s\n",
g.beg, g.size, g.name);
res |= DescribeAddrIfMyRedZone(g, addr);
}
@@ -117,7 +117,7 @@
l->next = list_of_globals;
list_of_globals = l;
if (FLAG_report_globals >= 2)
- Report("Added Global: beg=%p size=%ld name=%s\n",
+ Report("Added Global: beg=%p size=%zu name=%s\n",
g->beg, g->size, g->name);
}
Modified: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Wed Mar 21 06:32:46 2012
@@ -115,7 +115,7 @@
INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) {
GET_STACK_TRACE_HERE_FOR_MALLOC;
- // Printf("posix_memalign: %lx %ld\n", alignment, size);
+ // Printf("posix_memalign: %zx %zu\n", alignment, size);
return asan_posix_memalign(memptr, alignment, size, &stack);
}
Modified: compiler-rt/trunk/lib/asan/asan_printf.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_printf.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_printf.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_printf.cc Wed Mar 21 06:32:46 2012
@@ -108,7 +108,7 @@
static int VSNPrintf(char *buff, int buff_length,
const char *format, va_list args) {
static const char *kPrintfFormatsHelp = "Supported Printf formats: "
- "%%[l]{d,u,x}; %%p; %%s";
+ "%%[z]{d,u,x}; %%p; %%s";
RAW_CHECK(format);
RAW_CHECK(buff_length > 0);
const char *buff_end = &buff[buff_length - 1];
@@ -117,28 +117,28 @@
for (; *cur; cur++) {
if (*cur == '%') {
cur++;
- bool have_l = (*cur == 'l');
- cur += have_l;
+ bool have_z = (*cur == 'z');
+ cur += have_z;
int64_t dval;
- uint64_t uval, xval;
+ uint64_t uval;
switch (*cur) {
- case 'd': dval = have_l ? va_arg(args, intptr_t)
+ case 'd': dval = have_z ? va_arg(args, intptr_t)
: va_arg(args, int);
result += AppendSignedDecimal(&buff, buff_end, dval);
break;
- case 'u': uval = have_l ? va_arg(args, uintptr_t)
- : va_arg(args, unsigned int);
+ case 'u': uval = have_z ? va_arg(args, size_t)
+ : va_arg(args, unsigned);
result += AppendUnsigned(&buff, buff_end, uval, 10, 0);
break;
- case 'x': xval = have_l ? va_arg(args, uintptr_t)
- : va_arg(args, unsigned int);
- result += AppendUnsigned(&buff, buff_end, xval, 16, 0);
+ case 'x': uval = have_z ? va_arg(args, size_t)
+ : va_arg(args, unsigned);
+ result += AppendUnsigned(&buff, buff_end, uval, 16, 0);
break;
- case 'p': RAW_CHECK_MSG(!have_l, kPrintfFormatsHelp);
+ case 'p': RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
result += AppendPointer(&buff, buff_end,
va_arg(args, uintptr_t));
break;
- case 's': RAW_CHECK_MSG(!have_l, kPrintfFormatsHelp);
+ case 's': RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
result += AppendString(&buff, buff_end, va_arg(args, char*));
break;
default: RAW_CHECK_MSG(false, kPrintfFormatsHelp);
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed Mar 21 06:32:46 2012
@@ -66,9 +66,9 @@
static void PrintBytes(const char *before, uintptr_t *a) {
uint8_t *bytes = (uint8_t*)a;
size_t byte_num = (__WORDSIZE) / 8;
- Printf("%s%p:", before, (uintptr_t)a);
+ Printf("%s%p:", before, (void*)a);
for (size_t i = 0; i < byte_num; i++) {
- Printf(" %lx%lx", bytes[i] >> 4, bytes[i] & 15);
+ Printf(" %x%x", bytes[i] >> 4, bytes[i] & 15);
}
Printf("\n");
}
@@ -122,7 +122,7 @@
// ---------------------- mmap -------------------- {{{1
void OutOfMemoryMessageAndDie(const char *mem_type, size_t size) {
Report("ERROR: AddressSanitizer failed to allocate "
- "0x%lx (%ld) bytes of %s\n",
+ "0x%zx (%zd) bytes of %s\n",
size, size, mem_type);
PRINT_CURRENT_STACK();
ShowStatsAndAbort();
@@ -173,14 +173,14 @@
internal_strncat(buf, frame_descr,
Min(kBufSize,
static_cast<intptr_t>(name_end - frame_descr)));
- Printf("Address %p is located at offset %ld "
+ Printf("Address %p is located at offset %zu "
"in frame <%s> of T%d's stack:\n",
addr, offset, buf, t->tid());
// Report the number of stack objects.
char *p;
size_t n_objects = internal_simple_strtoll(name_end, &p, 10);
CHECK(n_objects > 0);
- Printf(" This frame has %ld object(s):\n", n_objects);
+ Printf(" This frame has %zu object(s):\n", n_objects);
// Report all objects in this frame.
for (size_t i = 0; i < n_objects; i++) {
size_t beg, size;
@@ -197,7 +197,7 @@
buf[0] = 0;
internal_strncat(buf, p, Min(kBufSize, len));
p += len;
- Printf(" [%ld, %ld) '%s'\n", beg, beg + size, buf);
+ Printf(" [%zu, %zu) '%s'\n", beg, beg + size, buf);
}
Printf("HINT: this may be a false positive if your program uses "
"some custom stack unwind mechanism\n"
@@ -374,10 +374,10 @@
}
Report("ERROR: AddressSanitizer %s on address "
- "%p at pc 0x%lx bp 0x%lx sp 0x%lx\n",
+ "%p at pc 0x%zx bp 0x%zx sp 0x%zx\n",
bug_descr, addr, pc, bp, sp);
- Printf("%s of size %d at %p thread T%d\n",
+ Printf("%s of size %zu at %p thread T%d\n",
access_size ? (is_write ? "WRITE" : "READ") : "ACCESS",
access_size, addr, curr_tid);
@@ -486,12 +486,12 @@
MEM_TO_SHADOW(kLowShadowEnd),
MEM_TO_SHADOW(kHighShadowBeg),
MEM_TO_SHADOW(kHighShadowEnd));
- Printf("red_zone=%ld\n", FLAG_redzone);
- Printf("malloc_context_size=%ld\n", (int)FLAG_malloc_context_size);
+ Printf("red_zone=%zu\n", (size_t)FLAG_redzone);
+ Printf("malloc_context_size=%zu\n", (size_t)FLAG_malloc_context_size);
- Printf("SHADOW_SCALE: %lx\n", SHADOW_SCALE);
- Printf("SHADOW_GRANULARITY: %lx\n", SHADOW_GRANULARITY);
- Printf("SHADOW_OFFSET: %lx\n", SHADOW_OFFSET);
+ Printf("SHADOW_SCALE: %zx\n", (size_t)SHADOW_SCALE);
+ Printf("SHADOW_GRANULARITY: %zx\n", (size_t)SHADOW_GRANULARITY);
+ Printf("SHADOW_OFFSET: %zx\n", (size_t)SHADOW_OFFSET);
CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7);
}
Modified: compiler-rt/trunk/lib/asan/asan_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.cc Wed Mar 21 06:32:46 2012
@@ -32,7 +32,7 @@
uintptr_t pc = addr[i];
char buff[4096];
ASAN_USE_EXTERNAL_SYMBOLIZER((void*)pc, buff, sizeof(buff));
- Printf(" #%ld 0x%lx %s\n", i, pc, buff);
+ Printf(" #%zu 0x%zx %s\n", i, pc, buff);
}
}
@@ -46,9 +46,9 @@
char filename[4096];
if (proc_maps.GetObjectNameAndOffset(pc, &offset,
filename, sizeof(filename))) {
- Printf(" #%ld 0x%lx (%s+0x%lx)\n", i, pc, filename, offset);
+ Printf(" #%zu 0x%zx (%s+0x%zx)\n", i, pc, filename, offset);
} else {
- Printf(" #%ld 0x%lx\n", i, pc);
+ Printf(" #%zu 0x%zx\n", i, pc);
}
}
}
@@ -104,19 +104,19 @@
uintptr_t pc = stack->trace[i];
if (!pc) break;
if ((int64_t)pc < 0) break;
- // Printf("C pc[%ld] %lx\n", i, pc);
+ // Printf("C pc[%zu] %zx\n", i, pc);
if (prev_pc - pc < kMaxOffset || pc - prev_pc < kMaxOffset) {
uintptr_t offset = (int64_t)(pc - prev_pc);
offset |= (1U << 31);
if (c_index >= size) break;
- // Printf("C co[%ld] offset %lx\n", i, offset);
+ // Printf("C co[%zu] offset %zx\n", i, offset);
compressed[c_index++] = offset;
} else {
uintptr_t hi = pc >> 32;
uintptr_t lo = (pc << 32) >> 32;
CHECK((hi & (1 << 31)) == 0);
if (c_index + 1 >= size) break;
- // Printf("C co[%ld] hi/lo: %lx %lx\n", c_index, hi, lo);
+ // Printf("C co[%zu] hi/lo: %zx %zx\n", c_index, hi, lo);
compressed[c_index++] = hi;
compressed[c_index++] = lo;
}
@@ -134,7 +134,7 @@
AsanStackTrace check_stack;
UncompressStack(&check_stack, compressed, size);
if (res < check_stack.size) {
- Printf("res %ld check_stack.size %ld; c_size %ld\n", res,
+ Printf("res %zu check_stack.size %zu; c_size %zu\n", res,
check_stack.size, size);
}
// |res| may be greater than check_stack.size, because
@@ -164,7 +164,7 @@
uint32_t x = compressed[i];
uintptr_t pc = 0;
if (x & (1U << 31)) {
- // Printf("U co[%ld] offset: %x\n", i, x);
+ // Printf("U co[%zu] offset: %x\n", i, x);
// this is an offset
int32_t offset = x;
offset = (offset << 1) >> 1; // remove the 31-byte and sign-extend.
@@ -175,12 +175,12 @@
if (i + 1 >= size) break;
uintptr_t hi = x;
uintptr_t lo = compressed[i+1];
- // Printf("U co[%ld] hi/lo: %lx %lx\n", i, hi, lo);
+ // Printf("U co[%zu] hi/lo: %zx %zx\n", i, hi, lo);
i++;
pc = (hi << 32) | lo;
if (!pc) break;
}
- // Printf("U pc[%ld] %lx\n", stack->size, pc);
+ // Printf("U pc[%zu] %zx\n", stack->size, pc);
stack->trace[stack->size++] = pc;
prev_pc = pc;
}
Modified: compiler-rt/trunk/lib/asan/asan_stats.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stats.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stats.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stats.cc Wed Mar 21 06:32:46 2012
@@ -30,26 +30,26 @@
Printf("%s", prefix);
for (size_t i = 0; i < kNumberOfSizeClasses; i++) {
if (!array[i]) continue;
- Printf("%ld:%ld; ", i, array[i]);
+ Printf("%zu:%zu; ", i, array[i]);
}
Printf("\n");
}
void AsanStats::Print() {
- Printf("Stats: %ldM malloced (%ldM for red zones) by %ld calls\n",
+ Printf("Stats: %zuM malloced (%zuM for red zones) by %zu calls\n",
malloced>>20, malloced_redzones>>20, mallocs);
- Printf("Stats: %ldM realloced by %ld calls\n", realloced>>20, reallocs);
- Printf("Stats: %ldM freed by %ld calls\n", freed>>20, frees);
- Printf("Stats: %ldM really freed by %ld calls\n",
+ Printf("Stats: %zuM realloced by %zu calls\n", realloced>>20, reallocs);
+ Printf("Stats: %zuM freed by %zu calls\n", freed>>20, frees);
+ Printf("Stats: %zuM really freed by %zu calls\n",
really_freed>>20, real_frees);
- Printf("Stats: %ldM (%ld full pages) mmaped in %ld calls\n",
+ Printf("Stats: %zuM (%zu full pages) mmaped in %zu calls\n",
mmaped>>20, mmaped / kPageSize, mmaps);
PrintMallocStatsArray(" mmaps by size class: ", mmaped_by_size);
PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size);
PrintMallocStatsArray(" frees by size class: ", freed_by_size);
PrintMallocStatsArray(" rfrees by size class: ", really_freed_by_size);
- Printf("Stats: malloc large: %ld small slow: %ld\n",
+ Printf("Stats: malloc large: %zu small slow: %zu\n",
malloc_large, malloc_small_slow);
}
Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=153177&r1=153176&r2=153177&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Wed Mar 21 06:32:46 2012
@@ -73,7 +73,7 @@
ClearShadowForThreadStack();
if (FLAG_v >= 1) {
int local = 0;
- Report("T%d: stack [%p,%p) size 0x%lx; local=%p\n",
+ Report("T%d: stack [%p,%p) size 0x%zx; local=%p\n",
tid(), stack_bottom_, stack_top_,
stack_top_ - stack_bottom_, &local);
}
More information about the llvm-commits
mailing list