@@ -10,11 +10,11 @@ pub fn build(b: *std.Build) !void {
10
10
11
11
// Custom options
12
12
const use_z = b .option (bool , "use-z" , "Use system zlib" ) orelse true ;
13
+ const enable_lto = b .option (bool , "enable-lto" , "Enable LTO mode" ) orelse true ;
13
14
const build_nyx = b .option (bool , "build-nyx" , "Build Nyx mode on Linux" ) orelse true ;
14
15
const enable_wafl = b .option (bool , "enable-wafl" , "Enable WAFL mode on WASI" ) orelse false ;
15
16
const build_coresight = b .option (bool , "build-coresight" , "Build CoreSight mode on ARM64 Linux" ) orelse true ;
16
17
const build_unicorn_aarch64 = b .option (bool , "build-unicorn-aarch64" , "Build Unicorn mode on ARM64" ) orelse true ;
17
- const enable_lto = b .option (bool , "enable-lto" , "Enable LTO mode" ) orelse if (target .result .isDarwin ()) false else true ;
18
18
19
19
// Dependencies
20
20
const AFLplusplus_dep = b .dependency ("AFLplusplus" , .{});
@@ -259,13 +259,9 @@ pub fn build(b: *std.Build) !void {
259
259
b .fmt ("-DCLANGPP_BIN=\" {s}/clang++\" " , .{llvm_bin_dir }),
260
260
});
261
261
if (enable_lto ) {
262
- llvm_c_flags .appendSliceAssumeCapacity (&.{
263
- "-DAFL_CLANG_FLTO=\" -flto\" " ,
264
- });
262
+ llvm_c_flags .appendAssumeCapacity ("-DAFL_CLANG_FLTO=\" -flto\" " );
265
263
} else {
266
- llvm_c_flags .appendSliceAssumeCapacity (&.{
267
- "-DAFL_CLANG_FLTO=\"\" " ,
268
- });
264
+ llvm_c_flags .appendAssumeCapacity ("-DAFL_CLANG_FLTO=\"\" " );
269
265
}
270
266
if (target .query .isNative ()) {
271
267
llvm_c_flags .appendAssumeCapacity ("-march=native" );
@@ -281,11 +277,6 @@ pub fn build(b: *std.Build) !void {
281
277
if (enable_wafl and target .result .isWasm ()) {
282
278
llvm_cpp_flags .appendSliceAssumeCapacity (&.{ "-DNDEBUG" , "-DNO_TLS" });
283
279
}
284
- if (target .result .isDarwin ()) {
285
- llvm_cpp_flags .appendSliceAssumeCapacity (&.{ "-Wl,-flat_namespace" , "-Wl,-undefined,suppress" });
286
- } else {
287
- llvm_cpp_flags .appendAssumeCapacity ("-Wl,-znodelete" );
288
- }
289
280
290
281
// LLVM instrumentation object suite
291
282
const llvm_objs_step = b .step ("llvm_objs" , "Install LLVM instrumentation object suite" );
@@ -336,9 +327,16 @@ pub fn build(b: *std.Build) !void {
336
327
const llvm_libs_step = b .step ("llvm_libs" , "Install LLVM instrumentation library suite" );
337
328
338
329
const llvm_inc_dir = std .mem .trimRight (u8 , b .run (&.{ "llvm-config" , "--includedir" }), "\n " );
339
- const llvm_name = std .mem .trimRight (u8 , b .run (&.{ "llvm-config" , "--libs" }), "\n " )[2.. ];
340
330
const llvm_inc_path = std.Build.LazyPath { .cwd_relative = llvm_inc_dir };
341
331
332
+ const llvm_libs = std .mem .trimRight (u8 , b .run (&.{ "llvm-config" , "--libs" }), "\n " );
333
+ const llvm_name : []const u8 = blk : {
334
+ if (std .mem .indexOf (u8 , llvm_libs , "-lLLVM-1" )) | llvm_lib_name_idx | {
335
+ break :blk llvm_libs [llvm_lib_name_idx + 2 .. llvm_lib_name_idx + 9 ];
336
+ }
337
+ unreachable ;
338
+ };
339
+
342
340
const llvm_common_obj = b .addObject (.{
343
341
.name = "afl-llvm-common" ,
344
342
.pic = true ,
@@ -418,7 +416,7 @@ pub fn build(b: *std.Build) !void {
418
416
cc_exe_install .step .dependOn (llvm_libs_step );
419
417
llvm_exes_step .dependOn (& cc_exe_install .step );
420
418
421
- if (! target . result . isDarwin () ) {
419
+ if (enable_lto ) {
422
420
const ld_lto_exe = b .addExecutable (.{
423
421
.name = "afl-ld-lto" ,
424
422
.target = target ,
@@ -600,6 +598,7 @@ const LLVM_EXE_C_FLAGS = .{
600
598
601
599
const LLVM_EXE_CPP_FLAGS = .{
602
600
"-fno-rtti" ,
601
+ "-Wl,-znodelete" ,
603
602
"-fno-exceptions" ,
604
603
"-Wno-deprecated-declarations" ,
605
604
};
0 commit comments