about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMate Soos <soos.mate@gmail.com>2015-12-04 00:05:53 +0000
committerMate Soos <soos.mate@gmail.com>2015-12-04 00:05:53 +0000
commitcd2ccf035d5e5abaa3851da5d0ee88ca7cd97d40 (patch)
tree3a060fc3aacc34ff55b7646ff181ef9426f5f762
parent6b0082b01e60ea2361da401694ea5aa7f7a6e966 (diff)
downloadklee-cd2ccf035d5e5abaa3851da5d0ee88ca7cd97d40.tar.gz
Fixing klee-clang to strip all flags not understood by llvm-link
-rwxr-xr-xscripts/klee-clang41
1 files changed, 31 insertions, 10 deletions
diff --git a/scripts/klee-clang b/scripts/klee-clang
index 2584024d..212bc8ed 100755
--- a/scripts/klee-clang
+++ b/scripts/klee-clang
@@ -2,6 +2,8 @@
 
 import os, sys
 import subprocess
+import re
+
 
 def isLinkCommand():
     # Look for '-Wl,' as a signal that we are calling the linker. What a hack.
@@ -9,6 +11,19 @@ def isLinkCommand():
         if arg.startswith('-Wl,'):
             return True
 
+link_exact_filter = ['-g', '-W', '-O', '-D', '-f',
+                     '-fnested-functions', '-pthread', '-fPIC', '-g',
+                     '-pedantic', '-shared', '-rdynamic', '-nodefaultlibs']
+
+link_regexp_filter_patts = ['^-Wl.*', '^-l.*', '^-W.*', '^-O\d', '^-gg.*',
+                            '^-mtune.*', '^-std=c.*', '^-f.*frame-pointer',
+                            '^-fvisibility.*']
+link_regexp_filters = []
+for patt in link_regexp_filter_patts:
+    prog = re.compile(patt)
+    link_regexp_filters.append(prog)
+
+
 def main():
     llvm_path = subprocess.Popen(["llvm-config", "--bindir"], stdout=subprocess.PIPE).communicate()[0].strip()
 
@@ -22,23 +37,29 @@ def main():
     args = sys.argv[1:]
     linkArgs = []
     for a in args:
-        if a in ('-g', '-W', '-O', '-D', '-f',
-                 '-fnested-functions', '-pthread'):
-            continue
-        elif a.startswith('-Wl,'):
+        a = a.strip()
+        if a in link_exact_filter:
             continue
 
-	if a in linkArgs:
-	    continue
+        match = False
+        for filt in link_regexp_filters:
+            # print "matching %s on filter" % a
+            if filt.match(a):
+                # print "MATCHED %s" % a
+                match = True
+                break
 
-        if a.startswith('-l'):
-	    continue
+        if match:
+            continue
+
+        if a in linkArgs:
+            continue
 
         linkArgs.append(a)
-    
+
     os.execvp(llvm_path+"/llvm-link", [llvm_path+"/llvm-link"] + linkArgs)
     return 1
 
+
 if __name__ == '__main__':
     main()
-