forked from firebase/firebase-ios-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfuzzing_options.cmake
More file actions
52 lines (46 loc) · 2.16 KB
/
Copy pathfuzzing_options.cmake
File metadata and controls
52 lines (46 loc) · 2.16 KB
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
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Add fuzz testing options to the current build.
option(FUZZING "Build for Fuzz Testing (local fuzzing and OSS Fuzz)" OFF)
# Assume OSS Fuzz if LIB_FUZZING_ENGINE environment variable is set. OSS Fuzz
# provides its required compiler-specific flags in CXXFLAGS, which are
# automatically added to CMAKE_CXX_FLAGS. For local fuzzing, multiple compile
# and linking flags must be set. These flags depend on the compiler version.
if(FUZZING AND NOT DEFINED ENV{LIB_FUZZING_ENGINE})
if(WIN32)
# Currently, libFuzzer cannot be built on Windows.
message(FATAL_ERROR "Fuzzing is currently not supported on Windows.")
endif()
# Address sanitizer must be enabled during fuzzing to detect memory errors.
if(NOT WITH_ASAN)
message(FATAL_ERROR "Fuzzing requires WITH_ASAN=ON to detect memory errors.")
endif()
# Set the flag to enable code coverage instrumentation. Fuzzing engines use
# code coverage as a metric to guide the fuzzing. We use the basic code
# coverage level (trace-pc). This flag has different values in Clang and GNU.
# Other values, such as trace-cmp, can be used to trace data flow. See the
# official documentation for the compiler flags.
if(CXX_CLANG)
# TODO(minafarid): Check the version of Clang. Clang versions >= 5.0 should
# have libFuzzer by default.
set(fuzzing_flags -fsanitize-coverage=trace-pc-guard)
elseif(CXX_GNU)
set(fuzzing_flags -fsanitize-coverage=trace-pc)
else()
message(FATAL_ERROR "Only Clang and GCC support fuzzing.")
endif()
foreach(flag ${fuzzing_flags})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endforeach()
endif()