Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial support for integrated fuzzing #20725

Merged
merged 13 commits into from
Jul 23, 2024
Prev Previous commit
Next Next commit
add libfuzzer to linking
  • Loading branch information
andrewrk committed Jul 22, 2024
commit b9225aea780a230971f1ae4b4e0b95b31f0a3e1d
4 changes: 4 additions & 0 deletions src/link/Coff/lld.zig
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
try argv.append(comp.libunwind_static_lib.?.full_object_path);
}

if (comp.config.any_fuzz) {
try argv.append(comp.fuzzer_lib.?.full_object_path);
}

if (is_exe_or_dyn_lib and !comp.skip_linker_dependencies) {
if (!comp.config.link_libc) {
if (comp.libc_static_lib) |lib| {
Expand Down
14 changes: 13 additions & 1 deletion src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1144,11 +1144,14 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
_ = try rpath_table.put(rpath, {});
}

// TSAN
if (comp.config.any_sanitize_thread) {
try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });
}

if (comp.config.any_fuzz) {
try positionals.append(.{ .path = comp.fuzzer_lib.?.full_object_path });
}

// libc
if (!comp.skip_linker_dependencies and !comp.config.link_libc) {
if (comp.libc_static_lib) |lib| {
Expand Down Expand Up @@ -1607,6 +1610,10 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
try argv.append(comp.tsan_lib.?.full_object_path);
}

if (comp.config.any_fuzz) {
try argv.append(comp.fuzzer_lib.?.full_object_path);
}

// libc
if (!comp.skip_linker_dependencies and !comp.config.link_libc) {
if (comp.libc_static_lib) |lib| {
Expand Down Expand Up @@ -2272,6 +2279,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
man.hash.add(self.bind_global_refs_locally);
man.hash.add(self.compress_debug_sections);
man.hash.add(comp.config.any_sanitize_thread);
man.hash.add(comp.config.any_fuzz);
man.hash.addOptionalBytes(comp.sysroot);

// We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
Expand Down Expand Up @@ -2616,6 +2624,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
try argv.append(comp.tsan_lib.?.full_object_path);
}

if (comp.config.any_fuzz) {
try argv.append(comp.fuzzer_lib.?.full_object_path);
}

// libc
if (is_exe_or_dyn_lib and
!comp.skip_linker_dependencies and
Expand Down
10 changes: 9 additions & 1 deletion src/link/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,14 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n

if (module_obj_path) |path| try positionals.append(.{ .path = path });

// TSAN
if (comp.config.any_sanitize_thread) {
try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });
}

if (comp.config.any_fuzz) {
try positionals.append(.{ .path = comp.fuzzer_lib.?.full_object_path });
}

andrewrk marked this conversation as resolved.
Show resolved Hide resolved
for (positionals.items) |obj| {
self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {
error.MalformedObject,
Expand Down Expand Up @@ -462,6 +465,11 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
};
}

if (comp.fuzzer_lib) |fuzzer_lib| {
_ = fuzzer_lib.full_object_path;
log.err("TODO macho linking code for adding libfuzzer", .{});
}

andrewrk marked this conversation as resolved.
Show resolved Hide resolved
// Finally, link against compiler_rt.
const compiler_rt_path: ?[]const u8 = blk: {
if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;
Expand Down