| OLD | NEW |
| 1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
| 2 | 2 |
| 3 import argparse | 3 import argparse |
| 4 from collections import namedtuple | |
| 5 import os | 4 import os |
| 6 import shutil | 5 import shutil |
| 7 import tempfile | 6 import tempfile |
| 7 |
| 8 import targets |
| 8 from utils import shellcmd | 9 from utils import shellcmd |
| 9 from utils import FindBaseNaCl | 10 from utils import FindBaseNaCl |
| 10 | 11 |
| 12 |
| 11 def Translate(ll_files, extra_args, obj, verbose): | 13 def Translate(ll_files, extra_args, obj, verbose): |
| 12 """Translate a set of input bitcode files into a single object file. | 14 """Translate a set of input bitcode files into a single object file. |
| 13 | 15 |
| 14 Use pnacl-llc to translate textual bitcode input ll_files into object file | 16 Use pnacl-llc to translate textual bitcode input ll_files into object file |
| 15 obj, using extra_args as the architectural flags. | 17 obj, using extra_args as the architectural flags. |
| 16 """ | 18 """ |
| 17 shellcmd(['cat'] + ll_files + ['|', | 19 shellcmd(['cat'] + ll_files + ['|', |
| 18 'pnacl-llc', | 20 'pnacl-llc', |
| 19 '-externalize', | 21 '-externalize', |
| 20 '-function-sections', | 22 '-function-sections', |
| 21 '-O2', | 23 '-O2', |
| 22 '-filetype=obj', | 24 '-filetype=obj', |
| 23 '-bitcode-format=llvm', | 25 '-bitcode-format=llvm', |
| 24 '-o', obj | 26 '-o', obj |
| 25 ] + extra_args, echo=verbose) | 27 ] + extra_args, echo=verbose) |
| 26 shellcmd(['le32-nacl-objcopy', | 28 shellcmd(['le32-nacl-objcopy', |
| 27 '--strip-symbol=nacl_tp_tdb_offset', | 29 '--strip-symbol=nacl_tp_tdb_offset', |
| 28 '--strip-symbol=nacl_tp_tls_offset', | 30 '--strip-symbol=nacl_tp_tls_offset', |
| 29 obj | 31 obj |
| 30 ], echo=verbose) | 32 ], echo=verbose) |
| 31 | 33 |
| 34 |
| 32 def PartialLink(obj_files, extra_args, lib, verbose): | 35 def PartialLink(obj_files, extra_args, lib, verbose): |
| 33 """Partially links a set of obj files into a final obj library.""" | 36 """Partially links a set of obj files into a final obj library.""" |
| 34 shellcmd(['le32-nacl-ld', | 37 shellcmd(['le32-nacl-ld', |
| 35 '-o', lib, | 38 '-o', lib, |
| 36 '-r', | 39 '-r', |
| 37 ] + extra_args + obj_files, echo=verbose) | 40 ] + extra_args + obj_files, echo=verbose) |
| 38 | 41 |
| 39 | 42 |
| 40 TargetInfo = namedtuple('TargetInfo', | |
| 41 ['target', 'triple', 'llc_flags', 'ld_emu']) | |
| 42 | |
| 43 | |
| 44 def MakeRuntimesForTarget(target_info, ll_files, | 43 def MakeRuntimesForTarget(target_info, ll_files, |
| 45 srcdir, tempdir, rtdir, verbose): | 44 srcdir, tempdir, rtdir, verbose): |
| 46 def TmpFile(template): | 45 def TmpFile(template): |
| 47 return template.format(dir=tempdir, target=target_info.target) | 46 return template.format(dir=tempdir, target=target_info.target) |
| 48 def OutFile(template): | 47 def OutFile(template): |
| 49 return template.format(rtdir=rtdir, target=target_info.target) | 48 return template.format(rtdir=rtdir, target=target_info.target) |
| 50 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to | 49 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to |
| 51 # szrt_native_{target}.tmp.o. | 50 # szrt_native_{target}.tmp.o. |
| 52 Translate(ll_files, | 51 Translate(ll_files, |
| 53 ['-mtriple=' + target_info.triple] + target_info.llc_flags, | 52 ['-mtriple=' + target_info.triple] + target_info.llc_flags, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 PartialLink([TmpFile('{dir}/szrt_native_{target}.tmp.o'), | 64 PartialLink([TmpFile('{dir}/szrt_native_{target}.tmp.o'), |
| 66 TmpFile('{dir}/szrt_profiler_native_{target}.o')], | 65 TmpFile('{dir}/szrt_profiler_native_{target}.o')], |
| 67 ['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], | 66 ['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], |
| 68 OutFile('{rtdir}/szrt_native_{target}.o'), | 67 OutFile('{rtdir}/szrt_native_{target}.o'), |
| 69 verbose) | 68 verbose) |
| 70 | 69 |
| 71 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_{target}.o | 70 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_{target}.o |
| 72 # The sandboxed library does not get the profiler helper function as the | 71 # The sandboxed library does not get the profiler helper function as the |
| 73 # binaries are linked with -nostdlib. | 72 # binaries are linked with -nostdlib. |
| 74 Translate(ll_files, | 73 Translate(ll_files, |
| 75 ['-mtriple=' + target_info.triple.replace('linux', 'nacl')] + | 74 ['-mtriple=' + targets.ConvertTripleToNaCl(target_info.triple)] + |
| 76 target_info.llc_flags, | 75 target_info.llc_flags, |
| 77 OutFile('{rtdir}/szrt_sb_{target}.o'), | 76 OutFile('{rtdir}/szrt_sb_{target}.o'), |
| 78 verbose) | 77 verbose) |
| 79 | 78 |
| 80 | 79 |
| 81 def main(): | 80 def main(): |
| 82 """Build the Subzero runtime support library for all architectures. | 81 """Build the Subzero runtime support library for all architectures. |
| 83 """ | 82 """ |
| 84 argparser = argparse.ArgumentParser( | 83 argparser = argparse.ArgumentParser( |
| 85 description=' ' + main.__doc__, | 84 description=' ' + main.__doc__, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 116 '-pnacl-abi-simplify-preopt', | 115 '-pnacl-abi-simplify-preopt', |
| 117 '-pnacl-abi-simplify-postopt', | 116 '-pnacl-abi-simplify-postopt', |
| 118 '-pnaclabi-allow-debug-metadata', | 117 '-pnaclabi-allow-debug-metadata', |
| 119 '{dir}/szrt.tmp.bc'.format(dir=tempdir), | 118 '{dir}/szrt.tmp.bc'.format(dir=tempdir), |
| 120 '-S', | 119 '-S', |
| 121 '-o', '{dir}/szrt.ll'.format(dir=tempdir) | 120 '-o', '{dir}/szrt.ll'.format(dir=tempdir) |
| 122 ], echo=args.verbose) | 121 ], echo=args.verbose) |
| 123 ll_files = ['{dir}/szrt.ll'.format(dir=tempdir), | 122 ll_files = ['{dir}/szrt.ll'.format(dir=tempdir), |
| 124 '{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)] | 123 '{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)] |
| 125 | 124 |
| 126 x8632_target = TargetInfo(target='x8632', | 125 MakeRuntimesForTarget(targets.X8632Target, ll_files, |
| 127 triple='i686-none-linux', | |
| 128 llc_flags=['-mcpu=pentium4m'], | |
| 129 ld_emu='elf_i386_nacl') | |
| 130 MakeRuntimesForTarget(x8632_target, ll_files, | |
| 131 srcdir, tempdir, rtdir, args.verbose) | 126 srcdir, tempdir, rtdir, args.verbose) |
| 132 arm32_target = TargetInfo(target='arm32', | 127 MakeRuntimesForTarget(targets.ARM32Target, ll_files, |
| 133 triple='armv7a-none-linux-gnueabihf', | |
| 134 llc_flags=['-mcpu=cortex-a9', | |
| 135 '-float-abi=hard', | |
| 136 '-mattr=+neon'], | |
| 137 ld_emu='armelf_nacl') | |
| 138 MakeRuntimesForTarget(arm32_target, ll_files, | |
| 139 srcdir, tempdir, rtdir, args.verbose) | 128 srcdir, tempdir, rtdir, args.verbose) |
| 140 | 129 |
| 141 finally: | 130 finally: |
| 142 try: | 131 try: |
| 143 shutil.rmtree(tempdir) | 132 shutil.rmtree(tempdir) |
| 144 except OSError as exc: | 133 except OSError as exc: |
| 145 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory | 134 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory |
| 146 raise # re-raise exception | 135 raise # re-raise exception |
| 147 | 136 |
| 148 if __name__ == '__main__': | 137 if __name__ == '__main__': |
| 149 main() | 138 main() |
| OLD | NEW |