]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
2 | # you may not use this file except in compliance with the License. | |
3 | # You may obtain a copy of the License at | |
4 | # | |
5 | # http://www.apache.org/licenses/LICENSE-2.0 | |
6 | # | |
7 | # Unless required by applicable law or agreed to in writing, software | |
8 | # distributed under the License is distributed on an "AS IS" BASIS, | |
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
10 | # See the License for the specific language governing permissions and | |
11 | # limitations under the License. See accompanying LICENSE file. | |
12 | ||
13 | # Clang does not support using ASAN and TSAN simultaneously. | |
14 | if("${ARROW_USE_ASAN}" AND "${ARROW_USE_TSAN}") | |
15 | message(SEND_ERROR "Can only enable one of ASAN or TSAN at a time") | |
16 | endif() | |
17 | ||
18 | # Flag to enable clang address sanitizer | |
19 | # This will only build if clang or a recent enough gcc is the chosen compiler | |
20 | if(${ARROW_USE_ASAN}) | |
21 | if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" | |
22 | OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" | |
23 | OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION | |
24 | VERSION_GREATER "4.8")) | |
25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -DADDRESS_SANITIZER") | |
26 | else() | |
27 | message(SEND_ERROR "Cannot use ASAN without clang or gcc >= 4.8") | |
28 | endif() | |
29 | endif() | |
30 | ||
31 | # Flag to enable clang undefined behavior sanitizer | |
32 | # We explicitly don't enable all of the sanitizer flags: | |
33 | # - disable 'vptr' because of RTTI issues across shared libraries (?) | |
34 | # - disable 'alignment' because unaligned access is really OK on Nehalem and we do it | |
35 | # all over the place. | |
36 | # - disable 'function' because it appears to give a false positive | |
37 | # (https://github.com/google/sanitizers/issues/911) | |
38 | # - disable 'float-divide-by-zero' on clang, which considers it UB | |
39 | # (https://bugs.llvm.org/show_bug.cgi?id=17000#c1) | |
40 | # Note: GCC does not support the 'function' flag. | |
41 | if(${ARROW_USE_UBSAN}) | |
42 | if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL | |
43 | "Clang") | |
44 | set(CMAKE_CXX_FLAGS | |
45 | "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr,function,float-divide-by-zero -fno-sanitize-recover=all" | |
46 | ) | |
47 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION | |
48 | VERSION_GREATER_EQUAL "5.1") | |
49 | set(CMAKE_CXX_FLAGS | |
50 | "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr -fno-sanitize-recover=all" | |
51 | ) | |
52 | else() | |
53 | message(SEND_ERROR "Cannot use UBSAN without clang or gcc >= 5.1") | |
54 | endif() | |
55 | endif() | |
56 | ||
57 | # Flag to enable thread sanitizer (clang or gcc 4.8) | |
58 | if(${ARROW_USE_TSAN}) | |
59 | if(NOT | |
60 | (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" | |
61 | OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" | |
62 | OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION | |
63 | VERSION_GREATER "4.8"))) | |
64 | message(SEND_ERROR "Cannot use TSAN without clang or gcc >= 4.8") | |
65 | endif() | |
66 | ||
67 | add_definitions("-fsanitize=thread") | |
68 | ||
69 | # Enables dynamic_annotations.h to actually generate code | |
70 | add_definitions("-DDYNAMIC_ANNOTATIONS_ENABLED") | |
71 | ||
72 | # changes atomicops to use the tsan implementations | |
73 | add_definitions("-DTHREAD_SANITIZER") | |
74 | ||
75 | # Disables using the precompiled template specializations for std::string, shared_ptr, etc | |
76 | # so that the annotations in the header actually take effect. | |
77 | add_definitions("-D_GLIBCXX_EXTERN_TEMPLATE=0") | |
78 | ||
79 | # Some of the above also need to be passed to the linker. | |
80 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fsanitize=thread") | |
81 | ||
82 | # Strictly speaking, TSAN doesn't require dynamic linking. But it does | |
83 | # require all code to be position independent, and the easiest way to | |
84 | # guarantee that is via dynamic linking (not all 3rd party archives are | |
85 | # compiled with -fPIC e.g. boost). | |
86 | if("${ARROW_LINK}" STREQUAL "a") | |
87 | message("Using dynamic linking for TSAN") | |
88 | set(ARROW_LINK "d") | |
89 | elseif("${ARROW_LINK}" STREQUAL "s") | |
90 | message(SEND_ERROR "Cannot use TSAN with static linking") | |
91 | endif() | |
92 | endif() | |
93 | ||
94 | if(${ARROW_USE_COVERAGE}) | |
95 | if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL | |
96 | "Clang") | |
97 | add_definitions("-fsanitize-coverage=pc-table,inline-8bit-counters,edge,no-prune,trace-cmp,trace-div,trace-gep" | |
98 | ) | |
99 | ||
100 | set(CMAKE_CXX_FLAGS | |
101 | "${CMAKE_CXX_FLAGS} -fsanitize-coverage=pc-table,inline-8bit-counters,edge,no-prune,trace-cmp,trace-div,trace-gep" | |
102 | ) | |
103 | else() | |
104 | message(SEND_ERROR "You can only enable coverage with clang") | |
105 | endif() | |
106 | endif() | |
107 | ||
108 | if("${ARROW_USE_UBSAN}" | |
109 | OR "${ARROW_USE_ASAN}" | |
110 | OR "${ARROW_USE_TSAN}") | |
111 | # GCC 4.8 and 4.9 (latest as of this writing) don't allow you to specify | |
112 | # disallowed entries for the sanitizer. | |
113 | if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL | |
114 | "Clang") | |
115 | set(CMAKE_CXX_FLAGS | |
116 | "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${BUILD_SUPPORT_DIR}/sanitizer-disallowed-entries.txt" | |
117 | ) | |
118 | else() | |
119 | message(WARNING "GCC does not support specifying a sanitizer disallowed entries list. Known sanitizer check failures will not be suppressed." | |
120 | ) | |
121 | endif() | |
122 | endif() |