| author | |
| committer | |
| log | f0feda820e678a7a8f7c2716b515145f4b9a5303 |
| tree | 4623cb6ce4c3f2933c0248d66879026a180ad74a |
| parent | bb79c85cb7ad591e0d8d4fe94b3c32883173c5fa |
| parent | 0ba77eca7430ecb7c9852df175f3fc175bf50bbf |
| signature |
add standalone test for libfuzzer initialization5 files changed, 53 insertions(+), 1 deletions(-)
lib/std/os/linux.zig+1| ... | ... | @@ -523,6 +523,7 @@ pub const getauxval = if (extern_getauxval) struct { |
| 523 | 523 | }.getauxval else getauxvalImpl; |
| 524 | 524 | |
| 525 | 525 | fn getauxvalImpl(index: usize) callconv(.c) usize { |
| 526 | @disableInstrumentation(); | |
| 526 | 527 | const auxv = elf_aux_maybe orelse return 0; |
| 527 | 528 | var i: usize = 0; |
| 528 | 529 | while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { |
src/link/MachO.zig+1-1| ... | ... | @@ -416,7 +416,7 @@ pub fn flushModule( |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | if (comp.config.any_fuzz) { |
| 419 | try positionals.append(try link.openObjectInput(diags, comp.fuzzer_lib.?.full_object_path)); | |
| 419 | try positionals.append(try link.openArchiveInput(diags, comp.fuzzer_lib.?.full_object_path, false, false)); | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | if (comp.ubsan_rt_lib) |crt_file| { |
test/standalone/build.zig.zon+3| ... | ... | @@ -108,6 +108,9 @@ |
| 108 | 108 | .libcxx = .{ |
| 109 | 109 | .path = "libcxx", |
| 110 | 110 | }, |
| 111 | .libfuzzer = .{ | |
| 112 | .path = "libfuzzer", | |
| 113 | }, | |
| 111 | 114 | .load_dynamic_library = .{ |
| 112 | 115 | .path = "load_dynamic_library", |
| 113 | 116 | }, |
test/standalone/libfuzzer/build.zig created+26| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | ||
| 4 | pub fn build(b: *std.Build) void { | |
| 5 | const target = b.standardTargetOptions(.{}); | |
| 6 | const optimize = b.standardOptimizeOption(.{}); | |
| 7 | ||
| 8 | if (builtin.os.tag == .windows) return; // TODO: libfuzzer support for windows | |
| 9 | ||
| 10 | const run_step = b.step("run", "Run executables"); | |
| 11 | const exe = b.addExecutable(.{ | |
| 12 | .name = "main", | |
| 13 | .root_module = b.createModule(.{ | |
| 14 | .root_source_file = b.path("main.zig"), | |
| 15 | .target = target, | |
| 16 | .optimize = optimize, | |
| 17 | .fuzz = true, | |
| 18 | }), | |
| 19 | }); | |
| 20 | ||
| 21 | b.installArtifact(exe); | |
| 22 | b.default_step = run_step; | |
| 23 | ||
| 24 | const run_artifact = b.addRunArtifact(exe); | |
| 25 | run_step.dependOn(&run_artifact.step); | |
| 26 | } |
test/standalone/libfuzzer/main.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | const FuzzerSlice = extern struct { | |
| 4 | ptr: [*]const u8, | |
| 5 | len: usize, | |
| 6 | ||
| 7 | fn fromSlice(s: []const u8) FuzzerSlice { | |
| 8 | return .{ .ptr = s.ptr, .len = s.len }; | |
| 9 | } | |
| 10 | }; | |
| 11 | ||
| 12 | extern fn fuzzer_set_name(name_ptr: [*]const u8, name_len: usize) void; | |
| 13 | extern fn fuzzer_init(cache_dir: FuzzerSlice) void; | |
| 14 | extern fn fuzzer_init_corpus_elem(input_ptr: [*]const u8, input_len: usize) void; | |
| 15 | extern fn fuzzer_coverage_id() u64; | |
| 16 | ||
| 17 | pub fn main() !void { | |
| 18 | fuzzer_init(FuzzerSlice.fromSlice("")); | |
| 19 | fuzzer_init_corpus_elem("hello".ptr, "hello".len); | |
| 20 | fuzzer_set_name("test".ptr, "test".len); | |
| 21 | _ = fuzzer_coverage_id(); | |
| 22 | } |