@@ -103,7 +103,8 @@ static void find_obj(u8* argv0) {
103103
104104static 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
0 commit comments