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" {...@@ -45,7 +45,7 @@ test "fuzz example" {
4545
46fn testOne(context: void, smith: *std.testing.Smith) !void {46fn testOne(context: void, smith: *std.testing.Smith) !void {
47 _ = context;47 _ = 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
50 const gpa = std.testing.allocator;50 const gpa = std.testing.allocator;
51 var list: std.ArrayList(u8) = .empty;51 var list: std.ArrayList(u8) = .empty;
src/Compilation/Config.zig+9-1
...@@ -147,6 +147,7 @@ pub const ResolveError = error{...@@ -147,6 +147,7 @@ pub const ResolveError = error{
147 TargetRequiresPie,147 TargetRequiresPie,
148 SanitizeThreadRequiresPie,148 SanitizeThreadRequiresPie,
149 SanitizeThreadRequiresLlvmBackend,149 SanitizeThreadRequiresLlvmBackend,
150 FuzzRequiresLlvmBackend,
150 BackendLacksErrorTracing,151 BackendLacksErrorTracing,
151 LlvmLibraryUnavailable,152 LlvmLibraryUnavailable,
152 LldUnavailable,153 LldUnavailable,
...@@ -196,7 +197,8 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -196,7 +197,8 @@ pub fn resolve(options: Options) ResolveError!Config {
196 break :b options.use_lib_llvm orelse true;197 break :b options.use_lib_llvm orelse true;
197 };198 };
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
201 // Make a decision on whether to use Clang or Aro for translate-c and compiling C files.203 // Make a decision on whether to use Clang or Aro for translate-c and compiling C files.
202 const c_frontend: CFrontend = b: {204 const c_frontend: CFrontend = b: {
...@@ -349,6 +351,12 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -349,6 +351,12 @@ pub fn resolve(options: Options) ResolveError!Config {
349 break :b true;351 break :b true;
350 }352 }
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
352 if (options.use_llvm) |x| break :b x;360 if (options.use_llvm) |x| break :b x;
353361
354 // If we cannot use LLVM libraries, then our own backends will be a362 // If we cannot use LLVM libraries, then our own backends will be a
src/main.zig+1
...@@ -4328,6 +4328,7 @@ fn createModule(...@@ -4328,6 +4328,7 @@ fn createModule(
4328 error.TargetRequiresPie => fatal("the specified target requires position independent executables", .{}),4328 error.TargetRequiresPie => fatal("the specified target requires position independent executables", .{}),
4329 error.SanitizeThreadRequiresPie => fatal("thread sanitization requires position independent executables", .{}),4329 error.SanitizeThreadRequiresPie => fatal("thread sanitization requires position independent executables", .{}),
4330 error.SanitizeThreadRequiresLlvmBackend => fatal("thread sanitization requires the LLVM backend", .{}),4330 error.SanitizeThreadRequiresLlvmBackend => fatal("thread sanitization requires the LLVM backend", .{}),
4331 error.FuzzRequiresLlvmBackend => fatal("fuzzing requires the LLVM backend", .{}),
4331 error.BackendLacksErrorTracing => fatal("the selected backend has not yet implemented error return tracing", .{}),4332 error.BackendLacksErrorTracing => fatal("the selected backend has not yet implemented error return tracing", .{}),
4332 error.LlvmLibraryUnavailable => fatal("zig was compiled without LLVM libraries", .{}),4333 error.LlvmLibraryUnavailable => fatal("zig was compiled without LLVM libraries", .{}),
4333 error.LldUnavailable => fatal("zig was compiled without LLD libraries", .{}),4334 error.LldUnavailable => fatal("zig was compiled without LLD libraries", .{}),