OLD | NEW |
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 | 2 |
3 import argparse | 3 import argparse |
4 import os | 4 import os |
5 import pipes | 5 import pipes |
6 import re | 6 import re |
7 import sys | 7 import sys |
8 | 8 |
9 from utils import FindBaseNaCl, GetObjcopyCmd, get_sfi_string, shellcmd | 9 from utils import FindBaseNaCl, GetObjcopyCmd, get_sfi_string, shellcmd |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 help='Generate code for specified target.') | 96 help='Generate code for specified target.') |
97 argparser.add_argument('--verbose', '-v', dest='verbose', | 97 argparser.add_argument('--verbose', '-v', dest='verbose', |
98 action='store_true', | 98 action='store_true', |
99 help='Display some extra debugging output') | 99 help='Display some extra debugging output') |
100 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], | 100 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], |
101 help='Extra arguments for Subzero') | 101 help='Extra arguments for Subzero') |
102 argparser.add_argument('--llc', dest='llc_args', action='append', | 102 argparser.add_argument('--llc', dest='llc_args', action='append', |
103 default=[], help='Extra arguments for llc') | 103 default=[], help='Extra arguments for llc') |
104 argparser.add_argument('--no-sz', dest='nosz', action='store_true', | 104 argparser.add_argument('--no-sz', dest='nosz', action='store_true', |
105 help='Run only post-Subzero build steps') | 105 help='Run only post-Subzero build steps') |
| 106 argparser.add_argument('--fsanitize-address', dest='asan', |
| 107 action='store_true', |
| 108 help='Instrument with AddressSanitizer') |
106 | 109 |
107 def LinkSandbox(objs, exe, target, verbose=True): | 110 def LinkSandbox(objs, exe, target, verbose=True): |
108 assert target in ('x8632', 'x8664', 'arm32'), \ | 111 assert target in ('x8632', 'x8664', 'arm32'), \ |
109 '-sandbox is not available for %s' % target | 112 '-sandbox is not available for %s' % target |
110 nacl_root = FindBaseNaCl() | 113 nacl_root = FindBaseNaCl() |
111 gold = ('{root}/toolchain/linux_x86/pnacl_newlib_raw/bin/' + | 114 gold = ('{root}/toolchain/linux_x86/pnacl_newlib_raw/bin/' + |
112 'le32-nacl-ld.gold').format(root=nacl_root) | 115 'le32-nacl-ld.gold').format(root=nacl_root) |
113 target_lib_dir = { | 116 target_lib_dir = { |
114 'arm32': 'arm', | 117 'arm32': 'arm', |
115 'x8632': 'x86-32', | 118 'x8632': 'x86-32', |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 --install=toolchain/linux_x86/pnacl_newlib_raw | 259 --install=toolchain/linux_x86/pnacl_newlib_raw |
257 """ | 260 """ |
258 argparser = argparse.ArgumentParser( | 261 argparser = argparse.ArgumentParser( |
259 description=' ' + main.__doc__, | 262 description=' ' + main.__doc__, |
260 formatter_class=argparse.RawTextHelpFormatter) | 263 formatter_class=argparse.RawTextHelpFormatter) |
261 AddOptionalArgs(argparser) | 264 AddOptionalArgs(argparser) |
262 argparser.add_argument('pexe', help='Finalized pexe to translate') | 265 argparser.add_argument('pexe', help='Finalized pexe to translate') |
263 args = argparser.parse_args() | 266 args = argparser.parse_args() |
264 pexe = args.pexe | 267 pexe = args.pexe |
265 exe = args.output | 268 exe = args.output |
| 269 if args.asan: |
| 270 if args.sandbox or args.nonsfi: |
| 271 print 'Can only use AddressSanitizer with a native build' |
| 272 exit(1) |
| 273 args.sz_args.append('-fsanitize-address') |
266 ProcessPexe(args, pexe, exe) | 274 ProcessPexe(args, pexe, exe) |
267 | 275 |
268 def ProcessPexe(args, pexe, exe): | 276 def ProcessPexe(args, pexe, exe): |
269 [pexe_base, ext] = os.path.splitext(pexe) | 277 [pexe_base, ext] = os.path.splitext(pexe) |
270 if ext != '.pexe': | 278 if ext != '.pexe': |
271 pexe_base = pexe | 279 pexe_base = pexe |
272 pexe_base_unescaped = pexe_base | 280 pexe_base_unescaped = pexe_base |
273 pexe_base = pipes.quote(pexe_base) | 281 pexe_base = pipes.quote(pexe_base) |
274 pexe = pipes.quote(pexe) | 282 pexe = pipes.quote(pexe) |
275 | 283 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 start=get_sfi_string(args, '_start', '_start', | 447 start=get_sfi_string(args, '_start', '_start', |
440 '_user_start')), | 448 '_user_start')), |
441 echo=args.verbose) | 449 echo=args.verbose) |
442 | 450 |
443 # Run the linker regardless of hybrid mode. | 451 # Run the linker regardless of hybrid mode. |
444 if args.sandbox: | 452 if args.sandbox: |
445 LinkSandbox([obj_partial], exe, args.target, args.verbose) | 453 LinkSandbox([obj_partial], exe, args.target, args.verbose) |
446 elif args.nonsfi: | 454 elif args.nonsfi: |
447 LinkNonsfi([obj_partial], exe, args.target, args.verbose) | 455 LinkNonsfi([obj_partial], exe, args.target, args.verbose) |
448 else: | 456 else: |
449 LinkNative([obj_partial], exe, args.target, args.verbose) | 457 objs = [obj_partial] |
| 458 if args.asan: |
| 459 objs.append( |
| 460 ('{root}/toolchain_build/src/subzero/build/runtime/' + |
| 461 'szrt_asan_{target}.o').format(root=nacl_root, |
| 462 target=args.target)) |
| 463 LinkNative(objs, exe, args.target, args.verbose) |
450 | 464 |
451 # Put the extra verbose printing at the end. | 465 # Put the extra verbose printing at the end. |
452 if args.verbose and hybrid: | 466 if args.verbose and hybrid: |
453 print 'include={regex}'.format(regex=re_include_str) | 467 print 'include={regex}'.format(regex=re_include_str) |
454 print 'exclude={regex}'.format(regex=re_exclude_str) | 468 print 'exclude={regex}'.format(regex=re_exclude_str) |
455 print 'default_match={dm}'.format(dm=default_match) | 469 print 'default_match={dm}'.format(dm=default_match) |
456 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) | 470 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) |
457 | 471 |
458 if __name__ == '__main__': | 472 if __name__ == '__main__': |
459 main() | 473 main() |
OLD | NEW |