meson: support building fuzzers with libFuzzer

To support fuzzing via libFuzzer one has to pass a couple of compiler options: - It is mandatory to enable the "fuzzer-no-link" sanitizer for coverage feedback. - It is recommended to enable at least one more sanitizer to catch issues, like the "address" sanitizer. - The fuzzing executables need to be linked with "-fsanitize=fuzzer" to wire up libFuzzer itself. The first two items can already be achieved via the "-Db_sanitize=" option. But the last item cannot easily be achieved, as we can only configure global link arguments. Introduce a new "-Dfuzzers_link_args=" build option to plug this gap. Add documentation so that users know how to set up libFuzzer. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 3, 2026 at 14:58 UTC 8fed3acc0b54c267a86380c4369a535d68e50aae
3 files changed +18
meson.build
+15
@@ -161,6 +161,21 @@
161 # These machine files can be passed to `meson setup` via the `--native-file`
162 # option.
163 #
164 +# Fuzzing
165 +# =======
166 +#
167 +# Meson supports building the fuzzing targets by setting `-Dfuzzers=true`. By
168 +# default, the targets will be built without libFuzzer and thus won't be usable
169 +# for fuzzing. You have to configure a couple of options to properly wire up
170 +# libFuzzer:
171 +#
172 +# $ meson setup build-fuzzers \
173 +# -Db_sanitize=address,fuzzer-no-link \
174 +# -Dfuzzers=true \
175 +# -Dfuzzers_link_args=-fsanitize=fuzzer
176 +# $ meson compile -C build-fuzzers
177 +# $ ./build-fuzzers/oss-fuzz/fuzz-config <args>
178 +#
179 # Cross compilation
180 # =================
181 #
meson_options.txt
+2
@@ -131,3 +131,5 @@ option('test_utf8_locale', type: 'string',
131 description: 'Name of a UTF-8 locale used for testing.')
132 option('fuzzers', type: 'boolean', value: false,
133 description: 'Enable building fuzzers.')
134 +option('fuzzers_link_args', type: 'array', value: [],
135 + description: 'Linker arguments used to link fuzzers. Use -fsanitize=fuzzer for fuzzing.')
oss-fuzz/meson.build
+1
@@ -16,5 +16,6 @@ foreach fuzz_program : fuzz_programs
16 fuzz_program,
17 ],
18 dependencies: [libgit_commonmain],
19 + link_args: get_option('fuzzers_link_args'),
20 )
21 endforeach