-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.sh
executable file
·47 lines (39 loc) · 1.33 KB
/
validate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# ---------------------------------------------------------
# Script: validate.sh
# Purpose:
# - Validate memory safety using Valgrind.
# - Ensure ASAN runtime is correctly preloaded for the child process.
#
# Why:
# - Valgrind and AddressSanitizer (ASAN) can conflict when both intercept memory symbols.
# - Valgrind complains if ASAN runtime isn’t linked first, so we ensure it is preloaded.
#
# Usage:
# ./validate.sh <program> [args...]
# ---------------------------------------------------------
# Suppression file for known false positives
SUPPRESSION_FILE="$(pwd)/asan.supp"
# Enable or disable ASAN link order bypass
BYPASS_ASAN_LINK_ORDER=0
# Configure ASAN options
if [[ $BYPASS_ASAN_LINK_ORDER -eq 1 ]]; then
ASAN_OPTIONS="verify_asan_link_order=0"
else
ASAN_OPTIONS=""
fi
# Preload AddressSanitizer runtime library
LD_PRELOAD=$(gcc -print-file-name=libasan.so)
# Configure LSAN options (quietly suppress known false positives)
LSAN_OPTIONS="suppressions=${SUPPRESSION_FILE}"
export LD_PRELOAD ASAN_OPTIONS LSAN_OPTIONS
# Check for input arguments
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <program> [args...]"
exit 1
fi
# Run the program with Valgrind and ensure LD_PRELOAD propagates
valgrind --leak-check=full \
--show-leak-kinds=all \
--trace-children=yes \
-s "$@"