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 | 7 |
| 8 import targets | 8 import targets |
| 9 from utils import shellcmd | 9 from utils import shellcmd |
| 10 from utils import FindBaseNaCl | 10 from utils import FindBaseNaCl |
| 11 | 11 |
| 12 | 12 |
| 13 def Translate(ll_files, extra_args, obj, verbose): | 13 def Translate(ll_files, extra_args, obj, verbose): |
| 14 """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. |
| 15 | 15 |
| 16 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 |
| 17 obj, using extra_args as the architectural flags. | 17 obj, using extra_args as the architectural flags. |
| 18 """ | 18 """ |
| 19 shellcmd(['cat'] + ll_files + ['|', | 19 shellcmd(['cat'] + ll_files + ['|', |
| 20 'pnacl-llc', | 20 'pnacl-llc', |
| 21 '-externalize', | 21 '-externalize', |
| 22 '-function-sections', | 22 '-function-sections', |
| 23 '-O2', | 23 '-O2', |
| 24 '-filetype=obj', | 24 '-filetype=obj', |
| 25 '-bitcode-format=llvm', | 25 '-bitcode-format=llvm', |
| 26 '-o', obj | 26 '-o', obj |
| 27 ] + extra_args, echo=verbose) | 27 ] + extra_args, echo=verbose) |
| 28 shellcmd(['le32-nacl-objcopy', | 28 shellcmd(['le32-nacl-objcopy', |
| 29 '--strip-symbol=nacl_tp_tdb_offset', | 29 '--strip-symbol=nacl_tp_tdb_offset', |
| 30 '--strip-symbol=nacl_tp_tls_offset', | 30 '--strip-symbol=nacl_tp_tls_offset', |
| 31 obj | 31 obj |
| 32 ], echo=verbose) | 32 ], echo=verbose) |
| 33 | 33 |
| 34 | 34 |
| 35 def PartialLink(obj_files, extra_args, lib, verbose): | 35 def PartialLink(obj_files, extra_args, lib, verbose): |
| 36 """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.""" |
| 37 shellcmd(['le32-nacl-ld', | 37 shellcmd(['le32-nacl-ld', |
| 38 '-o', lib, | 38 '-o', lib, |
| 39 '-r', | 39 '-r', |
| 40 ] + extra_args + obj_files, echo=verbose) | 40 ] + extra_args + obj_files, echo=verbose) |
| 41 | 41 |
| 42 | 42 |
| 43 def MakeRuntimesForTarget(target_info, ll_files, | 43 def MakeRuntimesForTarget(target_info, ll_files, |
|
John
2015/12/22 15:44:38
This method is becoming too long. How about defini
Jim Stichnoth
2015/12/28 07:54:07
OK. Split into 3 methods, for native, sandboxed,
| |
| 44 srcdir, tempdir, rtdir, verbose): | 44 srcdir, tempdir, rtdir, verbose): |
| 45 def TmpFile(template): | 45 def TmpFile(template): |
| 46 return template.format(dir=tempdir, target=target_info.target) | 46 return template.format(dir=tempdir, target=target_info.target) |
| 47 def OutFile(template): | 47 def OutFile(template): |
| 48 return template.format(rtdir=rtdir, target=target_info.target) | 48 return template.format(rtdir=rtdir, target=target_info.target) |
| 49 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to | 49 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to |
| 50 # szrt_native_{target}.tmp.o. | 50 # szrt_native_{target}.tmp.o. |
| 51 Translate(ll_files, | 51 Translate(ll_files, |
| 52 ['-mtriple=' + target_info.triple] + target_info.llc_flags, | 52 ['-mtriple=' + target_info.triple] + target_info.llc_flags, |
| 53 TmpFile('{dir}/szrt_native_{target}.tmp.o'), | 53 TmpFile('{dir}/szrt_native_{target}.tmp.o'), |
| 54 verbose) | 54 verbose) |
| 55 # Compile srcdir/szrt_profiler.c to tempdir/szrt_profiler_native_{target}.o | 55 # Compile srcdir/szrt_profiler.c to tempdir/szrt_profiler_native_{target}.o. |
| 56 shellcmd(['clang', | 56 shellcmd(['clang', |
| 57 '-O2', | 57 '-O2', |
| 58 '-target=' + target_info.triple, | 58 '-target=' + target_info.triple, |
| 59 '-c', | 59 '-c', |
| 60 '{srcdir}/szrt_profiler.c'.format(srcdir=srcdir), | 60 '{srcdir}/szrt_profiler.c'.format(srcdir=srcdir), |
| 61 '-o', TmpFile('{dir}/szrt_profiler_native_{target}.o') | 61 '-o', TmpFile('{dir}/szrt_profiler_native_{target}.o') |
| 62 ], echo=verbose) | 62 ], echo=verbose) |
| 63 # Writing full szrt_native_{target}.o. | 63 # Write full szrt_native_{target}.o. |
| 64 PartialLink([TmpFile('{dir}/szrt_native_{target}.tmp.o'), | 64 PartialLink([TmpFile('{dir}/szrt_native_{target}.tmp.o'), |
| 65 TmpFile('{dir}/szrt_profiler_native_{target}.o')], | 65 TmpFile('{dir}/szrt_profiler_native_{target}.o')], |
| 66 ['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], | 66 ['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], |
| 67 OutFile('{rtdir}/szrt_native_{target}.o'), | 67 OutFile('{rtdir}/szrt_native_{target}.o'), |
| 68 verbose) | 68 verbose) |
| 69 | 69 |
| 70 # 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 |
| 71 # 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 |
| 72 # binaries are linked with -nostdlib. | 72 # binaries are linked with -nostdlib. |
| 73 Translate(ll_files, | 73 Translate(ll_files, |
| 74 ['-mtriple=' + targets.ConvertTripleToNaCl(target_info.triple)] + | 74 ['-mtriple=' + targets.ConvertTripleToNaCl(target_info.triple)] + |
| 75 target_info.llc_flags, | 75 target_info.llc_flags, |
| 76 OutFile('{rtdir}/szrt_sb_{target}.o'), | 76 OutFile('{rtdir}/szrt_sb_{target}.o'), |
| 77 verbose) | 77 verbose) |
| 78 | 78 |
| 79 # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to | |
| 80 # szrt_nonsfi_{target}.tmp.o. | |
| 81 Translate(ll_files, | |
| 82 ['-mtriple=' + target_info.triple] + target_info.llc_flags + | |
| 83 ['-relocation-model=pic', '-force-tls-non-pic', '-malign-double'], | |
| 84 TmpFile('{dir}/szrt_nonsfi_{target}.tmp.o'), | |
| 85 verbose) | |
| 86 # Assemble srcdir/szrt_asm_{target}.s to tempdir/szrt_asm_{target}.o. | |
| 87 shellcmd(['llvm-mc', | |
| 88 '-triple=' + target_info.triple, | |
| 89 '-filetype=obj', | |
| 90 '-o', TmpFile('{dir}/szrt_asm_{target}.o'), | |
| 91 '{srcdir}/szrt_asm_{target}.s'.format( | |
| 92 srcdir=srcdir, target=target_info.target) | |
| 93 ], echo=verbose) | |
| 94 # Write full szrt_nonsfi_{target}.o. | |
| 95 PartialLink([TmpFile('{dir}/szrt_nonsfi_{target}.tmp.o'), | |
| 96 TmpFile('{dir}/szrt_asm_{target}.o')], | |
| 97 ['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], | |
| 98 OutFile('{rtdir}/szrt_nonsfi_{target}.o'), | |
| 99 verbose) | |
| 100 | |
| 79 | 101 |
| 80 def main(): | 102 def main(): |
| 81 """Build the Subzero runtime support library for all architectures. | 103 """Build the Subzero runtime support library for all architectures. |
| 82 """ | 104 """ |
| 83 argparser = argparse.ArgumentParser( | 105 argparser = argparse.ArgumentParser( |
| 84 description=' ' + main.__doc__, | 106 description=' ' + main.__doc__, |
| 85 formatter_class=argparse.RawTextHelpFormatter) | 107 formatter_class=argparse.RawTextHelpFormatter) |
| 86 argparser.add_argument('--verbose', '-v', dest='verbose', | 108 argparser.add_argument('--verbose', '-v', dest='verbose', |
| 87 action='store_true', | 109 action='store_true', |
| 88 help='Display some extra debugging output') | 110 help='Display some extra debugging output') |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 153 |
| 132 finally: | 154 finally: |
| 133 try: | 155 try: |
| 134 shutil.rmtree(tempdir) | 156 shutil.rmtree(tempdir) |
| 135 except OSError as exc: | 157 except OSError as exc: |
| 136 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory | 158 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory |
| 137 raise # re-raise exception | 159 raise # re-raise exception |
| 138 | 160 |
| 139 if __name__ == '__main__': | 161 if __name__ == '__main__': |
| 140 main() | 162 main() |
| OLD | NEW |