From c191b1abe9db08abdf3b2d792980e8eee63735b5 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 1 Aug 2018 17:17:29 +0000 Subject: [PATCH] Cherry-pick compiler-rt revision 318044 and 319180. [PowerPC][tsan] Update tsan to handle changed memory layouts in newer kernels In more recent Linux kernels with 47 bit VMAs the layout of virtual memory for powerpc64 changed causing the thread sanitizer to not work properly. This patch adds support for 47 bit VMA kernels for powerpc64. Tested on several 4.x and 3.x kernel releases. Regtested/bootstrapped on ppc64le-linux with kernel 4.14; applying to trunk/8.3. 2018-08-01 Marek Polacek PR sanitizer/86759 * tsan/tsan_platform.h: Cherry-pick compiler-rt revision 318044. * tsan/tsan_platform_linux.cc: Cherry-pick compiler-rt revision 319180. From-SVN: r263229 --- libsanitizer/ChangeLog | 7 ++ libsanitizer/tsan/tsan_platform.h | 122 ++++++++++++++++------- libsanitizer/tsan/tsan_platform_linux.cc | 4 +- 3 files changed, 95 insertions(+), 38 deletions(-) diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog index 8e984f8b2e4..52b88337f00 100644 --- a/libsanitizer/ChangeLog +++ b/libsanitizer/ChangeLog @@ -1,3 +1,10 @@ +2018-08-01 Marek Polacek + + PR sanitizer/86759 + * tsan/tsan_platform.h: Cherry-pick compiler-rt revision 318044. + * tsan/tsan_platform_linux.cc: Cherry-pick compiler-rt revision + 319180. + 2018-07-25 H.J. Lu PR target/86560 diff --git a/libsanitizer/tsan/tsan_platform.h b/libsanitizer/tsan/tsan_platform.h index ddf4b13d05a..44a3ea99107 100644 --- a/libsanitizer/tsan/tsan_platform.h +++ b/libsanitizer/tsan/tsan_platform.h @@ -301,6 +301,38 @@ struct Mapping46 { static const uptr kVdsoBeg = 0x7800000000000000ull; }; +/* +C/C++ on linux/powerpc64 (47-bit VMA) +0000 0000 1000 - 0100 0000 0000: main binary +0100 0000 0000 - 0200 0000 0000: - +0100 0000 0000 - 1000 0000 0000: shadow +1000 0000 0000 - 1000 0000 0000: - +1000 0000 0000 - 2000 0000 0000: metainfo (memory blocks and sync objects) +2000 0000 0000 - 2000 0000 0000: - +2000 0000 0000 - 2200 0000 0000: traces +2200 0000 0000 - 7d00 0000 0000: - +7d00 0000 0000 - 7e00 0000 0000: heap +7e00 0000 0000 - 7e80 0000 0000: - +7e80 0000 0000 - 8000 0000 0000: modules and main thread stack +*/ +struct Mapping47 { + static const uptr kMetaShadowBeg = 0x100000000000ull; + static const uptr kMetaShadowEnd = 0x200000000000ull; + static const uptr kTraceMemBeg = 0x200000000000ull; + static const uptr kTraceMemEnd = 0x220000000000ull; + static const uptr kShadowBeg = 0x010000000000ull; + static const uptr kShadowEnd = 0x100000000000ull; + static const uptr kHeapMemBeg = 0x7d0000000000ull; + static const uptr kHeapMemEnd = 0x7e0000000000ull; + static const uptr kLoAppMemBeg = 0x000000001000ull; + static const uptr kLoAppMemEnd = 0x010000000000ull; + static const uptr kHiAppMemBeg = 0x7e8000000000ull; + static const uptr kHiAppMemEnd = 0x800000000000ull; // 47 bits + static const uptr kAppMemMsk = 0x7c0000000000ull; + static const uptr kAppMemXor = 0x020000000000ull; + static const uptr kVdsoBeg = 0x7800000000000000ull; +}; + // Indicates the runtime will define the memory regions at runtime. #define TSAN_RUNTIME_VMA 1 #endif @@ -427,11 +459,13 @@ uptr MappingArchImpl(void) { DCHECK(0); return 0; #elif defined(__powerpc64__) - if (vmaSize == 44) - return MappingImpl(); - else - return MappingImpl(); + switch (vmaSize) { + case 44: return MappingImpl(); + case 46: return MappingImpl(); + case 47: return MappingImpl(); + } DCHECK(0); + return 0; #else return MappingImpl(); #endif @@ -580,11 +614,13 @@ bool IsAppMem(uptr mem) { DCHECK(0); return false; #elif defined(__powerpc64__) - if (vmaSize == 44) - return IsAppMemImpl(mem); - else - return IsAppMemImpl(mem); + switch (vmaSize) { + case 44: return IsAppMemImpl(mem); + case 46: return IsAppMemImpl(mem); + case 47: return IsAppMemImpl(mem); + } DCHECK(0); + return false; #else return IsAppMemImpl(mem); #endif @@ -607,11 +643,13 @@ bool IsShadowMem(uptr mem) { DCHECK(0); return false; #elif defined(__powerpc64__) - if (vmaSize == 44) - return IsShadowMemImpl(mem); - else - return IsShadowMemImpl(mem); + switch (vmaSize) { + case 44: return IsShadowMemImpl(mem); + case 46: return IsShadowMemImpl(mem); + case 47: return IsShadowMemImpl(mem); + } DCHECK(0); + return false; #else return IsShadowMemImpl(mem); #endif @@ -634,11 +672,13 @@ bool IsMetaMem(uptr mem) { DCHECK(0); return false; #elif defined(__powerpc64__) - if (vmaSize == 44) - return IsMetaMemImpl(mem); - else - return IsMetaMemImpl(mem); + switch (vmaSize) { + case 44: return IsMetaMemImpl(mem); + case 46: return IsMetaMemImpl(mem); + case 47: return IsMetaMemImpl(mem); + } DCHECK(0); + return false; #else return IsMetaMemImpl(mem); #endif @@ -671,11 +711,13 @@ uptr MemToShadow(uptr x) { DCHECK(0); return 0; #elif defined(__powerpc64__) - if (vmaSize == 44) - return MemToShadowImpl(x); - else - return MemToShadowImpl(x); + switch (vmaSize) { + case 44: return MemToShadowImpl(x); + case 46: return MemToShadowImpl(x); + case 47: return MemToShadowImpl(x); + } DCHECK(0); + return 0; #else return MemToShadowImpl(x); #endif @@ -710,11 +752,13 @@ u32 *MemToMeta(uptr x) { DCHECK(0); return 0; #elif defined(__powerpc64__) - if (vmaSize == 44) - return MemToMetaImpl(x); - else - return MemToMetaImpl(x); + switch (vmaSize) { + case 44: return MemToMetaImpl(x); + case 46: return MemToMetaImpl(x); + case 47: return MemToMetaImpl(x); + } DCHECK(0); + return 0; #else return MemToMetaImpl(x); #endif @@ -762,11 +806,13 @@ uptr ShadowToMem(uptr s) { DCHECK(0); return 0; #elif defined(__powerpc64__) - if (vmaSize == 44) - return ShadowToMemImpl(s); - else - return ShadowToMemImpl(s); + switch (vmaSize) { + case 44: return ShadowToMemImpl(s); + case 46: return ShadowToMemImpl(s); + case 47: return ShadowToMemImpl(s); + } DCHECK(0); + return 0; #else return ShadowToMemImpl(s); #endif @@ -797,11 +843,13 @@ uptr GetThreadTrace(int tid) { DCHECK(0); return 0; #elif defined(__powerpc64__) - if (vmaSize == 44) - return GetThreadTraceImpl(tid); - else - return GetThreadTraceImpl(tid); + switch (vmaSize) { + case 44: return GetThreadTraceImpl(tid); + case 46: return GetThreadTraceImpl(tid); + case 47: return GetThreadTraceImpl(tid); + } DCHECK(0); + return 0; #else return GetThreadTraceImpl(tid); #endif @@ -827,11 +875,13 @@ uptr GetThreadTraceHeader(int tid) { DCHECK(0); return 0; #elif defined(__powerpc64__) - if (vmaSize == 44) - return GetThreadTraceHeaderImpl(tid); - else - return GetThreadTraceHeaderImpl(tid); + switch (vmaSize) { + case 44: return GetThreadTraceHeaderImpl(tid); + case 46: return GetThreadTraceHeaderImpl(tid); + case 47: return GetThreadTraceHeaderImpl(tid); + } DCHECK(0); + return 0; #else return GetThreadTraceHeaderImpl(tid); #endif diff --git a/libsanitizer/tsan/tsan_platform_linux.cc b/libsanitizer/tsan/tsan_platform_linux.cc index f8ae2567478..d46dff45a67 100644 --- a/libsanitizer/tsan/tsan_platform_linux.cc +++ b/libsanitizer/tsan/tsan_platform_linux.cc @@ -214,9 +214,9 @@ void InitializePlatformEarly() { Die(); } #elif defined(__powerpc64__) - if (vmaSize != 44 && vmaSize != 46) { + if (vmaSize != 44 && vmaSize != 46 && vmaSize != 47) { Printf("FATAL: ThreadSanitizer: unsupported VMA range\n"); - Printf("FATAL: Found %d - Supported 44 and 46\n", vmaSize); + Printf("FATAL: Found %d - Supported 44, 46, and 47\n", vmaSize); Die(); } #endif -- 2.30.2