@@ -20,6 +20,7 @@ pub fn build(b: *std.Build) void {
20
20
const AFLplusplus_src_path = AFLplusplus_dep .path ("src/" );
21
21
const AFLplusplus_utl_path = AFLplusplus_dep .path ("utils/" );
22
22
const AFLplusplus_inc_path = AFLplusplus_dep .path ("include/" );
23
+ const AFLplusplus_ins_path = AFLplusplus_dep .path ("instrumentation/" );
23
24
24
25
// Common flags
25
26
var flags = std .BoundedArray ([]const u8 , 16 ){};
@@ -235,18 +236,44 @@ pub fn build(b: *std.Build) void {
235
236
236
237
b .default_step .dependOn (exes_step );
237
238
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
+
238
268
// Executable utility suite
239
269
const exe_utils_step = b .step ("exe_utils" , "Install executable utility suite" );
240
270
241
- // TODO: LLVM instrumentation
242
-
243
271
const network_client_exe_util = b .addExecutable (.{
244
272
.name = "afl-network-client" ,
245
273
.target = target ,
246
274
.version = version ,
247
275
.optimize = optimize ,
248
276
});
249
-
250
277
network_client_exe_util .addCSourceFile (.{
251
278
.file = AFLplusplus_utl_path .path (b , "afl_network_proxy/afl-network-client.c" ),
252
279
.flags = flags .constSlice (),
@@ -258,8 +285,8 @@ pub fn build(b: *std.Build) void {
258
285
network_client_exe_util .addIncludePath (AFLplusplus_inc_path );
259
286
network_client_exe_util .linkLibC ();
260
287
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 );
263
290
264
291
const network_server_exe_util = b .addExecutable (.{
265
292
.name = "afl-network-server" ,
@@ -281,17 +308,15 @@ pub fn build(b: *std.Build) void {
281
308
network_server_exe_util .addObject (common_obj );
282
309
network_server_exe_util .linkLibC ();
283
310
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 );
286
313
287
314
b .default_step .dependOn (exe_utils_step );
288
315
289
316
// Library utility suite
290
317
const lib_utils_step = b .step ("lib_utils" , "Install library utility suite" );
291
318
292
319
if (! target .result .os .tag .isDarwin ()) {
293
- // TODO: GCC plugin instrumentation
294
-
295
320
const dislocator_lib_util = b .addSharedLibrary (.{
296
321
.name = "dislocator" ,
297
322
.pic = true ,
@@ -327,7 +352,7 @@ pub fn build(b: *std.Build) void {
327
352
lib_utils_step .dependOn (& tokencap_lib_util_install .step );
328
353
329
354
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)
331
356
}
332
357
}
333
358
@@ -365,16 +390,16 @@ pub fn build(b: *std.Build) void {
365
390
const argvfuzz_lib_util_install = b .addInstallArtifact (argvfuzz_lib_util , .{});
366
391
lib_utils_step .dependOn (& argvfuzz_lib_util_install .step );
367
392
368
- // TODO: FRIDA mode
393
+ // TODO: FRIDA mode (frida_mode/GNUmakefile)
369
394
370
- // TODO: QEMU mode
395
+ // TODO: QEMU mode (qemu_mode/build_qemu_support.sh)
371
396
372
397
if (build_nyx and target .result .os .tag == .linux ) {
373
- // TODO: Nyx mode
398
+ // TODO: Nyx mode (nyx_mode/build_nyx_support.sh)
374
399
}
375
400
376
401
if (! target .result .cpu .arch .isAARCH64 () or build_unicorn_aarch64 ) {
377
- // TODO: Unicorn mode
402
+ // TODO: Unicorn mode (unicorn_mode/build_unicorn_support.sh)
378
403
}
379
404
380
405
b .default_step .dependOn (lib_utils_step );
@@ -422,6 +447,34 @@ const EXE_FLAGS = .{
422
447
"-DDOC_PATH=\"\" " ,
423
448
};
424
449
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
+
425
478
const LIB_FLAGS = .{
426
479
"-O3" ,
427
480
"-g" ,
0 commit comments