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...@@ -460,6 +460,10 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
460 try argv.append(comp.libunwind_static_lib.?.full_object_path);460 try argv.append(comp.libunwind_static_lib.?.full_object_path);
461 }461 }
462462
463 if (comp.config.any_fuzz) {
464 try argv.append(comp.fuzzer_lib.?.full_object_path);
465 }
466
463 if (is_exe_or_dyn_lib and !comp.skip_linker_dependencies) {467 if (is_exe_or_dyn_lib and !comp.skip_linker_dependencies) {
464 if (!comp.config.link_libc) {468 if (!comp.config.link_libc) {
465 if (comp.libc_static_lib) |lib| {469 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...@@ -1144,11 +1144,14 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
1144 _ = try rpath_table.put(rpath, {});1144 _ = try rpath_table.put(rpath, {});
1145 }1145 }
11461146
1147 // TSAN
1148 if (comp.config.any_sanitize_thread) {1147 if (comp.config.any_sanitize_thread) {
1149 try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });1148 try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });
1150 }1149 }
11511150
1151 if (comp.config.any_fuzz) {
1152 try positionals.append(.{ .path = comp.fuzzer_lib.?.full_object_path });
1153 }
1154
1152 // libc1155 // libc
1153 if (!comp.skip_linker_dependencies and !comp.config.link_libc) {1156 if (!comp.skip_linker_dependencies and !comp.config.link_libc) {
1154 if (comp.libc_static_lib) |lib| {1157 if (comp.libc_static_lib) |lib| {
...@@ -1607,6 +1610,10 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {...@@ -1607,6 +1610,10 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
1607 try argv.append(comp.tsan_lib.?.full_object_path);1610 try argv.append(comp.tsan_lib.?.full_object_path);
1608 }1611 }
16091612
1613 if (comp.config.any_fuzz) {
1614 try argv.append(comp.fuzzer_lib.?.full_object_path);
1615 }
1616
1610 // libc1617 // libc
1611 if (!comp.skip_linker_dependencies and !comp.config.link_libc) {1618 if (!comp.skip_linker_dependencies and !comp.config.link_libc) {
1612 if (comp.libc_static_lib) |lib| {1619 if (comp.libc_static_lib) |lib| {
...@@ -2272,6 +2279,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s...@@ -2272,6 +2279,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
2272 man.hash.add(self.bind_global_refs_locally);2279 man.hash.add(self.bind_global_refs_locally);
2273 man.hash.add(self.compress_debug_sections);2280 man.hash.add(self.compress_debug_sections);
2274 man.hash.add(comp.config.any_sanitize_thread);2281 man.hash.add(comp.config.any_sanitize_thread);
2282 man.hash.add(comp.config.any_fuzz);
2275 man.hash.addOptionalBytes(comp.sysroot);2283 man.hash.addOptionalBytes(comp.sysroot);
22762284
2277 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.2285 // 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...@@ -2616,6 +2624,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
2616 try argv.append(comp.tsan_lib.?.full_object_path);2624 try argv.append(comp.tsan_lib.?.full_object_path);
2617 }2625 }
26182626
2627 if (comp.config.any_fuzz) {
2628 try argv.append(comp.fuzzer_lib.?.full_object_path);
2629 }
2630
2619 // libc2631 // libc
2620 if (is_exe_or_dyn_lib and2632 if (is_exe_or_dyn_lib and
2621 !comp.skip_linker_dependencies and2633 !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...@@ -389,11 +389,14 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
389389
390 if (module_obj_path) |path| try positionals.append(.{ .path = path });390 if (module_obj_path) |path| try positionals.append(.{ .path = path });
391391
392 // TSAN
393 if (comp.config.any_sanitize_thread) {392 if (comp.config.any_sanitize_thread) {
394 try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });393 try positionals.append(.{ .path = comp.tsan_lib.?.full_object_path });
395 }394 }
396395
396 if (comp.config.any_fuzz) {
397 try positionals.append(.{ .path = comp.fuzzer_lib.?.full_object_path });
398 }
399
397 for (positionals.items) |obj| {400 for (positionals.items) |obj| {
398 self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {401 self.parsePositional(obj.path, obj.must_link) catch |err| switch (err) {
399 error.MalformedObject,402 error.MalformedObject,
...@@ -462,6 +465,11 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n...@@ -462,6 +465,11 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
462 };465 };
463 }466 }
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
465 // Finally, link against compiler_rt.473 // Finally, link against compiler_rt.
466 const compiler_rt_path: ?[]const u8 = blk: {474 const compiler_rt_path: ?[]const u8 = blk: {
467 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;475 if (comp.compiler_rt_lib) |x| break :blk x.full_object_path;