Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sanitizers work again in coreclr #61948

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ elseif (CLR_CMAKE_HOST_UNIX)
string(FIND "$ENV{DEBUG_SANITIZERS}" "asan" __ASAN_POS)
string(FIND "$ENV{DEBUG_SANITIZERS}" "ubsan" __UBSAN_POS)
if ((${__ASAN_POS} GREATER -1) OR (${__UBSAN_POS} GREATER -1))
list(APPEND CLR_SANITIZE_CXX_OPTIONS -fsanitize-blacklist=${CMAKE_CURRENT_SOURCE_DIR}/sanitizerblacklist.txt)
list(APPEND CLR_SANITIZE_CXX_OPTIONS -fsanitize-blacklist=${CLR_ENG_NATIVE_DIR}/sanitizerblacklist.txt)
set (CLR_CXX_SANITIZERS "")
set (CLR_LINK_SANITIZERS "")
if (${__ASAN_POS} GREATER -1)
Expand Down Expand Up @@ -157,7 +157,7 @@ elseif (CLR_CMAKE_HOST_UNIX)

# -fdata-sections -ffunction-sections: each function has own section instead of one per .o file (needed for --gc-sections)
# -O1: optimization level used instead of -O0 to avoid compile error "invalid operand for inline asm constraint"
add_compile_options("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;--ffunction-sections;-O1>")
add_compile_options("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;-ffunction-sections;-O1>")
add_linker_flag("${CLR_SANITIZE_LINK_OPTIONS}" DEBUG CHECKED)
# -Wl and --gc-sections: drop unused sections\functions (similar to Windows /Gy function-level-linking)
add_linker_flag("-Wl,--gc-sections" DEBUG CHECKED)
Expand Down
46 changes: 23 additions & 23 deletions src/coreclr/enablesanitizers.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/usr/bin/env bash

if [ $# -eq 0 ]; then
echo "Script for enabling CLang sanitizers for debug builds."
echo "*Only tested on Ubuntu x64."
echo "Script for enabling Clang sanitizers for debug builds."
echo "*Tested on Ubuntu and Fedora x64."
echo "*This script must be 'sourced' (via dot+space) so that changes to environment variables are preserved. Run like this:"
if [ "$(dirname $0)" = "." ]; then
echo " . enablesanitizers.sh [options]"
else
echo " cd $(dirname $0);. enablesanitizers.sh [options]; cd -"
fi
echo "Usage: [asan] [ubsan] [lsan] [all] [off] [clangx.y]"
echo "Usage: [asan] [ubsan] [lsan] [all] [off] [symbolizer] [clangx.y]"
echo " asan: optional argument to enable Address Sanitizer."
echo " ubsan: optional argument to enable Undefined Behavior Sanitizer."
echo " lsan - optional argument to enable memory Leak Sanitizer."
echo " all - optional argument to enable asan, ubsan and lsan."
echo " off - optional argument to turn off all sanitizers."
echo " symbolizer - optional argument to export llvm-symbolizer path. "
echo " clangx.y - optional argument to specify clang version x.y. which is used to resolve stack traces. Default is 3.6"
else
# default to clang 3.6 instead of 3.5 because it supports print_stacktrace (otherwise only one stack frame)
__ClangMajorVersion=3
__ClangMinorVersion=6
__ClangMajorVersion=
__ClangMinorVersion=

__EnableASan=0
__EnableUBSan=0
__EnableLSan=0
__TurnOff=0
__Options=
__ExportSymbolizerPath=1
__ExportSymbolizerPath=0

for i in "$@"
do
Expand All @@ -50,28 +50,28 @@ else
off)
__TurnOff=1
;;
symbolizer)
__ExportSymbolizerPath=1
;;
clang3.5)
__ClangMajorVersion=3
__ClangMinorVersion=5
__ExportSymbolizerPath=1
;;
clang3.6)
__ClangMajorVersion=3
__ClangMinorVersion=6
__ExportSymbolizerPath=1
;;
clang3.7)
__ClangMajorVersion=3
__ClangMinorVersion=7
__ExportSymbolizerPath=0
;;
clang3.8)
__ClangMajorVersion=3
__ClangMinorVersion=8
__ExportSymbolizerPath=0
;;
clang3.9)
__ClangMajorVersion=3
__ClangMinorVersion=9
__ExportSymbolizerPath=0
clang*)
# clangx.y or clang-x.y
version="$(echo "$lowerI" | tr -d '[:alpha:]-=')"
parts=(${version//./ })
__ClangMajorVersion="${parts[0]}"
__ClangMinorVersion="${parts[1]}"
if [[ -z "$__ClangMinorVersion" ]]; then
__ClangMinorVersion=0;
fi
;;
*)
echo "Unknown arg: $i"
Expand Down Expand Up @@ -117,13 +117,13 @@ else
# 'atos' (for Darwin) otherwise it returns error
if [ $__ExportSymbolizerPath == 1 ]; then
# used by ASan at run-time
ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-$__ClangMajorVersion.$__ClangMinorVersion"
ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer${__ClangMajorVersion:+-${__ClangMajorVersion}.${__ClangMinorVersion}}"
export ASAN_SYMBOLIZER_PATH
echo "Setting ASAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH"
else
unset ASAN_SYMBOLIZER_PATH
fi
echo "Done. You can now run: build.sh Debug clang$__ClangMajorVersion.$__ClangMinorVersion"
echo "Done. You can now run: build.sh Debug clang${__ClangMajorVersion:+-${__ClangMajorVersion}.${__ClangMinorVersion}}"
fi

unset __ClangMajorVersion
Expand Down