about summary refs log tree commit diff homepage
path: root/scripts/klee-gcc
blob: 2add2248390f1569e9d3a987a614604df7665bf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python

# ===-- klee-gcc ----- ----------------------------------------------------===##
# 
#                      The KLEE Symbolic Virtual Machine
# 
#  This file is distributed under the University of Illinois Open Source
#  License. See LICENSE.TXT for details.
# 
# ===----------------------------------------------------------------------===##

import os, sys

def isLinkCommand():
    # Look for '-Wl,' as a signal that we are calling the linker. What a hack.
    for arg in sys.argv:
        if arg.startswith('-Wl,'):
            return True

def main():
    if not isLinkCommand():
        os.execvp("llvm-gcc", ["llvm-gcc", "-emit-llvm"] + sys.argv[1:])
        return 1

    # Otherwise, strip out arguments that llvm-ld doesn't understand. I don't
    # want my previous explicit declaration of hackyness to imply that this bit
    # of code here is not also a complete and total hack, it is.
    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,'):
            continue

        linkArgs.append(a)
    
    os.execvp("llvm-ld", ["llvm-ld", "--disable-opt"] + linkArgs)
    return 1

if __name__ == '__main__':
    main()