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

Commit e59fbd9

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

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-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) {
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+
cc_params[cc_par_cnt] = NULL;
291+
return;
292+
}
293+
294+
if (!shared_linking) {
295+
/* In order for AFL to work with shared libraries that are dynamically
296+
loaded through dlopen(), we need to ensure that the main binary exports
297+
the symbols used in the AFL runtime. */
298+
cc_params[cc_par_cnt++] = alloc_printf("-Wl,--dynamic-list=%s/symfile.txt", obj_path);
299+
}
300+
280301
#ifndef __ANDROID__
281302
switch (bit_mode) {
282303

symfile.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"__afl_area_ptr";
3+
"__afl_manual_init";
4+
"__afl_persistent_loop";
5+
"__afl_auto_init";
6+
"__afl_area_initial";
7+
"__afl_prev_loc";
8+
"__sanitizer_cov_trace_pc_guard";
9+
"__sanitizer_cov_trace_pc_guard_init";
10+
};

0 commit comments

Comments
 (0)