From 7a096596b2eead02405329a5504b0d71dd5b4a8d Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Mon, 30 Nov 2015 19:43:03 +0000 Subject: [PATCH] [compiler-rt] Remove SANITIZER_AARCH64_VMA usage This patch complete removed SANITIZER_AARCH64_VMA definition and usage. AArch64 ports now supports runtime VMA detection and instrumentation for 39 and 42-bit VMA. It also Rewrite print_address to take a variadic argument list (the addresses to print) and adjust the tests which uses it to the new signature. llvm-svn: 254319 --- .../lib/sanitizer_common/sanitizer_platform.h | 14 +------- .../lib/sanitizer_common/sanitizer_posix.cc | 16 --------- .../test/tsan/Darwin/symbolizer-atos.cc | 4 +-- .../test/tsan/Darwin/symbolizer-dladdr.cc | 4 +-- .../tsan/deadlock_detector_stress_test.cc | 4 +-- compiler-rt/test/tsan/global_race.cc | 4 +-- compiler-rt/test/tsan/global_race2.cc | 4 +-- compiler-rt/test/tsan/global_race3.cc | 4 +-- compiler-rt/test/tsan/memcmp_race.cc | 2 +- compiler-rt/test/tsan/memcpy_race.cc | 2 +- compiler-rt/test/tsan/mop_with_offset.cc | 4 +-- compiler-rt/test/tsan/mop_with_offset2.cc | 4 +-- compiler-rt/test/tsan/race_on_heap.cc | 3 +- compiler-rt/test/tsan/test.h | 36 ++++++++----------- 14 files changed, 30 insertions(+), 75 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h index a60691efbea0..841cceb510a8 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -81,16 +81,6 @@ # define SANITIZER_X32 0 #endif -// VMA size definition for architecture that support multiple sizes. -// AArch64 has 3 VMA sizes: 39, 42 and 48. -#if !defined(SANITIZER_AARCH64_VMA) -# define SANITIZER_AARCH64_VMA 39 -#else -# if SANITIZER_AARCH64_VMA != 39 && SANITIZER_AARCH64_VMA != 42 -# error "invalid SANITIZER_AARCH64_VMA size" -# endif -#endif - // By default we allow to use SizeClassAllocator64 on 64-bit platform. // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64 // does not work well and we need to fallback to SizeClassAllocator32. @@ -137,10 +127,8 @@ #define SANITIZER_USES_UID16_SYSCALLS 0 #endif -#if defined(__mips__) || (defined(__aarch64__) && SANITIZER_AARCH64_VMA == 39) +#if defined(__mips__) # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10) -#elif defined(__aarch64__) && SANITIZER_AARCH64_VMA == 42 -# define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 11) #else # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12) #endif diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index 333fbe1f13e7..5ae68663df0e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -321,22 +321,6 @@ SignalContext SignalContext::Create(void *siginfo, void *context) { return SignalContext(context, addr, pc, sp, bp); } -// This function check is the built VMA matches the runtime one for -// architectures with multiple VMA size. -void CheckVMASize() { -#ifdef __aarch64__ - static const unsigned kBuiltVMA = SANITIZER_AARCH64_VMA; - unsigned maxRuntimeVMA = - (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1); - if (kBuiltVMA != maxRuntimeVMA) { - Printf("WARNING: %s runtime VMA is not the one built for.\n", - SanitizerToolName); - Printf("\tBuilt VMA: %u bits\n", kBuiltVMA); - Printf("\tRuntime VMA: %u bits\n", maxRuntimeVMA); - } -#endif -} - } // namespace __sanitizer #endif // SANITIZER_POSIX diff --git a/compiler-rt/test/tsan/Darwin/symbolizer-atos.cc b/compiler-rt/test/tsan/Darwin/symbolizer-atos.cc index 318ecf0783f7..960fecc98641 100644 --- a/compiler-rt/test/tsan/Darwin/symbolizer-atos.cc +++ b/compiler-rt/test/tsan/Darwin/symbolizer-atos.cc @@ -12,9 +12,7 @@ void *Thread(void *a) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr="); - print_address(GlobalData); - fprintf(stderr, "\n"); + print_address("addr=", 1, GlobalData); pthread_t t; pthread_create(&t, 0, Thread, 0); GlobalData[2] = 43; diff --git a/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cc b/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cc index bb7aa75359fb..3b213dda85d4 100644 --- a/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cc +++ b/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cc @@ -12,9 +12,7 @@ void *Thread(void *a) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr="); - print_address(GlobalData); - fprintf(stderr, "\n"); + print_address("addr=", 1, GlobalData); pthread_t t; pthread_create(&t, 0, Thread, 0); GlobalData[2] = 43; diff --git a/compiler-rt/test/tsan/deadlock_detector_stress_test.cc b/compiler-rt/test/tsan/deadlock_detector_stress_test.cc index 41ad5818bdf1..bbaaabbb3c14 100644 --- a/compiler-rt/test/tsan/deadlock_detector_stress_test.cc +++ b/compiler-rt/test/tsan/deadlock_detector_stress_test.cc @@ -152,7 +152,7 @@ class LockTest { fprintf(stderr, "Starting Test1\n"); // CHECK: Starting Test1 Init(5); - fprintf(stderr, "Expecting lock inversion: %p %p\n", A(0), A(1)); + print_address("Expecting lock inversion: ", 2, A(0), A(1)); // CHECK: Expecting lock inversion: [[A1:0x[a-f0-9]*]] [[A2:0x[a-f0-9]*]] Lock_0_1(); Lock_1_0(); @@ -178,7 +178,7 @@ class LockTest { fprintf(stderr, "Starting Test2\n"); // CHECK: Starting Test2 Init(5); - fprintf(stderr, "Expecting lock inversion: %p %p %p\n", A(0), A(1), A(2)); + print_address("Expecting lock inversion: ", 3, A(0), A(1), A(2)); // CHECK: Expecting lock inversion: [[A1:0x[a-f0-9]*]] [[A2:0x[a-f0-9]*]] [[A3:0x[a-f0-9]*]] Lock2(0, 1); Lock2(1, 2); diff --git a/compiler-rt/test/tsan/global_race.cc b/compiler-rt/test/tsan/global_race.cc index d1f0e3859637..a35299619e9d 100644 --- a/compiler-rt/test/tsan/global_race.cc +++ b/compiler-rt/test/tsan/global_race.cc @@ -11,9 +11,7 @@ void *Thread(void *a) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr="); - print_address(GlobalData); - fprintf(stderr, "\n"); + print_address("addr=", 1, GlobalData); pthread_t t; pthread_create(&t, 0, Thread, 0); GlobalData[2] = 43; diff --git a/compiler-rt/test/tsan/global_race2.cc b/compiler-rt/test/tsan/global_race2.cc index 5c29a78c789d..95dff1997808 100644 --- a/compiler-rt/test/tsan/global_race2.cc +++ b/compiler-rt/test/tsan/global_race2.cc @@ -11,9 +11,7 @@ void *Thread(void *a) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr2="); - print_address(&x); - fprintf(stderr, "\n"); + print_address("addr2=", 1, &x); pthread_t t; pthread_create(&t, 0, Thread, 0); x = 0; diff --git a/compiler-rt/test/tsan/global_race3.cc b/compiler-rt/test/tsan/global_race3.cc index 6361c4339a93..e0d59d284420 100644 --- a/compiler-rt/test/tsan/global_race3.cc +++ b/compiler-rt/test/tsan/global_race3.cc @@ -16,9 +16,7 @@ void *Thread(void *a) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr3="); - print_address(XXX::YYY::ZZZ); - fprintf(stderr, "\n"); + print_address("addr3=", 1, XXX::YYY::ZZZ); pthread_t t; pthread_create(&t, 0, Thread, 0); XXX::YYY::ZZZ[0] = 0; diff --git a/compiler-rt/test/tsan/memcmp_race.cc b/compiler-rt/test/tsan/memcmp_race.cc index 03287ff1906c..b76f427e121c 100644 --- a/compiler-rt/test/tsan/memcmp_race.cc +++ b/compiler-rt/test/tsan/memcmp_race.cc @@ -23,7 +23,7 @@ void *Thread2(void *x) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr=%p\n", &data0[5]); + print_address("addr=", 1, &data0[5]); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, NULL); pthread_create(&t[1], NULL, Thread2, NULL); diff --git a/compiler-rt/test/tsan/memcpy_race.cc b/compiler-rt/test/tsan/memcpy_race.cc index 797fbc0fdfff..4a098c0405fc 100644 --- a/compiler-rt/test/tsan/memcpy_race.cc +++ b/compiler-rt/test/tsan/memcpy_race.cc @@ -22,7 +22,7 @@ void *Thread2(void *x) { int main() { barrier_init(&barrier, 2); - fprintf(stderr, "addr=%p\n", &data[5]); + print_address("addr=", 1, &data[5]); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, NULL); pthread_create(&t[1], NULL, Thread2, NULL); diff --git a/compiler-rt/test/tsan/mop_with_offset.cc b/compiler-rt/test/tsan/mop_with_offset.cc index c67e81e09cda..e2496d099ef1 100644 --- a/compiler-rt/test/tsan/mop_with_offset.cc +++ b/compiler-rt/test/tsan/mop_with_offset.cc @@ -18,8 +18,8 @@ void *Thread2(void *x) { int main() { barrier_init(&barrier, 2); int *data = new int(42); - fprintf(stderr, "ptr1=%p\n", data); - fprintf(stderr, "ptr2=%p\n", (char*)data + 2); + print_address("ptr1=", 1, data); + print_address("ptr2=", 1, (char*)data + 2); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, data); pthread_create(&t[1], NULL, Thread2, data); diff --git a/compiler-rt/test/tsan/mop_with_offset2.cc b/compiler-rt/test/tsan/mop_with_offset2.cc index 460267359cec..73c53f51233a 100644 --- a/compiler-rt/test/tsan/mop_with_offset2.cc +++ b/compiler-rt/test/tsan/mop_with_offset2.cc @@ -18,8 +18,8 @@ void *Thread2(void *x) { int main() { barrier_init(&barrier, 2); int *data = new int(42); - fprintf(stderr, "ptr1=%p\n", data); - fprintf(stderr, "ptr2=%p\n", (char*)data + 2); + print_address("ptr1=", 1, data); + print_address("ptr2=", 1, (char*)data + 2); pthread_t t[2]; pthread_create(&t[0], NULL, Thread1, data); pthread_create(&t[1], NULL, Thread2, data); diff --git a/compiler-rt/test/tsan/race_on_heap.cc b/compiler-rt/test/tsan/race_on_heap.cc index a66e0c4f93f7..6c2defc835a6 100644 --- a/compiler-rt/test/tsan/race_on_heap.cc +++ b/compiler-rt/test/tsan/race_on_heap.cc @@ -2,6 +2,7 @@ #include #include #include +#include "test.h" void *Thread1(void *p) { *(int*)p = 42; @@ -26,7 +27,7 @@ int main() { pthread_t t[2]; pthread_create(&t[0], 0, AllocThread, 0); pthread_join(t[0], &p); - fprintf(stderr, "addr=%p\n", p); + print_address("addr=", 1, p); pthread_create(&t[0], 0, Thread1, (char*)p + 16); pthread_create(&t[1], 0, Thread2, (char*)p + 16); pthread_join(t[0], 0); diff --git a/compiler-rt/test/tsan/test.h b/compiler-rt/test/tsan/test.h index aa4d81b10ef2..e7ffefdcf21a 100644 --- a/compiler-rt/test/tsan/test.h +++ b/compiler-rt/test/tsan/test.h @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef __APPLE__ #include @@ -39,30 +40,21 @@ void barrier_wait(invisible_barrier_t *barrier) { // Default instance of the barrier, but a test can declare more manually. invisible_barrier_t barrier; -void print_address(void *address) { -// On FreeBSD, the %p conversion specifier works as 0x%x and thus does not match -// to the format used in the diagnotic message. -#ifdef __x86_64__ - fprintf(stderr, "0x%012lx", (unsigned long) address); +void print_address(const char *str, int n, ...) { + fprintf(stderr, "%s", str); + va_list ap; + va_start(ap, n); + while (n--) { + void *p = va_arg(ap, void *); +#if defined(__x86_64__) || defined(__aarch64__) + // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not + // match to the format used in the diagnotic message. + fprintf(stderr, "0x%012lx ", (unsigned long) p); #elif defined(__mips64) - fprintf(stderr, "0x%010lx", (unsigned long) address); -#elif defined(__aarch64__) - // AArch64 currently has 3 different VMA (39, 42, and 48 bits) and it requires - // different pointer size to match the diagnostic message. - const char *format = 0; - unsigned long vma = (unsigned long)__builtin_frame_address(0); - vma = 64 - __builtin_clzll(vma); - if (vma == 39) - format = "0x%010lx"; - else if (vma == 42) - format = "0x%011lx"; - else { - fprintf(stderr, "unsupported vma: %lu\n", vma); - exit(1); - } - - fprintf(stderr, format, (unsigned long) address); + fprintf(stderr, "0x%010lx ", (unsigned long) p); #endif + } + fprintf(stderr, "\n"); } #ifdef __APPLE__