| author | |
| committer | |
| log | 3944c72a148096e3933745a9fda0397c0dd67cbf |
| tree | b34df21e1028e8ce27a9e3ea8bae55477793d8f5 |
| parent | 18d9b2850ecba8fca14b11bd18111c17f0415aa9 |
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" { |
| 45 | 45 | ||
| 46 | fn testOne(context: void, smith: *std.testing.Smith) !void { | 46 | fn 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! |
| 49 | 49 | ||
| 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 | }; |
| 198 | 199 | ||
| 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); | ||
| 200 | 202 | ||
| 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 | } |
| 351 | 353 | ||
| 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; |
| 353 | 361 | ||
| 354 | // If we cannot use LLVM libraries, then our own backends will be a | 362 | // 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", .{}), |