From d1ea5554628dee6d3b41710b1375e42f8b760988 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Tue, 7 Feb 2023 15:30:33 -0800 Subject: [PATCH] Rewrite libfuzzer buildfile for GN. --- third_party/libFuzzer/BUILD.gn | 69 ++++++++++++---------------------- 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/third_party/libFuzzer/BUILD.gn b/third_party/libFuzzer/BUILD.gn index eb14c5854..ec8a7c65e 100644 --- a/third_party/libFuzzer/BUILD.gn +++ b/third_party/libFuzzer/BUILD.gn @@ -1,41 +1,28 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. +# Copyright 2022 The GPGMM 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 +# +# 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. import("///build/config/sanitizers/sanitizers.gni") -config("warnings") { +config("libfuzzer_flags") { if (is_clang) { cflags = [ "-Wno-shadow", - - # See crbug.com/932188, libFuzzer does not check the result of write() - # when it does raw printing. "-Wno-unused-result", ] } } -# Engine should be compiled without coverage (infinite loop in trace_cmp). -fuzzing_engine_remove_configs = [ - "//build/config/coverage:default_coverage", - "//build/config/sanitizers:default_sanitizer_flags", -] - -# Add any sanitizer flags back. In MSAN builds, instrumenting libfuzzer with -# MSAN is necessary since all parts of the binary need to be instrumented for it -# to work. ASAN builds are more subtle: libfuzzer depends on features from the -# C++ STL. If it were not instrumented, templates would be insantiated without -# ASAN from libfuzzer and with ASAN in other TUs. The linker might merge -# instrumented template instantiations with non-instrumented ones (which could -# have a different ABI) in the final binary, which is problematic for TUs -# expecting one particular ABI (https://crbug.com/915422). The other sanitizers -# are added back for the same reason. -fuzzing_engine_add_configs = [ - "//build/config/sanitizers:default_sanitizer_flags_but_coverage", - ":warnings", -] - source_set("libfuzzer") { sources = [ "src/FuzzerCrossOver.cpp", @@ -50,6 +37,7 @@ source_set("libfuzzer") { "src/FuzzerIOPosix.cpp", "src/FuzzerIOWindows.cpp", "src/FuzzerLoop.cpp", + "src/FuzzerMain.cpp", "src/FuzzerMerge.cpp", "src/FuzzerMutate.cpp", "src/FuzzerSHA1.cpp", @@ -62,24 +50,13 @@ source_set("libfuzzer") { "src/FuzzerUtilWindows.cpp", ] - if (!is_ios) { - sources += [ "src/FuzzerMain.cpp" ] - } - - configs -= fuzzing_engine_remove_configs - configs += fuzzing_engine_add_configs - - deps = [] - if (is_fuchsia) { - deps += [ "//third_party/fuchsia-sdk/sdk:fdio" ] - } -} - -if (use_afl) { - source_set("afl_driver") { - sources = [ "src/afl/afl_driver.cpp" ] + configs -= [ + "//build/config/coverage:default_coverage", + "//build/config/sanitizers:default_sanitizer_flags", + ] - configs -= fuzzing_engine_remove_configs - configs += fuzzing_engine_add_configs - } + configs += [ + "//build/config/sanitizers:default_sanitizer_flags_but_coverage", + ":libfuzzer_flags", + ] }