blob: 142b7617d476a682b131299b5e7e1d62e2a37890 (
plain)
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
|
# Copyright 2020 The Pigweed Authors
#
# 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
#
# https://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.
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_fuzzer/fuzzer.gni")
config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
}
# Add flags for adding LLVM sanitizer coverage for fuzzing. This is added by
# the host_clang_fuzz toolchains.
config("instrumentation") {
if (pw_toolchain_OSS_FUZZ_ENABLED) {
# OSS-Fuzz manipulates compiler flags directly. See
# google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements.
cflags_c = string_split(getenv("CFLAGS"))
cflags_cc = string_split(getenv("CXXFLAGS"))
# OSS-Fuzz sets "-stdlib=libc++", which conflicts with the "-nostdinc++" set
# by `pw_minimal_cpp_stdlib`.
cflags_cc += [ "-Wno-unused-command-line-argument" ]
} else {
cflags = [ "-fsanitize=fuzzer-no-link" ]
}
}
# Add flags for linking against compiler-rt's libFuzzer. This is added
# automatically by `pw_fuzzer`.
config("engine") {
if (pw_toolchain_OSS_FUZZ_ENABLED) {
# OSS-Fuzz manipulates linker flags directly. See
# google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements.
ldflags = string_split(getenv("LDFLAGS")) + [ getenv("LIB_FUZZING_ENGINE") ]
} else {
ldflags = [ "-fsanitize=fuzzer" ]
}
}
pw_source_set("pw_fuzzer") {
public_configs = [ ":public_include_path" ]
public = [
"public/pw_fuzzer/asan_interface.h",
"public/pw_fuzzer/fuzzed_data_provider.h",
]
public_deps = [ "$dir_pw_log" ]
}
pw_source_set("run_as_unit_test") {
configs = [ ":public_include_path" ]
sources = [ "pw_fuzzer_disabled.cc" ]
deps = [
dir_pw_log,
dir_pw_unit_test,
]
}
# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
config("fuzzing_build_mode_unsafe_for_production") {
defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
}
config("fuzzing_verbose_logging") {
defines = [ "FUZZING_VERBOSE_LOGGING" ]
}
pw_doc_group("docs") {
inputs = [ "doc_resources/pw_fuzzer_coverage_guided.png" ]
sources = [ "docs.rst" ]
}
# Sample fuzzer
pw_fuzzer("toy_fuzzer") {
sources = [ "examples/toy_fuzzer.cc" ]
deps = [
":pw_fuzzer",
dir_pw_status,
]
}
pw_test_group("tests") {
tests = [ ":toy_fuzzer_test" ]
}
group("fuzzers") {
deps = [ ":toy_fuzzer" ]
}
|