Chromium Code Reviews| 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 shutil | 5 import shutil |
| 6 import tempfile | 6 import tempfile |
| 7 from utils import shellcmd | 7 from utils import shellcmd |
| 8 from utils import FindBaseNaCl | 8 from utils import FindBaseNaCl |
| 9 | 9 |
| 10 def Translate(ll_files, extra_args, obj, verbose): | 10 def Translate(ll_files, extra_args, obj, verbose): |
| 11 """Translate a set of input bitcode files into a single object file. | 11 """Translate a set of input bitcode files into a single object file. |
| 12 | 12 |
| 13 Use pnacl-llc to translate textual bitcode input ll_files into object file | 13 Use pnacl-llc to translate textual bitcode input ll_files into object file |
| 14 obj, using extra_args as the architectural flags. | 14 obj, using extra_args as the architectural flags. |
| 15 """ | 15 """ |
| 16 shellcmd(['cat'] + ll_files + ['|', | 16 shellcmd(['cat'] + ll_files + ['|', |
| 17 'pnacl-llc', | 17 'pnacl-llc', |
| 18 '-externalize', | 18 '-externalize', |
| 19 '-function-sections', | 19 '-function-sections', |
| 20 '-O2', | 20 '-O2', |
| 21 '-filetype=obj', | 21 '-filetype=obj', |
| 22 '-bitcode-format=llvm', | 22 '-bitcode-format=llvm', |
| 23 '-o', obj | 23 '-o', obj |
| 24 ] + extra_args, echo=verbose) | 24 ] + extra_args, echo=verbose) |
| 25 shellcmd(['objcopy', | 25 shellcmd(['objcopy', |
| 26 '--localize-symbol=nacl_tp_tdb_offset', | 26 '--strip-symbol=nacl_tp_tdb_offset', |
|
Jim Stichnoth
2015/06/08 23:45:30
cool :)
| |
| 27 '--localize-symbol=nacl_tp_tls_offset', | 27 '--strip-symbol=nacl_tp_tls_offset', |
| 28 obj | 28 obj |
| 29 ], echo=verbose) | 29 ], echo=verbose) |
| 30 | 30 |
| 31 def PartialLink(obj_files, extra_args, lib, verbose): | |
| 32 """Partially links a set of obj files into a final obj library.""" | |
| 33 shellcmd(['ld', | |
| 34 '-o', lib, | |
| 35 '-r', | |
| 36 ] + extra_args + obj_files, echo=verbose) | |
| 37 | |
| 31 def main(): | 38 def main(): |
| 32 """Build the Subzero runtime support library for all architectures. | 39 """Build the Subzero runtime support library for all architectures. |
| 33 """ | 40 """ |
| 34 argparser = argparse.ArgumentParser( | 41 argparser = argparse.ArgumentParser( |
| 35 description=' ' + main.__doc__, | 42 description=' ' + main.__doc__, |
| 36 formatter_class=argparse.RawTextHelpFormatter) | 43 formatter_class=argparse.RawTextHelpFormatter) |
| 37 argparser.add_argument('--verbose', '-v', dest='verbose', | 44 argparser.add_argument('--verbose', '-v', dest='verbose', |
| 38 action='store_true', | 45 action='store_true', |
| 39 help='Display some extra debugging output') | 46 help='Display some extra debugging output') |
| 40 argparser.add_argument('--pnacl-root', dest='pnacl_root', | 47 argparser.add_argument('--pnacl-root', dest='pnacl_root', |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 65 shellcmd(['pnacl-opt', | 72 shellcmd(['pnacl-opt', |
| 66 '-pnacl-abi-simplify-preopt', | 73 '-pnacl-abi-simplify-preopt', |
| 67 '-pnacl-abi-simplify-postopt', | 74 '-pnacl-abi-simplify-postopt', |
| 68 '-pnaclabi-allow-debug-metadata', | 75 '-pnaclabi-allow-debug-metadata', |
| 69 '{dir}/szrt.tmp.bc'.format(dir=tempdir), | 76 '{dir}/szrt.tmp.bc'.format(dir=tempdir), |
| 70 '-S', | 77 '-S', |
| 71 '-o', '{dir}/szrt.ll'.format(dir=tempdir) | 78 '-o', '{dir}/szrt.ll'.format(dir=tempdir) |
| 72 ], echo=args.verbose) | 79 ], echo=args.verbose) |
| 73 ll_files = ['{dir}/szrt.ll'.format(dir=tempdir), | 80 ll_files = ['{dir}/szrt.ll'.format(dir=tempdir), |
| 74 '{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)] | 81 '{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)] |
| 75 # Translate tempdir/szrt.ll and srcdir/szrt_ll.ll to szrt_native_x8632.o | 82 |
| 83 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_native_x8632. tmp.o | |
|
Jim Stichnoth
2015/06/08 23:45:30
80-col, here and below
John
2015/06/09 15:36:17
Done.
| |
| 76 Translate(ll_files, | 84 Translate(ll_files, |
| 77 ['-mtriple=i686', '-mcpu=pentium4m'], | 85 ['-mtriple=i686', '-mcpu=pentium4m'], |
| 78 '{rtdir}/szrt_native_x8632.o'.format(rtdir=rtdir), | 86 '{dir}/szrt_native_x8632.tmp.o'.format(dir=tempdir), |
| 79 args.verbose) | 87 args.verbose) |
| 80 # Translate tempdir/szrt.ll and srcdir/szrt_ll.ll to szrt_sb_x8632.o | 88 # Compile srcdir/szrt_profiler.c to tempdir/szrt_profiler_native_i686.o |
| 89 shellcmd(['clang', | |
| 90 '-O2', | |
| 91 '-target=i686', | |
| 92 '-c', | |
| 93 '{srcdir}/szrt_profiler.c'.format(srcdir=srcdir), | |
| 94 '-o', '{dir}/szrt_profiler_native_x8632.o'.format(dir=tempdir) | |
| 95 ], echo=args.verbose) | |
| 96 # Writing full szrt_native_i686.o. | |
| 97 PartialLink(['{dir}/szrt_native_x8632.tmp.o'.format(dir=tempdir), | |
| 98 '{dir}/szrt_profiler_native_x8632.o'.format(dir=tempdir) | |
| 99 ], ['-m elf_i386'], '{rtdir}/szrt_native_x8632.o'.format(rtdir=rtdir ), args.verbose) | |
| 100 | |
| 101 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_x8632.o | |
| 102 # The sandboxed library does not get the profiler helper function as the binaries are | |
| 103 # linked with -nostdlib. | |
| 81 Translate(ll_files, | 104 Translate(ll_files, |
| 82 ['-mtriple=i686-nacl', '-mcpu=pentium4m'], | 105 ['-mtriple=i686-nacl', '-mcpu=pentium4m'], |
| 83 '{rtdir}/szrt_sb_x8632.o'.format(rtdir=rtdir), | 106 '{rtdir}/szrt_sb_x8632.o'.format(rtdir=rtdir), |
| 84 args.verbose) | 107 args.verbose) |
| 85 finally: | 108 finally: |
| 86 try: | 109 try: |
| 87 shutil.rmtree(tempdir) | 110 shutil.rmtree(tempdir) |
| 88 except OSError as exc: | 111 except OSError as exc: |
| 89 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory | 112 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory |
| 90 raise # re-raise exception | 113 raise # re-raise exception |
| 91 | 114 |
| 92 if __name__ == '__main__': | 115 if __name__ == '__main__': |
| 93 main() | 116 main() |
| OLD | NEW |