[MemProf] Add sanitizer interface decls for histogram funcs. (#151398)

Add the necessary sanitizer interface decls required when the memprof
runtime is built in dynamic mode.  This was a latent issue since we didn't
add tests for the histogram feature in compiler-rt. These tests are run
with `ninja check-memprof-dynamic`.  I discovered this after the CI
failures for #147854.
This commit is contained in:
Snehasish Kumar
2025-07-30 16:27:10 -07:00
committed by GitHub
parent cd4360a16a
commit 8377f90c21
2 changed files with 48 additions and 0 deletions

View File

@@ -35,9 +35,15 @@ SANITIZER_INTERFACE_ATTRIBUTE void __memprof_version_mismatch_check_v1();
SANITIZER_INTERFACE_ATTRIBUTE
void __memprof_record_access(void const volatile *addr);
SANITIZER_INTERFACE_ATTRIBUTE
void __memprof_record_access_hist(void const volatile *addr);
SANITIZER_INTERFACE_ATTRIBUTE
void __memprof_record_access_range(void const volatile *addr, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE
void __memprof_record_access_range_hist(void const volatile *addr, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_print_accumulated_stats();
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
@@ -51,6 +57,10 @@ extern uptr __memprof_shadow_memory_dynamic_address;
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
__memprof_profile_filename[1];
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern bool
__memprof_histogram;
SANITIZER_INTERFACE_ATTRIBUTE int __memprof_profile_dump();
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_profile_reset();

View File

@@ -0,0 +1,38 @@
// Test the histogram support in memprof using the text format output.
// Shadow memory counters per object are limited to 8b. In memory counters
// aggregating counts across multiple objects are 64b.
// RUN: %clangxx_memprof -O0 -mllvm -memprof-histogram -mllvm -memprof-use-callbacks=true %s -o %t
// RUN: %env_memprof_opts=print_text=1:histogram=1:log_path=stdout %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <stdlib.h>
int main() {
// Allocate memory that will create a histogram
char *buffer = (char *)malloc(1024);
if (!buffer)
return 1;
for (int i = 0; i < 10; ++i) {
// Access every 8th byte (since shadow granularity is 8b.
buffer[i * 8] = 'A';
}
for (int j = 0; j < 200; ++j) {
buffer[8] = 'B'; // Count = previous count + 200
}
for (int j = 0; j < 400; ++j) {
buffer[16] = 'B'; // Count is saturated at 255
}
// Free the memory to trigger MIB creation with histogram
free(buffer);
printf("Test completed successfully\n");
return 0;
}
// CHECK: AccessCountHistogram[128]: 1 201 255 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
// CHECK: Test completed successfully