File: sanitizer-env.sh

package info (click to toggle)
kmod 34.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,864 kB
  • sloc: ansic: 16,990; makefile: 498; sh: 382; xml: 61; perl: 12
file content (51 lines) | stat: -rwxr-xr-x 1,483 bytes parent folder | download
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
48
49
50
51
#!/bin/bash

# set -euo pipefail # don't set these, since this script is sourced

if [[ ${CC-} == *gcc* ]]; then
    OUR_PRELOAD=$("$CC" -print-file-name=libasan.so)
elif [[ ${CC-} == *clang* ]]; then
    # With v19, the library lacks the CPU arch in its name
    OUR_PRELOAD=$("$CC" -print-file-name=libclang_rt.asan.so)
    if ! test -f "$OUR_PRELOAD"; then
       OUR_PRELOAD=$("$CC" -print-file-name=libclang_rt.asan-x86_64.so)
    fi
else
    cat <<- EOF >&2

    WARNING: Unknown compiler CC="${CC-}" - gcc and clang are supported.
    Assuming "gcc", manually set the variable and retry if needed.

EOF
    OUR_PRELOAD=$(gcc -print-file-name=libasan.so)
fi

if test -f "$OUR_PRELOAD"; then
    # In some cases, like in Fedora, the file is a script which cannot be
    # preloaded. Attempt to extract the details from within.
    if grep -q INPUT "$OUR_PRELOAD"; then
        input=$(sed -r -n "s/INPUT \( (.*) \)/\1/p" "$OUR_PRELOAD")
        test -f "$input" && OUR_PRELOAD="$input"
    fi

    LD_PRELOAD=${LD_PRELOAD+${LD_PRELOAD}:}$OUR_PRELOAD
    export LD_PRELOAD
    cat <<- EOF

    LD_PRELOAD has been set to "$LD_PRELOAD".
    The sanitizer might report issues with ANY process you execute.

EOF
else
    cat <<- EOF >&2

    WARNING: compiler returned non-existing library name "$OUR_PRELOAD".

    Make sure to install the relevant packages and ensure this script
    references the correct library name.

    LD_PRELOAD will NOT be set.

EOF
fi
unset OUR_PRELOAD