authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 19:13:11-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-22 13:07:02-07:00
logb9225aea780a230971f1ae4b4e0b95b31f0a3e1d
tree2f26acf4d861eb2ea379cc366130d46cb33d8ea4
parent7802cf9814c135437863ce742b9951d7656849cd

add libfuzzer to linking


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

src/link/Coff/lld.zig+4
......@@ -460,6 +460,10 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
460460 try argv.append(comp.libunwind_static_lib.?.full_object_path);
461461 }
462462
463 if (comp.config.any_fuzz) {
464 try argv.append(comp.fuzzer_lib.?.full_object_path);
465 }
466
463467 if (is_exe_or_dyn_lib and !comp.skip_linker_dependencies) {
464468 if (!comp.config.link_libc) {
465469 if (comp.libc_static_lib) |lib| {
src/link/Elf.zig+13-1
......@@ -1144,11 +1144,14 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
11441144 _ = try rpath_table.put(rpath, {});
11451145 }
11461146
1147 // TSAN
11481147 if (comp.config.any_sanitize_thread) {
11491148 try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });
11501149 }
11511150
1151 if (comp.config.any_fuzz) {
1152 try positionals.append(.{ .path = comp.fuzzer_lib.?.full_object_path });
1153 }
1154
11521155 // libc
11531156 if (!comp.skip_linker_dependencies and !comp.config.link_libc) {
11541157 if (comp.libc_static_lib) |lib| {
......@@ -1607,6 +1610,10 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
16071610 try argv.append(comp.tsan_lib.?.full_object_path);
16081611 }
16091612
1613 if (comp.config.any_fuzz) {
1614 try argv.append(comp.fuzzer_lib.?.full_object_path);
1615 }
1616
16101617 // libc
16111618 if (!comp.skip_linker_dependencies and !comp.config.link_libc) {
16121619 if (comp.libc_static_lib) |lib| {
......@@ -2272,6 +2279,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
22722279 man.hash.add(self.bind_global_refs_locally);
22732280 man.hash.add(self.compress_debug_sections);
22742281 man.hash.add(comp.config.any_sanitize_thread);
2282 man.hash.add(comp.config.any_fuzz);
22752283 man.hash.addOptionalBytes(comp.sysroot);
22762284
22772285 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
......@@ -2616,6 +2624,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
26162624 try argv.append(comp.tsan_lib.?.full_object_path);
26172625 }
26182626
2627 if (comp.config.any_fuzz) {
2628 try argv.append(comp.fuzzer_lib.?.full_object_path);
2629 }
2630
26192631 // libc
26202632 if (is_exe_or_dyn_lib and
26212633 !comp.skip_linker_dependencies and
src/link/MachO.zig+9-1
......@@ -389,11 +389,14 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
389389
390390 if (module_obj_path) |path| try positionals.append(.{ .path = path });
391391
392 // TSAN
393392 if (comp.config.any_sanitize_thread) {
394393 try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });
395394 }
396395
396 if (comp.config.any_fuzz) {
397 try positionals.append(.{ .path = comp.fuzzer_lib.?.full_object_path });
398 }
399
397400 for (positionals.items) |obj| {
398401 self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {
399402 error.MalformedObject,
......@@ -462,6 +465,11 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
462465 };
463466 }
464467
468 if (comp.fuzzer_lib) |fuzzer_lib| {
469 _ = fuzzer_lib.full_object_path;
470 log.err("TODO macho linking code for adding libfuzzer", .{});
471 }
472
465473 // Finally, link against compiler_rt.
466474 const compiler_rt_path: ?[]const u8 = blk: {
467475 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;