packaging: add libc_malloc_debug.so.0
[platform/upstream/glibc.git] / asan-glibc-gcc-wrapper.py
1 #!/usr/bin/env python
2 import os
3 import re
4 import shutil
5 import sys
6
7 GCC = 'gcc'
8
9 blacklist=['rtld', '/dl-', 'elf/', 'string/mem', 'time/time',
10            'time/gettimeofday', 'time/timegm', 'time/timespec_get',
11            'nptl/libc_pthread_init', 'nptl/register-atfork',
12             #In Tizen, ASan tries to write error log to procfs, in case procfs is not mounted,
13             #this action will generate a kernel panic. So, just disble errors which happens because
14             #of dword-aligned reading by glibc.
15            'string',
16            ]
17
18 def AllowAsan(out_file):
19   match = re.match(r'/.*build/(.*).os$', out_file)
20   if not match:
21     #print >>sys.stderr, 'FALLBACK_NO_MATCH: %s' % out_file
22     return False
23   obj = match.group(1)
24
25   for b in blacklist:
26     if re.search(b, obj):
27       #print >>sys.stderr, 'FALLBACK_BLACKLIST: %s' % obj
28       return False
29   return True
30
31 def o():
32   try:
33     i = sys.argv.index('-o')
34     return sys.argv[i + 1]
35   except Exception:
36     return ''
37
38 if __name__ == '__main__':
39   args = sys.argv[1:]
40   args = [arg for arg in args if arg != '-Wl,-z,defs']
41
42   if AllowAsan(o()):
43     print >> sys.stderr, 'ASAN:', o()
44     args.append('-fsanitize-recover=address')
45     args.append('-fsanitize=address')
46     args.append('--param')
47     args.append('asan-use-after-return=0')
48
49   args.append('-fno-omit-frame-pointer')
50   args.append('-Wno-error')
51   args.append('-DSKIP_IFUNC');
52
53   os.execvp(GCC, [GCC] + args)