about summary refs log tree commit diff
path: root/llvm_mode/afl-clang-fast.c
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-08-01 13:56:10 +0200
committervan Hauser <vh@thc.org>2020-08-01 13:56:10 +0200
commit6efe51a8a78a9451ef94eeb0705d9a976a3365ca (patch)
treec665c6cb04d0c0cee83e9c547d392577337864b5 /llvm_mode/afl-clang-fast.c
parent593940c39a3838b072863b7093ed31f92846cfcb (diff)
downloadafl++-6efe51a8a78a9451ef94eeb0705d9a976a3365ca.tar.gz
improve chances to compile with lto
Diffstat (limited to 'llvm_mode/afl-clang-fast.c')
-rw-r--r--llvm_mode/afl-clang-fast.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm_mode/afl-clang-fast.c b/llvm_mode/afl-clang-fast.c
index 8e3ca90c..c1b11a04 100644
--- a/llvm_mode/afl-clang-fast.c
+++ b/llvm_mode/afl-clang-fast.c
@@ -162,6 +162,7 @@ static void find_obj(u8 *argv0) {
 static void edit_params(u32 argc, char **argv, char **envp) {
 
   u8  fortify_set = 0, asan_set = 0, x_set = 0, bit_mode = 0;
+  u8  have_pic = 0, have_s = 0, have_c = 0, have_shared = 0;
   u8 *name;
 
   cc_params = ck_alloc((argc + 128) * sizeof(u8 *));
@@ -363,6 +364,23 @@ static void edit_params(u32 argc, char **argv, char **envp) {
 
   }
 
+  u32 idx;
+  if (lto_mode && argc > 1) {
+
+    for (idx = 1; idx < argc; idx++) {
+
+      if (!strncmp(argv[idx], "-shared", 7)) have_shared = 1;
+      if (!strcmp(argv[idx], "-S")) have_s = 1;
+      if (!strcmp(argv[idx], "-c")) have_c = 1;
+      if (!strncasecmp(argv[idx], "-fpic", 5)) have_pic = 1;
+
+    }
+
+    if (!have_pic) cc_params[cc_par_cnt++] = "-fPIC";
+    if (!have_shared && (have_s || have_c)) cc_params[cc_par_cnt++] = "-shared";
+
+  }
+
   /* Detect stray -v calls from ./configure scripts. */
 
   while (--argc) {