diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp --- a/compiler-rt/lib/asan/asan_errors.cpp +++ b/compiler-rt/lib/asan/asan_errors.cpp @@ -539,7 +539,8 @@ u8 *bytes, u8 *guilty, uptr n) { Decorator d; if (before) - str->append("%s%p:", before, (void *)bytes); + str->append("%s%p:", before, + (void *)ShadowToMem(reinterpret_cast(bytes))); for (uptr i = 0; i < n; i++) { u8 *p = bytes + i; const char *before = diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h --- a/compiler-rt/lib/asan/asan_mapping.h +++ b/compiler-rt/lib/asan/asan_mapping.h @@ -272,6 +272,8 @@ # else # define MEM_TO_SHADOW(mem) \ (((mem) >> ASAN_SHADOW_SCALE) + (ASAN_SHADOW_OFFSET)) +# define SHADOW_TO_MEM(mem) \ + (((mem) - (ASAN_SHADOW_OFFSET)) << (ASAN_SHADOW_SCALE)) # define kLowMemBeg 0 # define kLowMemEnd (ASAN_SHADOW_OFFSET ? ASAN_SHADOW_OFFSET - 1 : 0) @@ -376,6 +378,12 @@ return AddrIsInLowShadow(a) || AddrIsInMidShadow(a) || AddrIsInHighShadow(a); } +static inline uptr ShadowToMem(uptr p) { + PROFILE_ASAN_MAPPING(); + CHECK(AddrIsInShadow(p)); + return SHADOW_TO_MEM(p); +} + static inline bool AddrIsAlignedByGranularity(uptr a) { PROFILE_ASAN_MAPPING(); return (a & (ASAN_SHADOW_GRANULARITY - 1)) == 0; diff --git a/compiler-rt/lib/asan/asan_mapping_sparc64.h b/compiler-rt/lib/asan/asan_mapping_sparc64.h --- a/compiler-rt/lib/asan/asan_mapping_sparc64.h +++ b/compiler-rt/lib/asan/asan_mapping_sparc64.h @@ -28,6 +28,7 @@ #define MEM_TO_SHADOW(mem) \ ((((mem) << HIGH_BITS) >> (HIGH_BITS + (ASAN_SHADOW_SCALE))) + \ (ASAN_SHADOW_OFFSET)) +#define SHADOW_TO_MEM(ptr) (__asan::ShadowToMemSparc64(ptr)) #define kLowMemBeg 0 #define kLowMemEnd (ASAN_SHADOW_OFFSET - 1) @@ -97,6 +98,16 @@ return a >= kShadowGapBeg && a <= kShadowGapEnd; } +static inline uptr ShadowToMemSparc64(uptr p) { + PROFILE_ASAN_MAPPING(); + p -= ASAN_SHADOW_OFFSET; + p <<= ASAN_SHADOW_SCALE; + if (p >= 0x8000000000000) { + p |= (~0) << VMA_BITS; + } + return p; +} + } // namespace __asan #endif // ASAN_MAPPING_SPARC64_H