diff options
Diffstat (limited to 'compiler-rt/include')
| -rw-r--r-- | compiler-rt/include/profile/MIBEntryDef.inc | 2 | ||||
| -rw-r--r-- | compiler-rt/include/profile/MemProfData.inc | 29 | ||||
| -rw-r--r-- | compiler-rt/include/sanitizer/nsan_interface.h | 75 |
3 files changed, 104 insertions, 2 deletions
diff --git a/compiler-rt/include/profile/MIBEntryDef.inc b/compiler-rt/include/profile/MIBEntryDef.inc index 794163ae1038..58c1fc4de4ab 100644 --- a/compiler-rt/include/profile/MIBEntryDef.inc +++ b/compiler-rt/include/profile/MIBEntryDef.inc @@ -51,3 +51,5 @@ MIBEntryDef(MaxAccessDensity = 22, MaxAccessDensity, uint32_t) MIBEntryDef(TotalLifetimeAccessDensity = 23, TotalLifetimeAccessDensity, uint64_t) MIBEntryDef(MinLifetimeAccessDensity = 24, MinLifetimeAccessDensity, uint32_t) MIBEntryDef(MaxLifetimeAccessDensity = 25, MaxLifetimeAccessDensity, uint32_t) +MIBEntryDef(AccessHistogramSize = 26, AccessHistogramSize, uint32_t) +MIBEntryDef(AccessHistogram = 27, AccessHistogram, uintptr_t)
\ No newline at end of file diff --git a/compiler-rt/include/profile/MemProfData.inc b/compiler-rt/include/profile/MemProfData.inc index b82a4baf6dd7..3dc88478fb93 100644 --- a/compiler-rt/include/profile/MemProfData.inc +++ b/compiler-rt/include/profile/MemProfData.inc @@ -33,7 +33,11 @@ (uint64_t)'o' << 24 | (uint64_t)'f' << 16 | (uint64_t)'r' << 8 | (uint64_t)129) // The version number of the raw binary format. -#define MEMPROF_RAW_VERSION 3ULL +#define MEMPROF_RAW_VERSION 4ULL + +// Currently supported versions. +#define MEMPROF_RAW_SUPPORTED_VERSIONS \ + { 3ULL, 4ULL } #define MEMPROF_BUILDID_MAX_SIZE 32ULL @@ -119,7 +123,8 @@ MemInfoBlock() { } MemInfoBlock(uint32_t Size, uint64_t AccessCount, uint32_t AllocTs, - uint32_t DeallocTs, uint32_t AllocCpu, uint32_t DeallocCpu) + uint32_t DeallocTs, uint32_t AllocCpu, uint32_t DeallocCpu, + uintptr_t Histogram, uint32_t HistogramSize) : MemInfoBlock() { AllocCount = 1U; TotalAccessCount = AccessCount; @@ -149,6 +154,8 @@ MemInfoBlock(uint32_t Size, uint64_t AccessCount, uint32_t AllocTs, AllocCpuId = AllocCpu; DeallocCpuId = DeallocCpu; NumMigratedCpu = AllocCpuId != DeallocCpuId; + AccessHistogramSize = HistogramSize; + AccessHistogram = Histogram; } void Merge(const MemInfoBlock &newMIB) { @@ -194,6 +201,24 @@ void Merge(const MemInfoBlock &newMIB) { NumSameDeallocCpu += DeallocCpuId == newMIB.DeallocCpuId; AllocCpuId = newMIB.AllocCpuId; DeallocCpuId = newMIB.DeallocCpuId; + + // For merging histograms, we always keep the longer histogram, and add + // values of shorter histogram to larger one. + uintptr_t ShorterHistogram; + uint32_t ShorterHistogramSize; + if (newMIB.AccessHistogramSize > AccessHistogramSize) { + ShorterHistogram = AccessHistogram; + ShorterHistogramSize = AccessHistogramSize; + // Swap histogram of current to larger histogram + AccessHistogram = newMIB.AccessHistogram; + AccessHistogramSize = newMIB.AccessHistogramSize; + } else { + ShorterHistogram = newMIB.AccessHistogram; + ShorterHistogramSize = newMIB.AccessHistogramSize; + } + for (size_t i = 0; i < ShorterHistogramSize; ++i) { + ((uint64_t *)AccessHistogram)[i] += ((uint64_t *)ShorterHistogram)[i]; + } } #ifdef _MSC_VER diff --git a/compiler-rt/include/sanitizer/nsan_interface.h b/compiler-rt/include/sanitizer/nsan_interface.h new file mode 100644 index 000000000000..057ca0473bb3 --- /dev/null +++ b/compiler-rt/include/sanitizer/nsan_interface.h @@ -0,0 +1,75 @@ +//===-- sanitizer/nsan_interface.h ------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Public interface for nsan. +// +//===----------------------------------------------------------------------===// +#ifndef SANITIZER_NSAN_INTERFACE_H +#define SANITIZER_NSAN_INTERFACE_H + +#include <sanitizer/common_interface_defs.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/// User-provided default option settings. +/// +/// You can provide your own implementation of this function to return a string +/// containing NSan runtime options (for example, +/// <c>verbosity=1:halt_on_error=0</c>). +/// +/// \returns Default options string. +const char *__nsan_default_options(void); + +// Dumps nsan shadow data for a block of `size_bytes` bytes of application +// memory at location `addr`. +// +// Each line contains application address, shadow types, then values. +// Unknown types are shown as `__`, while known values are shown as +// `f`, `d`, `l` for float, double, and long double respectively. Position is +// shown as a single hex digit. The shadow value itself appears on the line that +// contains the first byte of the value. +// FIXME: Show both shadow and application value. +// +// Example: `__nsan_dump_shadow_mem(addr, 32, 8, 0)` might print: +// +// 0x0add7359: __ f0 f1 f2 f3 __ __ __ (42.000) +// 0x0add7361: __ d1 d2 d3 d4 d5 d6 d7 +// 0x0add7369: d8 f0 f1 f2 f3 __ __ f2 (-1.000) (12.5) +// 0x0add7371: f3 __ __ __ __ __ __ __ +// +// This means that there is: +// - a shadow double for the float at address 0x0add7360, with value 42; +// - a shadow float128 for the double at address 0x0add7362, with value -1; +// - a shadow double for the float at address 0x0add736a, with value 12.5; +// There was also a shadow double for the float at address 0x0add736e, but bytes +// f0 and f1 were overwritten by one or several stores, so that the shadow value +// is no longer valid. +// The argument `reserved` can be any value. Its true value is provided by the +// instrumentation. +void __nsan_dump_shadow_mem(const char *addr, size_t size_bytes, + size_t bytes_per_line, size_t reserved); + +// Explicitly dumps a value. +// FIXME: vector versions ? +void __nsan_dump_float(float value); +void __nsan_dump_double(double value); +void __nsan_dump_longdouble(long double value); + +// Explicitly checks a value. +// FIXME: vector versions ? +void __nsan_check_float(float value); +void __nsan_check_double(double value); +void __nsan_check_longdouble(long double value); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // SANITIZER_NSAN_INTERFACE_H |
