| 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 shellcmd | 9 from utils import shellcmd |
| 10 from utils import FindBaseNaCl | 10 from utils import FindBaseNaCl |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 ' Default %(default)s.') | 82 ' Default %(default)s.') |
| 83 argparser.add_argument('--filetype', default='iasm', dest='filetype', | 83 argparser.add_argument('--filetype', default='iasm', dest='filetype', |
| 84 choices=['obj', 'asm', 'iasm'], | 84 choices=['obj', 'asm', 'iasm'], |
| 85 help='Output file type. Default %(default)s.') | 85 help='Output file type. Default %(default)s.') |
| 86 argparser.add_argument('--sandbox', dest='sandbox', action='store_true', | 86 argparser.add_argument('--sandbox', dest='sandbox', action='store_true', |
| 87 help='Enable sandboxing in the translator') | 87 help='Enable sandboxing in the translator') |
| 88 argparser.add_argument('--enable-block-profile', | 88 argparser.add_argument('--enable-block-profile', |
| 89 dest='enable_block_profile', action='store_true', | 89 dest='enable_block_profile', action='store_true', |
| 90 help='Enable basic block profiling.') | 90 help='Enable basic block profiling.') |
| 91 argparser.add_argument('--target', default='x8632', dest='target', | 91 argparser.add_argument('--target', default='x8632', dest='target', |
| 92 choices=['arm32', 'x8632'], | 92 choices=['arm32', 'x8632', 'x8664'], |
| 93 help='Generate code for specified target.') | 93 help='Generate code for specified target.') |
| 94 argparser.add_argument('--verbose', '-v', dest='verbose', | 94 argparser.add_argument('--verbose', '-v', dest='verbose', |
| 95 action='store_true', | 95 action='store_true', |
| 96 help='Display some extra debugging output') | 96 help='Display some extra debugging output') |
| 97 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], | 97 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], |
| 98 help='Extra arguments for Subzero') | 98 help='Extra arguments for Subzero') |
| 99 argparser.add_argument('--llc', dest='llc_args', action='append', | 99 argparser.add_argument('--llc', dest='llc_args', action='append', |
| 100 default=[], help='Extra arguments for llc') | 100 default=[], help='Extra arguments for llc') |
| 101 argparser.add_argument('--no-sz', dest='nosz', action='store_true', | 101 argparser.add_argument('--no-sz', dest='nosz', action='store_true', |
| 102 help='Run only post-Subzero build steps') | 102 help='Run only post-Subzero build steps') |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 opt_level = args.optlevel | 183 opt_level = args.optlevel |
| 184 opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' } | 184 opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' } |
| 185 hybrid = args.include or args.exclude | 185 hybrid = args.include or args.exclude |
| 186 | 186 |
| 187 if hybrid and (args.force or | 187 if hybrid and (args.force or |
| 188 NewerThanOrNotThere(pexe, obj_llc) or | 188 NewerThanOrNotThere(pexe, obj_llc) or |
| 189 NewerThanOrNotThere(llcbin, obj_llc)): | 189 NewerThanOrNotThere(llcbin, obj_llc)): |
| 190 arch = { | 190 arch = { |
| 191 'arm32': 'armv7' if args.sandbox else 'arm-nonsfi', | 191 'arm32': 'armv7' if args.sandbox else 'arm-nonsfi', |
| 192 'x8632': 'x86-32' if args.sandbox else 'x86-32-linux', | 192 'x8632': 'x86-32' if args.sandbox else 'x86-32-linux', |
| 193 'x8664': 'x86-64' if args.sandbox else 'x86-64-linux', |
| 193 }[args.target] | 194 }[args.target] |
| 194 | 195 |
| 195 # Only run pnacl-translate in hybrid mode. | 196 # Only run pnacl-translate in hybrid mode. |
| 196 shellcmd(['{base}/pnacl-translate'.format(base=path_addition), | 197 shellcmd(['{base}/pnacl-translate'.format(base=path_addition), |
| 197 '-split-module=1', | 198 '-split-module=1', |
| 198 '-ffunction-sections', | 199 '-ffunction-sections', |
| 199 '-fdata-sections', | 200 '-fdata-sections', |
| 200 '-c', | 201 '-c', |
| 201 '-arch', arch, | 202 '-arch', arch, |
| 202 '-O' + opt_level_map[opt_level], | 203 '-O' + opt_level_map[opt_level], |
| (...skipping 30 matching lines...) Expand all Loading... |
| 233 (['-enable-block-profile'] if | 234 (['-enable-block-profile'] if |
| 234 args.enable_block_profile and not args.sandbox | 235 args.enable_block_profile and not args.sandbox |
| 235 else []) + | 236 else []) + |
| 236 args.sz_args + | 237 args.sz_args + |
| 237 [pexe], | 238 [pexe], |
| 238 echo=args.verbose) | 239 echo=args.verbose) |
| 239 if args.filetype != 'obj': | 240 if args.filetype != 'obj': |
| 240 triple = { | 241 triple = { |
| 241 'arm32': 'arm-nacl' if args.sandbox else 'arm', | 242 'arm32': 'arm-nacl' if args.sandbox else 'arm', |
| 242 'x8632': 'i686-nacl' if args.sandbox else 'i686', | 243 'x8632': 'i686-nacl' if args.sandbox else 'i686', |
| 244 'x8664': 'x86_64-nacl' if args.sandbox else 'x86_64-linux-gnux32', |
| 243 }[args.target] | 245 }[args.target] |
| 244 | 246 |
| 245 shellcmd(( | 247 shellcmd(( |
| 246 '{base}/llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}' | 248 '{base}/llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}' |
| 247 ).format(base=path_addition, asm=asm_sz, obj=obj_sz, | 249 ).format(base=path_addition, asm=asm_sz, obj=obj_sz, |
| 248 triple=triple), | 250 triple=triple), |
| 249 echo=args.verbose) | 251 echo=args.verbose) |
| 250 if not args.sandbox: | 252 if not args.sandbox: |
| 251 shellcmd(( | 253 shellcmd(( |
| 252 '{objcopy} --redefine-sym _start=_user_start {obj}' | 254 '{objcopy} --redefine-sym _start=_user_start {obj}' |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 echo=args.verbose) | 290 echo=args.verbose) |
| 289 else: | 291 else: |
| 290 shellcmd(( | 292 shellcmd(( |
| 291 '{objcopy} {obj} {weak}' | 293 '{objcopy} {obj} {weak}' |
| 292 ).format(objcopy=objcopy, obj=obj_llc, weak=obj_llc_weak), | 294 ).format(objcopy=objcopy, obj=obj_llc, weak=obj_llc_weak), |
| 293 echo=args.verbose) | 295 echo=args.verbose) |
| 294 obj_partial = pexe_base + '.o' | 296 obj_partial = pexe_base + '.o' |
| 295 ld = { | 297 ld = { |
| 296 'arm32': 'arm-linux-gnueabihf-ld', | 298 'arm32': 'arm-linux-gnueabihf-ld', |
| 297 'x8632': 'ld', | 299 'x8632': 'ld', |
| 300 'x8664': 'ld', |
| 298 }[args.target] | 301 }[args.target] |
| 299 emulation = { | 302 emulation = { |
| 300 'arm32': 'armelf_linux_eabi', | 303 'arm32': 'armelf_linux_eabi', |
| 301 'x8632': 'elf_i386', | 304 'x8632': 'elf_i386', |
| 305 'x8664': 'elf32_x86_64', |
| 302 }[args.target] | 306 }[args.target] |
| 303 shellcmd(( | 307 shellcmd(( |
| 304 '{ld} -r -m {emulation} -o {partial} {sz} {llc}' | 308 '{ld} -r -m {emulation} -o {partial} {sz} {llc}' |
| 305 ).format(ld=ld, emulation=emulation, partial=obj_partial, | 309 ).format(ld=ld, emulation=emulation, partial=obj_partial, |
| 306 sz=obj_sz_weak, llc=obj_llc_weak), | 310 sz=obj_sz_weak, llc=obj_llc_weak), |
| 307 echo=args.verbose) | 311 echo=args.verbose) |
| 308 shellcmd(( | 312 shellcmd(( |
| 309 '{objcopy} -w --localize-symbol="*" {partial}' | 313 '{objcopy} -w --localize-symbol="*" {partial}' |
| 310 ).format(objcopy=objcopy, partial=obj_partial), | 314 ).format(objcopy=objcopy, partial=obj_partial), |
| 311 echo=args.verbose) | 315 echo=args.verbose) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 338 '--end-group {linklib}/crtend.o --undefined=_start ' + | 342 '--end-group {linklib}/crtend.o --undefined=_start ' + |
| 339 '--defsym=__Sz_AbsoluteZero=0 ' + | 343 '--defsym=__Sz_AbsoluteZero=0 ' + |
| 340 '-o {exe}' | 344 '-o {exe}' |
| 341 ).format(gold=gold, linklib=linklib, partial=obj_partial, exe=exe, | 345 ).format(gold=gold, linklib=linklib, partial=obj_partial, exe=exe, |
| 342 root=nacl_root, target=args.target), | 346 root=nacl_root, target=args.target), |
| 343 echo=args.verbose) | 347 echo=args.verbose) |
| 344 else: | 348 else: |
| 345 linker = { | 349 linker = { |
| 346 'arm32': '/usr/bin/arm-linux-gnueabihf-g++', | 350 'arm32': '/usr/bin/arm-linux-gnueabihf-g++', |
| 347 'x8632': ('{root}/../third_party/llvm-build/Release+Asserts/bin/clang' | 351 'x8632': ('{root}/../third_party/llvm-build/Release+Asserts/bin/clang' |
| 352 ).format(root=nacl_root), |
| 353 'x8664': ('{root}/../third_party/llvm-build/Release+Asserts/bin/clang' |
| 348 ).format(root=nacl_root) | 354 ).format(root=nacl_root) |
| 349 }[args.target] | 355 }[args.target] |
| 350 | 356 |
| 351 extra_linker_args = ' '.join({ | 357 extra_linker_args = ' '.join({ |
| 352 'arm32': ['-mcpu=cortex-a9'], | 358 'arm32': ['-mcpu=cortex-a9'], |
| 353 'x8632': ['-m32'] | 359 'x8632': ['-m32'], |
| 360 'x8664': ['-mx32'] |
| 354 }[args.target]) | 361 }[args.target]) |
| 355 | 362 |
| 356 lib_dir = { | 363 lib_dir = { |
| 357 'arm32': 'arm-linux', | 364 'arm32': 'arm-linux', |
| 358 'x8632': 'x86-32-linux', | 365 'x8632': 'x86-32-linux', |
| 366 'x8664': 'x86-64-linux', |
| 359 }[args.target] | 367 }[args.target] |
| 360 | 368 |
| 361 shellcmd(( | 369 shellcmd(( |
| 362 '{ld} {ld_extra_args} {partial} -o {exe} ' + | 370 '{ld} {ld_extra_args} {partial} -o {exe} ' + |
| 363 # Keep the rest of this command line (except szrt_native_x8632.o) in | 371 # Keep the rest of this command line (except szrt_native_x8632.o) in |
| 364 # sync with RunHostLD() in pnacl-translate.py. | 372 # sync with RunHostLD() in pnacl-translate.py. |
| 365 '{root}/toolchain/linux_x86/pnacl_newlib_raw/translator/' + | 373 '{root}/toolchain/linux_x86/pnacl_newlib_raw/translator/' + |
| 366 '{lib_dir}/lib/' + | 374 '{lib_dir}/lib/' + |
| 367 '{{unsandboxed_irt,irt_random,irt_query_list}}.o ' + | 375 '{{unsandboxed_irt,irt_random,irt_query_list}}.o ' + |
| 368 '{root}/toolchain_build/src/subzero/build/runtime/' + | 376 '{root}/toolchain_build/src/subzero/build/runtime/' + |
| 369 'szrt_native_{target}.o -lpthread -lrt ' + | 377 'szrt_native_{target}.o -lpthread -lrt ' + |
| 370 '-Wl,--defsym=__Sz_AbsoluteZero=0' | 378 '-Wl,--defsym=__Sz_AbsoluteZero=0' |
| 371 ).format(ld=linker, ld_extra_args=extra_linker_args, | 379 ).format(ld=linker, ld_extra_args=extra_linker_args, |
| 372 partial=obj_partial, exe=exe, root=nacl_root, | 380 partial=obj_partial, exe=exe, root=nacl_root, |
| 373 target=args.target, lib_dir=lib_dir), | 381 target=args.target, lib_dir=lib_dir), |
| 374 echo=args.verbose) | 382 echo=args.verbose) |
| 375 | 383 |
| 376 # Put the extra verbose printing at the end. | 384 # Put the extra verbose printing at the end. |
| 377 if args.verbose and hybrid: | 385 if args.verbose and hybrid: |
| 378 print 'include={regex}'.format(regex=re_include_str) | 386 print 'include={regex}'.format(regex=re_include_str) |
| 379 print 'exclude={regex}'.format(regex=re_exclude_str) | 387 print 'exclude={regex}'.format(regex=re_exclude_str) |
| 380 print 'default_match={dm}'.format(dm=default_match) | 388 print 'default_match={dm}'.format(dm=default_match) |
| 381 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) | 389 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) |
| 382 | 390 |
| 383 if __name__ == '__main__': | 391 if __name__ == '__main__': |
| 384 main() | 392 main() |
| OLD | NEW |