[PATCH v3 01/12] meson: support building fuzzers with libFuzzer
From: Patrick Steinhardt <hidden>
Date: 2026-07-03 12:58:57
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 <redacted>
---
meson.build | 15 +++++++++++++++
meson_options.txt | 2 ++
oss-fuzz/meson.build | 1 +
3 files changed, 18 insertions(+)
diff --git a/meson.build b/meson.build
index 3247697f74..9df6fbb0a5 100644
--- a/meson.build
+++ b/meson.build@@ -161,6 +161,21 @@ # These machine files can be passed to `meson setup` via the `--native-file` # option. # +# Fuzzing +# ======= +# +# Meson supports building the fuzzing targets by setting `-Dfuzzers=true`. By +# default, the targets will be built without libFuzzer and thus won't be usable +# for fuzzing. You have to configure a couple of options to properly wire up +# libFuzzer: +# +# $ meson setup build-fuzzers \ +# -Db_sanitize=address,fuzzer-no-link \ +# -Dfuzzers=true \ +# -Dfuzzers_link_args=-fsanitize=fuzzer +# $ meson compile -C build-fuzzers +# $ ./build-fuzzers/oss-fuzz/fuzz-config <args> +# # Cross compilation # ================= #
diff --git a/meson_options.txt b/meson_options.txt
index d936ada098..dc88f130d7 100644
--- a/meson_options.txt
+++ b/meson_options.txt@@ -131,3 +131,5 @@ option('test_utf8_locale', type: 'string', description: 'Name of a UTF-8 locale used for testing.') option('fuzzers', type: 'boolean', value: false, description: 'Enable building fuzzers.') +option('fuzzers_link_args', type: 'array', value: [], + description: 'Linker arguments used to link fuzzers. Use -fsanitize=fuzzer for fuzzing.')
diff --git a/oss-fuzz/meson.build b/oss-fuzz/meson.build
index 878afd8426..10bcac2f6d 100644
--- a/oss-fuzz/meson.build
+++ b/oss-fuzz/meson.build@@ -16,5 +16,6 @@ foreach fuzz_program : fuzz_programs fuzz_program, ], dependencies: [libgit_commonmain], + link_args: get_option('fuzzers_link_args'), ) endforeach
--
2.55.0.795.g602f6c329a.dirty