From 189737e48f7d747ab3a702f2406b22b4afd12d7d Mon Sep 17 00:00:00 2001 From: "Christian Holler (:decoder)" Date: Tue, 4 Aug 2020 14:18:27 +0200 Subject: [PATCH] Issue #110 - Fix afl-clang-fast -E and -shared regressions. --- llvm_mode/afl-clang-fast.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/llvm_mode/afl-clang-fast.c b/llvm_mode/afl-clang-fast.c index 2104a1244..abbc5e0e4 100644 --- a/llvm_mode/afl-clang-fast.c +++ b/llvm_mode/afl-clang-fast.c @@ -103,7 +103,8 @@ static void find_obj(u8* argv0) { static void edit_params(u32 argc, char** argv) { - u8 fortify_set = 0, asan_set = 0, x_set = 0, bit_mode = 0; + u8 fortify_set = 0, asan_set = 0, x_set = 0, bit_mode = 0, + shared_linking = 0, preprocessor_only = 0; u8 *name; cc_params = ck_alloc((argc + 128) * sizeof(u8*)); @@ -158,6 +159,9 @@ static void edit_params(u32 argc, char** argv) { if (!strcmp(cur, "-Wl,-z,defs") || !strcmp(cur, "-Wl,--no-undefined")) continue; + if (!strcmp(cur, "-E")) preprocessor_only = 1; + if (!strcmp(cur, "-shared")) shared_linking = 1; + cc_params[cc_par_cnt++] = cur; } @@ -277,6 +281,23 @@ static void edit_params(u32 argc, char** argv) { cc_params[cc_par_cnt++] = "none"; } + if (preprocessor_only || shared_linking) { + /* In the preprocessor_only case (-E), we are not actually compiling at + all but requesting the compiler to output preprocessed sources only. + We must not add the runtime in this case because the compiler will + simply output its binary content back on stdout, breaking any build + systems that rely on a separate source preprocessing step. + + The shared_linking case (-shared) is more complex. This flag should + only be passed when linking a shared object. When loading such a shared + object into a binary that has also been built with AFL, two AFL runtimes + will exist side-by-side. This is only a problem in the dynamic loading + case because for static linking, the compiler can de-duplicate the + runtime. We must hence avoid attaching the runtime to shared objects. */ + cc_params[cc_par_cnt] = NULL; + return; + } + #ifndef __ANDROID__ switch (bit_mode) {