authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-06-29 21:11:46-04:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-09 10:14:16+02:00
log3944c72a148096e3933745a9fda0397c0dd67cbf
treeb34df21e1028e8ce27a9e3ea8bae55477793d8f5
parent18d9b2850ecba8fca14b11bd18111c17f0415aa9

default to LLVM and ReleaseSafe for fuzzing

Currently, only the LLVM backend is capable of emitting fuzzing instrumentation, so `-ffuzz -fno-llvm` now results in an error.

3 files changed, 11 insertions(+), 2 deletions(-)

lib/init/src/main.zig+1-1
......@@ -45,7 +45,7 @@ test "fuzz example" {
4545
4646fn testOne(context: void, smith: *std.testing.Smith) !void {
4747 _ = context;
48 // Try command `zig build test --fuzz -Doptimize=ReleaseFast` to see if it manages to fail this test case!
48 // Try running `zig build test --fuzz` and see if it manages to fail this test case!
4949
5050 const gpa = std.testing.allocator;
5151 var list: std.ArrayList(u8) = .empty;
src/Compilation/Config.zig+9-1
......@@ -147,6 +147,7 @@ pub const ResolveError = error{
147147 TargetRequiresPie,
148148 SanitizeThreadRequiresPie,
149149 SanitizeThreadRequiresLlvmBackend,
150 FuzzRequiresLlvmBackend,
150151 BackendLacksErrorTracing,
151152 LlvmLibraryUnavailable,
152153 LldUnavailable,
......@@ -196,7 +197,8 @@ pub fn resolve(options: Options) ResolveError!Config {
196197 break :b options.use_lib_llvm orelse true;
197198 };
198199
199 const root_optimize_mode = options.root_optimize_mode orelse .debug;
200 const root_optimize_mode = options.root_optimize_mode orelse
201 @as(std.lang.OptimizeMode, if (options.any_fuzz) .safe else .debug);
200202
201203 // Make a decision on whether to use Clang or Aro for translate-c and compiling C files.
202204 const c_frontend: CFrontend = b: {
......@@ -349,6 +351,12 @@ pub fn resolve(options: Options) ResolveError!Config {
349351 break :b true;
350352 }
351353
354 if (options.any_fuzz) {
355 // Fuzzing instrumentation requires the LLVM backend.
356 if (options.use_llvm == false) return error.FuzzRequiresLlvmBackend;
357 break :b true;
358 }
359
352360 if (options.use_llvm) |x| break :b x;
353361
354362 // If we cannot use LLVM libraries, then our own backends will be a
src/main.zig+1
......@@ -4328,6 +4328,7 @@ fn createModule(
43284328 error.TargetRequiresPie => fatal("the specified target requires position independent executables", .{}),
43294329 error.SanitizeThreadRequiresPie => fatal("thread sanitization requires position independent executables", .{}),
43304330 error.SanitizeThreadRequiresLlvmBackend => fatal("thread sanitization requires the LLVM backend", .{}),
4331 error.FuzzRequiresLlvmBackend => fatal("fuzzing requires the LLVM backend", .{}),
43314332 error.BackendLacksErrorTracing => fatal("the selected backend has not yet implemented error return tracing", .{}),
43324333 error.LlvmLibraryUnavailable => fatal("zig was compiled without LLVM libraries", .{}),
43334334 error.LldUnavailable => fatal("zig was compiled without LLD libraries", .{}),