Skip to content

Commit cd14dd0

Browse files
committed
feat: start LLVM instrumentation implementation
1 parent e09aea2 commit cd14dd0

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

build.zig

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn build(b: *std.Build) void {
2020
const AFLplusplus_src_path = AFLplusplus_dep.path("src/");
2121
const AFLplusplus_utl_path = AFLplusplus_dep.path("utils/");
2222
const AFLplusplus_inc_path = AFLplusplus_dep.path("include/");
23+
const AFLplusplus_ins_path = AFLplusplus_dep.path("instrumentation/");
2324

2425
// Common flags
2526
var flags = std.BoundedArray([]const u8, 16){};
@@ -235,18 +236,44 @@ pub fn build(b: *std.Build) void {
235236

236237
b.default_step.dependOn(exes_step);
237238

239+
// LLVM instrumentation flags
240+
var llvm_flags = std.BoundedArray([]const u8, 16){};
241+
llvm_flags.appendSliceAssumeCapacity(&EXE_LLVM_FLAGS);
242+
llvm_flags.appendSliceAssumeCapacity(&.{ lib_path_flag, bin_path_flag });
243+
244+
// Executable LLVM instrumentation suite
245+
const exe_llvm_step = b.step("exe_llvm", "Install executable instrumentation suite");
246+
247+
const cc_exe = b.addExecutable(.{
248+
.name = "afl-cc",
249+
.target = target,
250+
.version = version,
251+
.optimize = optimize,
252+
});
253+
cc_exe.addCSourceFile(.{
254+
.file = AFLplusplus_src_path.path(b, "afl-cc.c"),
255+
.flags = llvm_flags.constSlice(),
256+
});
257+
cc_exe.addIncludePath(AFLplusplus_inc_path);
258+
cc_exe.addIncludePath(AFLplusplus_ins_path);
259+
cc_exe.addObject(common_obj);
260+
cc_exe.linkLibC();
261+
262+
const cc_exe_install = b.addInstallArtifact(cc_exe, .{});
263+
exe_llvm_step.dependOn(&cc_exe_install.step);
264+
265+
// TODO: finish implementing LLVM instrumentation
266+
// b.default_step.dependOn(exe_llvm_step);
267+
238268
// Executable utility suite
239269
const exe_utils_step = b.step("exe_utils", "Install executable utility suite");
240270

241-
// TODO: LLVM instrumentation
242-
243271
const network_client_exe_util = b.addExecutable(.{
244272
.name = "afl-network-client",
245273
.target = target,
246274
.version = version,
247275
.optimize = optimize,
248276
});
249-
250277
network_client_exe_util.addCSourceFile(.{
251278
.file = AFLplusplus_utl_path.path(b, "afl_network_proxy/afl-network-client.c"),
252279
.flags = flags.constSlice(),
@@ -258,8 +285,8 @@ pub fn build(b: *std.Build) void {
258285
network_client_exe_util.addIncludePath(AFLplusplus_inc_path);
259286
network_client_exe_util.linkLibC();
260287

261-
const network_client_exe_install_util = b.addInstallArtifact(network_client_exe_util, .{});
262-
exe_utils_step.dependOn(&network_client_exe_install_util.step);
288+
const network_client_exe_util_install = b.addInstallArtifact(network_client_exe_util, .{});
289+
exe_utils_step.dependOn(&network_client_exe_util_install.step);
263290

264291
const network_server_exe_util = b.addExecutable(.{
265292
.name = "afl-network-server",
@@ -281,17 +308,15 @@ pub fn build(b: *std.Build) void {
281308
network_server_exe_util.addObject(common_obj);
282309
network_server_exe_util.linkLibC();
283310

284-
const network_server_exe_install_util = b.addInstallArtifact(network_server_exe_util, .{});
285-
exe_utils_step.dependOn(&network_server_exe_install_util.step);
311+
const network_server_exe_util_install = b.addInstallArtifact(network_server_exe_util, .{});
312+
exe_utils_step.dependOn(&network_server_exe_util_install.step);
286313

287314
b.default_step.dependOn(exe_utils_step);
288315

289316
// Library utility suite
290317
const lib_utils_step = b.step("lib_utils", "Install library utility suite");
291318

292319
if (!target.result.os.tag.isDarwin()) {
293-
// TODO: GCC plugin instrumentation
294-
295320
const dislocator_lib_util = b.addSharedLibrary(.{
296321
.name = "dislocator",
297322
.pic = true,
@@ -327,7 +352,7 @@ pub fn build(b: *std.Build) void {
327352
lib_utils_step.dependOn(&tokencap_lib_util_install.step);
328353

329354
if (build_coresight and target.result.cpu.arch.isAARCH64() and target.result.ofmt == .elf) {
330-
// TODO: CoreSight mode
355+
// TODO: CoreSight mode (coresight_mode/GNUmakefile)
331356
}
332357
}
333358

@@ -365,16 +390,16 @@ pub fn build(b: *std.Build) void {
365390
const argvfuzz_lib_util_install = b.addInstallArtifact(argvfuzz_lib_util, .{});
366391
lib_utils_step.dependOn(&argvfuzz_lib_util_install.step);
367392

368-
// TODO: FRIDA mode
393+
// TODO: FRIDA mode (frida_mode/GNUmakefile)
369394

370-
// TODO: QEMU mode
395+
// TODO: QEMU mode (qemu_mode/build_qemu_support.sh)
371396

372397
if (build_nyx and target.result.os.tag == .linux) {
373-
// TODO: Nyx mode
398+
// TODO: Nyx mode (nyx_mode/build_nyx_support.sh)
374399
}
375400

376401
if (!target.result.cpu.arch.isAARCH64() or build_unicorn_aarch64) {
377-
// TODO: Unicorn mode
402+
// TODO: Unicorn mode (unicorn_mode/build_unicorn_support.sh)
378403
}
379404

380405
b.default_step.dependOn(lib_utils_step);
@@ -422,6 +447,34 @@ const EXE_FLAGS = .{
422447
"-DDOC_PATH=\"\"",
423448
};
424449

450+
const EXE_LLVM_FLAGS = .{
451+
"-O3",
452+
"-funroll-loops",
453+
"-Wall",
454+
"-g",
455+
"-Wno-cast-qual",
456+
"-Wno-variadic-macros",
457+
"-Wno-pointer-sign",
458+
"-Wno-unused-function",
459+
"-Wno-deprecated-copy-with-dtor",
460+
"-DAFL_CLANG_FLTO=\"-flto=full\"",
461+
"-DUSE_BINDIR=1",
462+
// TODO: properly set these by using system `llvm-config`
463+
// "-DLLVM_BINDIR=\"$(LLVM_BINDIR)\"",
464+
// "-DVERSION=\"$(VERSION)\"",
465+
// "-DLLVM_LIBDIR=\"$(LLVM_LIBDIR)\"",
466+
// "-DLLVM_VERSION=\"$(LLVMVER)\"",
467+
// "-DAFL_REAL_LD=\"$(AFL_REAL_LD)\"",
468+
// "-DAFL_CLANG_LDPATH=\"$(AFL_CLANG_LDPATH)\"",
469+
// "-DAFL_CLANG_FUSELD=\"$(AFL_CLANG_FUSELD)\"",
470+
// "-DCLANG_BIN=\"$(CLANG_BIN)\"",
471+
// "-DCLANGPP_BIN=\"$(CLANGPP_BIN)\"",
472+
// "$(AFL_CLANG_DEBUG_PREFIX)",
473+
// "-DLLVM_MINOR=$(LLVM_MINOR)",
474+
// "-DLLVM_MAJOR=$(LLVM_MAJOR)",
475+
// "-DCFLAGS_OPT=\"$(CFLAGS_OPT)",
476+
};
477+
425478
const LIB_FLAGS = .{
426479
"-O3",
427480
"-g",

0 commit comments

Comments
 (0)