Skip to content

Commit bf4347b

Browse files
authored
[sanitizer_common] Use %p to print addresses (llvm#98578)
Pointers print more leading zeroes for better alignment.
1 parent c072580 commit bf4347b

14 files changed

+50
-41
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ class SizeClassAllocator64 {
316316
Printf(
317317
"%s %02zd (%6zd): mapped: %6zdK allocs: %7zd frees: %7zd inuse: %6zd "
318318
"num_freed_chunks %7zd avail: %6zd rss: %6zdK releases: %6zd "
319-
"last released: %6lldK region: 0x%zx\n",
319+
"last released: %6lldK region: %p\n",
320320
region->exhausted ? "F" : " ", class_id, ClassIdToSize(class_id),
321321
region->mapped_user >> 10, region->stats.n_allocated,
322322
region->stats.n_freed, in_use, region->num_freed_chunks, avail_chunks,
323323
rss >> 10, region->rtoi.num_releases,
324324
region->rtoi.last_released_bytes >> 10,
325-
SpaceBeg() + kRegionSize * class_id);
325+
(void *)(SpaceBeg() + kRegionSize * class_id));
326326
}
327327

328328
void PrintStats() {

compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ static void SanitizerDumpCoverage(const uptr* unsorted_pcs, uptr len) {
7575
if (!pc) continue;
7676

7777
if (!GetModuleAndOffsetForPc(pc, nullptr, 0, &pcs[i])) {
78-
Printf("ERROR: unknown pc 0x%zx (may happen if dlclose is used)\n", pc);
78+
Printf("ERROR: unknown pc %p (may happen if dlclose is used)\n",
79+
(void*)pc);
7980
continue;
8081
}
8182
uptr module_base = pc - pcs[i];

compiler-rt/lib/sanitizer_common/sanitizer_libignore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ void LibIgnore::OnLibraryLoaded(const char *name) {
105105
continue;
106106
if (IsPcInstrumented(range.beg) && IsPcInstrumented(range.end - 1))
107107
continue;
108-
VReport(1, "Adding instrumented range 0x%zx-0x%zx from library '%s'\n",
109-
range.beg, range.end, mod.full_name());
108+
VReport(1, "Adding instrumented range %p-%p from library '%s'\n",
109+
(void *)range.beg, (void *)range.end, mod.full_name());
110110
const uptr idx =
111111
atomic_load(&instrumented_ranges_count_, memory_order_relaxed);
112112
CHECK_LT(idx, ARRAY_SIZE(instrumented_code_ranges_));

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,8 @@ void DumpProcessMap() {
13721372
for (uptr i = 0; i < modules.size(); ++i) {
13731373
char uuid_str[128];
13741374
FormatUUID(uuid_str, sizeof(uuid_str), modules[i].uuid());
1375-
Printf("0x%zx-0x%zx %s (%s) %s\n", modules[i].base_address(),
1376-
modules[i].max_address(), modules[i].full_name(),
1375+
Printf("%p-%p %s (%s) %s\n", (void *)modules[i].base_address(),
1376+
(void *)modules[i].max_address(), modules[i].full_name(),
13771377
ModuleArchToString(modules[i].arch()), uuid_str);
13781378
}
13791379
Printf("End of module map.\n");

compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ static void *MmapFixedImpl(uptr fixed_addr, uptr size, bool tolerate_enomem,
130130
if (tolerate_enomem && reserrno == ENOMEM)
131131
return nullptr;
132132
char mem_type[40];
133-
internal_snprintf(mem_type, sizeof(mem_type), "memory at address 0x%zx",
134-
fixed_addr);
133+
internal_snprintf(mem_type, sizeof(mem_type), "memory at address %p",
134+
(void *)fixed_addr);
135135
ReportMmapFailureAndDie(size, mem_type, "allocate", reserrno);
136136
}
137137
IncreaseTotalMmap(size);

compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ static bool MmapFixed(uptr fixed_addr, uptr size, int additional_flags,
327327
MAP_PRIVATE | MAP_FIXED | additional_flags | MAP_ANON, name);
328328
int reserrno;
329329
if (internal_iserror(p, &reserrno)) {
330-
Report("ERROR: %s failed to "
331-
"allocate 0x%zx (%zd) bytes at address %zx (errno: %d)\n",
332-
SanitizerToolName, size, size, fixed_addr, reserrno);
330+
Report(
331+
"ERROR: %s failed to "
332+
"allocate 0x%zx (%zd) bytes at address %p (errno: %d)\n",
333+
SanitizerToolName, size, size, (void *)fixed_addr, reserrno);
333334
return false;
334335
}
335336
IncreaseTotalMmap(size);

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void FormattedStackTracePrinter::RenderFrame(InternalScopedString *buffer,
192192
buffer->AppendF("%u", frame_no);
193193
break;
194194
case 'p':
195-
buffer->AppendF("0x%zx", address);
195+
buffer->AppendF("%p", (void *)address);
196196
break;
197197
case 'm':
198198
buffer->AppendF("%s", StripPathPrefix(info->module, strip_path_prefix));

compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ static void TracerThreadDieCallback() {
257257
static void TracerThreadSignalHandler(int signum, __sanitizer_siginfo *siginfo,
258258
void *uctx) {
259259
SignalContext ctx(siginfo, uctx);
260-
Printf("Tracer caught signal %d: addr=0x%zx pc=0x%zx sp=0x%zx\n", signum,
261-
ctx.addr, ctx.pc, ctx.sp);
260+
Printf("Tracer caught signal %d: addr=%p pc=%p sp=%p\n", signum,
261+
(void *)ctx.addr, (void *)ctx.pc, (void *)ctx.sp);
262262
ThreadSuspender *inst = thread_suspender_instance;
263263
if (inst) {
264264
if (signum == SIGABRT)

compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ static void TracerThreadDieCallback() {
158158
static void TracerThreadSignalHandler(int signum, __sanitizer_siginfo *siginfo,
159159
void *uctx) {
160160
SignalContext ctx(siginfo, uctx);
161-
Printf("Tracer caught signal %d: addr=0x%zx pc=0x%zx sp=0x%zx\n", signum,
162-
ctx.addr, ctx.pc, ctx.sp);
161+
Printf("Tracer caught signal %d: addr=%p pc=%p sp=%p\n", signum,
162+
(void *)ctx.addr, (void *)ctx.pc, (void *)ctx.sp);
163163
ThreadSuspender *inst = thread_suspender_instance;
164164
if (inst) {
165165
if (signum == SIGABRT)

compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,25 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
121121
uptr tls_size = 0;
122122
uptr tls_beg = reinterpret_cast<uptr>(res) - arg->offset - kDtvOffset;
123123
VReport(2,
124-
"__tls_get_addr: %p {0x%zx,0x%zx} => %p; tls_beg: 0x%zx; sp: %p "
124+
"__tls_get_addr: %p {0x%zx,0x%zx} => %p; tls_beg: %p; sp: %p "
125125
"num_live_dtls %zd\n",
126-
(void *)arg, arg->dso_id, arg->offset, res, tls_beg, (void *)&tls_beg,
126+
(void *)arg, arg->dso_id, arg->offset, res, (void *)tls_beg, &tls_beg,
127127
atomic_load(&number_of_live_dtls, memory_order_relaxed));
128128
if (dtls.last_memalign_ptr == tls_beg) {
129129
tls_size = dtls.last_memalign_size;
130-
VReport(2, "__tls_get_addr: glibc <=2.24 suspected; tls={0x%zx,0x%zx}\n",
131-
tls_beg, tls_size);
130+
VReport(2, "__tls_get_addr: glibc <=2.24 suspected; tls={%p,0x%zx}\n",
131+
(void *)tls_beg, tls_size);
132132
} else if (tls_beg >= static_tls_begin && tls_beg < static_tls_end) {
133133
// This is the static TLS block which was initialized / unpoisoned at thread
134134
// creation.
135-
VReport(2, "__tls_get_addr: static tls: 0x%zx\n", tls_beg);
135+
VReport(2, "__tls_get_addr: static tls: %p\n", (void *)tls_beg);
136136
tls_size = 0;
137137
} else if (const void *start =
138138
__sanitizer_get_allocated_begin((void *)tls_beg)) {
139139
tls_beg = (uptr)start;
140140
tls_size = __sanitizer_get_allocated_size(start);
141-
VReport(2, "__tls_get_addr: glibc >=2.25 suspected; tls={0x%zx,0x%zx}\n",
142-
tls_beg, tls_size);
141+
VReport(2, "__tls_get_addr: glibc >=2.25 suspected; tls={%p,0x%zx}\n",
142+
(void *)tls_beg, tls_size);
143143
} else {
144144
VReport(2, "__tls_get_addr: Can't guess glibc version\n");
145145
// This may happen inside the DTOR of main thread, so just ignore it.

0 commit comments

Comments
 (0)