From 3bd34dd30cb19e1351ea25e5c45e154719a9e32a Mon Sep 17 00:00:00 2001 From: Alessio Podda Date: Thu, 18 Sep 2025 11:32:13 +0200 Subject: [PATCH] Add option to always build fuzz binaries Currently the fuzzer binaries are only built when someone requests a fuzzer. This might cause us to inadvertently break fuzzing when changing function signatures. It also deviates with the behaviour we had with autotools, where the fuzz binaries were built with make test. This commit splits the -Dfuzzing option into two: fuzzing, and fuzzing-backend. The fuzzing option controls whether the fuzzing binaries are built. The fuzzing-backend option controls which backend to use, and defaults to none. If the value none is used the binaries are built, but no backend is used or guaranteed, which means that the binaries might be non-functional. --- fuzz/meson.build | 2 +- meson.build | 23 +++++++++++++---------- meson_options.txt | 10 +++++++++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/fuzz/meson.build b/fuzz/meson.build index 09eef853ad..43e1251bd7 100644 --- a/fuzz/meson.build +++ b/fuzz/meson.build @@ -9,7 +9,7 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. -if fuzz_opt == 'none' +if fuzz_opt.enabled() subdir_done() endif diff --git a/meson.build b/meson.build index ee12ed857f..972f41fed9 100644 --- a/meson.build +++ b/meson.build @@ -57,6 +57,7 @@ doc_opt = get_option('doc') doh_opt = get_option('doh') fips_opt = get_option('fips') fuzz_opt = get_option('fuzzing') +fuzz_backend_opt = get_option('fuzzing-backend') geoip_opt = get_option('geoip') gssapi_opt = get_option('gssapi') idn_opt = get_option('idn') @@ -406,17 +407,19 @@ endif config.set_quoted('FUZZDIR', meson.project_source_root() / 'fuzz') fuzz_link_args = [] -if fuzz_opt != 'none' - if get_option('b_lundef') != false - warning('fuzzing will fail to build properly without -Db_lundef=false') - endif +if fuzz_opt.enabled() + if fuzz_backed_opt != 'none' + if get_option('b_lundef') != false + warning('fuzzing will fail to build properly without -Db_lundef=false') + endif - if fuzz_opt == 'afl' - elif fuzz_opt == 'libfuzzer' - config.set('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1) - fuzz_link_args += '-fsanitize=fuzzer,address,undefined' - add_project_link_arguments('-fsanitize=address,undefined', language: 'c') - add_project_arguments('-fsanitize=fuzzer-no-link,address,undefined', language: 'c') + if fuzz_opt == 'afl' + elif fuzz_opt == 'libfuzzer' + config.set('FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION', 1) + fuzz_link_args += '-fsanitize=fuzzer,address,undefined' + add_project_link_arguments('-fsanitize=address,undefined', language: 'c') + add_project_arguments('-fsanitize=fuzzer-no-link,address,undefined', language: 'c') + endif endif endif diff --git a/meson_options.txt b/meson_options.txt index 5783d45f3d..2f1ae16a1c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -169,9 +169,17 @@ option( option( 'fuzzing', + type: 'feature', + value: 'auto', + description: 'Build fuzzing binaries', +) + +option( + 'fuzzing-backend', type: 'combo', choices: ['none', 'afl', 'libfuzzer', 'oss-fuzz'], - description: 'Enable fuzzing', + value: 'none', + description: 'Fuzzing backend (backend none with -Dfuzzing=enabled only compiles the binary)', ) option(