Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit 189737e

Browse files
committed
Issue #110 - Fix afl-clang-fast -E and -shared regressions.
1 parent fcf734a commit 189737e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

llvm_mode/afl-clang-fast.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static void find_obj(u8* argv0) {
103103

104104
static void edit_params(u32 argc, char** argv) {
105105

106-
u8 fortify_set = 0, asan_set = 0, x_set = 0, bit_mode = 0;
106+
u8 fortify_set = 0, asan_set = 0, x_set = 0, bit_mode = 0,
107+
shared_linking = 0, preprocessor_only = 0;
107108
u8 *name;
108109

109110
cc_params = ck_alloc((argc + 128) * sizeof(u8*));
@@ -158,6 +159,9 @@ static void edit_params(u32 argc, char** argv) {
158159
if (!strcmp(cur, "-Wl,-z,defs") ||
159160
!strcmp(cur, "-Wl,--no-undefined")) continue;
160161

162+
if (!strcmp(cur, "-E")) preprocessor_only = 1;
163+
if (!strcmp(cur, "-shared")) shared_linking = 1;
164+
161165
cc_params[cc_par_cnt++] = cur;
162166

163167
}
@@ -277,6 +281,23 @@ static void edit_params(u32 argc, char** argv) {
277281
cc_params[cc_par_cnt++] = "none";
278282
}
279283

284+
if (preprocessor_only || shared_linking) {
285+
/* In the preprocessor_only case (-E), we are not actually compiling at
286+
all but requesting the compiler to output preprocessed sources only.
287+
We must not add the runtime in this case because the compiler will
288+
simply output its binary content back on stdout, breaking any build
289+
systems that rely on a separate source preprocessing step.
290+
291+
The shared_linking case (-shared) is more complex. This flag should
292+
only be passed when linking a shared object. When loading such a shared
293+
object into a binary that has also been built with AFL, two AFL runtimes
294+
will exist side-by-side. This is only a problem in the dynamic loading
295+
case because for static linking, the compiler can de-duplicate the
296+
runtime. We must hence avoid attaching the runtime to shared objects. */
297+
cc_params[cc_par_cnt] = NULL;
298+
return;
299+
}
300+
280301
#ifndef __ANDROID__
281302
switch (bit_mode) {
282303

0 commit comments

Comments
 (0)