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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
From 1cf30166f8b1489ff3c9958e7ad21f097aa5065e Mon Sep 17 00:00:00 2001
From: Konstantin Baladurin <k.baladurin@partner.samsung.com>
Date: Sat, 9 Dec 2017 13:57:20 +0300
Subject: [PATCH 1/4] Fix build with Asan (#15372)
- verify_dependencies: disable checking dependencies for Asan build
because in this case shared libraries can have undefined symbols
(if static linking with compiler-rt is used).
- enablesanitizers.sh: remove excess quotes for ASAN_OPTIONS and
UBSAN_OPTIONS environment variable because otherwise Asan cannot
parse flags. Also doesn't export ASAN_SYMBOLIZER_PATH for clang > 3.6.
---
enablesanitizers.sh | 36 +++++++++++++++++++++++++++---------
functions.cmake | 16 +++++++++++++++-
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/enablesanitizers.sh b/enablesanitizers.sh
index 70555aa..2937b0b 100755
--- a/enablesanitizers.sh
+++ b/enablesanitizers.sh
@@ -26,6 +26,7 @@ else
__EnableLSan=0
__TurnOff=0
__Options=
+ __ExportSymbolizerPath=1
for i in "$@"
do
@@ -60,6 +61,17 @@ else
clang3.7)
__ClangMajorVersion=3
__ClangMinorVersion=7
+ __ExportSymbolizerPath=0
+ ;;
+ clang3.8)
+ __ClangMajorVersion=3
+ __ClangMinorVersion=8
+ __ExportSymbolizerPath=0
+ ;;
+ clang3.9)
+ __ClangMajorVersion=3
+ __ClangMinorVersion=9
+ __ExportSymbolizerPath=0
;;
*)
echo "Unknown arg: $i"
@@ -83,7 +95,9 @@ else
__Options="$__Options ubsan"
fi
if [ $__EnableLSan == 1 ]; then
- ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks"
+ ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks=1"
+ else
+ ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks=0"
fi
# passed to build.sh
@@ -92,18 +106,22 @@ else
echo "Setting DEBUG_SANITIZERS=$DEBUG_SANITIZERS"
# used by ASan at run-time
- ASAN_OPTIONS="\"$ASAN_OPTIONS\""
export ASAN_OPTIONS
- echo "Setting ASAN_OPTIONS=$ASAN_OPTIONS"
+ echo "Setting ASAN_OPTIONS=\"$ASAN_OPTIONS\""
- UBSAN_OPTIONS="\"$UBSAN_OPTIONS\""
export UBSAN_OPTIONS
- echo "Setting UBSAN_OPTIONS=$UBSAN_OPTIONS"
+ echo "Setting UBSAN_OPTIONS=\"$UBSAN_OPTIONS\""
- # used by ASan at run-time
- ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-$__ClangMajorVersion.$__ClangMinorVersion"
- export ASAN_SYMBOLIZER_PATH
- echo "Setting ASAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH"
+ # for compiler-rt > 3.6 Asan check that binary name is 'llvm-symbolizer', 'addr2line' or
+ # '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"
+ 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"
fi
diff --git a/functions.cmake b/functions.cmake
index cf4d08f..50e4bbe 100644
--- a/functions.cmake
+++ b/functions.cmake
@@ -223,9 +223,23 @@ function(_install)
endfunction()
function(verify_dependencies targetName errorMessage)
+ set(SANITIZER_BUILD OFF)
+
+ if (CLR_CMAKE_PLATFORM_UNIX)
+ if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
+ 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))
+ set(SANITIZER_BUILD ON)
+ endif()
+ endif()
+ endif()
+
# We don't need to verify dependencies on OSX, since missing dependencies
# result in link error over there.
- if (NOT CLR_CMAKE_PLATFORM_DARWIN AND NOT CLR_CMAKE_PLATFORM_ANDROID)
+ # Also don't verify dependencies for Asan build because in this case shared
+ # libraries can contain undefined symbols
+ if (NOT CLR_CMAKE_PLATFORM_DARWIN AND NOT CLR_CMAKE_PLATFORM_ANDROID AND NOT SANITIZER_BUILD)
add_custom_command(
TARGET ${targetName}
POST_BUILD
--
2.7.4
|