Index: pydir/build-runtime.py |
diff --git a/pydir/build-runtime.py b/pydir/build-runtime.py |
index ad38a2ed62757fb67fcd610753e6350b3b8bda8e..c735e85f96da4a368c5730b7998663a55f147bb7 100755 |
--- a/pydir/build-runtime.py |
+++ b/pydir/build-runtime.py |
@@ -11,63 +11,71 @@ from utils import FindBaseNaCl |
def Translate(ll_files, extra_args, obj, verbose): |
- """Translate a set of input bitcode files into a single object file. |
+ """Translate a set of input bitcode files into a single object file. |
- Use pnacl-llc to translate textual bitcode input ll_files into object file |
- obj, using extra_args as the architectural flags. |
- """ |
- shellcmd(['cat'] + ll_files + ['|', |
- 'pnacl-llc', |
- '-externalize', |
- '-function-sections', |
- '-O2', |
- '-filetype=obj', |
- '-bitcode-format=llvm', |
- '-o', obj |
- ] + extra_args, echo=verbose) |
- shellcmd(['le32-nacl-objcopy', |
- '--strip-symbol=nacl_tp_tdb_offset', |
- '--strip-symbol=nacl_tp_tls_offset', |
- obj |
- ], echo=verbose) |
+ Use pnacl-llc to translate textual bitcode input ll_files into object file |
+ obj, using extra_args as the architectural flags. |
+ """ |
+ shellcmd(['cat'] + ll_files + ['|', |
+ 'pnacl-llc', |
+ '-externalize', |
+ '-function-sections', |
+ '-O2', |
+ '-filetype=obj', |
+ '-bitcode-format=llvm', |
+ '-o', obj |
+ ] + extra_args, echo=verbose) |
+ shellcmd(['le32-nacl-objcopy', |
+ '--strip-symbol=nacl_tp_tdb_offset', |
+ '--strip-symbol=nacl_tp_tls_offset', |
+ obj |
+ ], echo=verbose) |
def PartialLink(obj_files, extra_args, lib, verbose): |
- """Partially links a set of obj files into a final obj library.""" |
- shellcmd(['le32-nacl-ld', |
- '-o', lib, |
- '-r', |
- ] + extra_args + obj_files, echo=verbose) |
+ """Partially links a set of obj files into a final obj library.""" |
+ shellcmd(['le32-nacl-ld', |
+ '-o', lib, |
+ '-r', |
+ ] + extra_args + obj_files, echo=verbose) |
def MakeRuntimesForTarget(target_info, ll_files, |
srcdir, tempdir, rtdir, verbose): |
- def TmpFile(template): |
- return template.format(dir=tempdir, target=target_info.target) |
- def OutFile(template): |
- return template.format(rtdir=rtdir, target=target_info.target) |
+ """Builds native, sandboxed, and nonsfi runtimes for the given target.""" |
+ # File-mangling helper functions. |
+ def TmpFile(template): |
+ return template.format(dir=tempdir, target=target_info.target) |
+ def OutFile(template): |
+ return template.format(rtdir=rtdir, target=target_info.target) |
+ # Helper function for building the native unsandboxed runtime. |
+ def MakeNativeRuntime(): |
+ """Builds just the native runtime.""" |
# Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to |
# szrt_native_{target}.tmp.o. |
Translate(ll_files, |
['-mtriple=' + target_info.triple] + target_info.llc_flags, |
TmpFile('{dir}/szrt_native_{target}.tmp.o'), |
verbose) |
- # Compile srcdir/szrt_profiler.c to tempdir/szrt_profiler_native_{target}.o |
+ # Compile srcdir/szrt_profiler.c to |
+ # tempdir/szrt_profiler_native_{target}.o. |
shellcmd(['clang', |
'-O2', |
'-target=' + target_info.triple, |
'-c', |
'{srcdir}/szrt_profiler.c'.format(srcdir=srcdir), |
'-o', TmpFile('{dir}/szrt_profiler_native_{target}.o') |
- ], echo=verbose) |
- # Writing full szrt_native_{target}.o. |
+ ], echo=verbose) |
+ # Write full szrt_native_{target}.o. |
PartialLink([TmpFile('{dir}/szrt_native_{target}.tmp.o'), |
TmpFile('{dir}/szrt_profiler_native_{target}.o')], |
['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], |
OutFile('{rtdir}/szrt_native_{target}.o'), |
verbose) |
- |
- # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_{target}.o |
+ # Helper function for building the sandboxed runtime. |
+ def MakeSandboxedRuntime(): |
+ """Builds just the sandboxed runtime.""" |
+ # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_{target}.o. |
# The sandboxed library does not get the profiler helper function as the |
# binaries are linked with -nostdlib. |
Translate(ll_files, |
@@ -75,11 +83,41 @@ def MakeRuntimesForTarget(target_info, ll_files, |
target_info.llc_flags, |
OutFile('{rtdir}/szrt_sb_{target}.o'), |
verbose) |
+ # Helper function for building the Non-SFI runtime. |
+ def MakeNonsfiRuntime(): |
+ """Builds just the nonsfi runtime.""" |
+ # Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to |
+ # szrt_nonsfi_{target}.tmp.o. |
+ Translate(ll_files, |
+ ['-mtriple=' + target_info.triple] + target_info.llc_flags + |
+ ['-relocation-model=pic', '-force-tls-non-pic', '-malign-double'], |
+ TmpFile('{dir}/szrt_nonsfi_{target}.tmp.o'), |
+ verbose) |
+ # Assemble srcdir/szrt_asm_{target}.s to tempdir/szrt_asm_{target}.o. |
+ shellcmd(['llvm-mc', |
+ '-triple=' + target_info.triple, |
+ '-filetype=obj', |
+ '-o', TmpFile('{dir}/szrt_asm_{target}.o'), |
+ '{srcdir}/szrt_asm_{target}.s'.format( |
+ srcdir=srcdir, target=target_info.target) |
+ ], echo=verbose) |
+ # Write full szrt_nonsfi_{target}.o. |
+ PartialLink([TmpFile('{dir}/szrt_nonsfi_{target}.tmp.o'), |
+ TmpFile('{dir}/szrt_asm_{target}.o')], |
+ ['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)], |
+ OutFile('{rtdir}/szrt_nonsfi_{target}.o'), |
+ verbose) |
+ |
+ # Run the helper functions. |
+ MakeNativeRuntime() |
+ MakeSandboxedRuntime() |
+ MakeNonsfiRuntime() |
def main(): |
"""Build the Subzero runtime support library for all architectures. |
""" |
+ nacl_root = FindBaseNaCl() |
argparser = argparse.ArgumentParser( |
description=' ' + main.__doc__, |
formatter_class=argparse.RawTextHelpFormatter) |
@@ -87,9 +125,11 @@ def main(): |
action='store_true', |
help='Display some extra debugging output') |
argparser.add_argument('--pnacl-root', dest='pnacl_root', |
+ default=( |
+ '{root}/toolchain/linux_x86/pnacl_newlib_raw' |
+ ).format(root=nacl_root), |
help='Path to PNaCl toolchain binaries.') |
args = argparser.parse_args() |
- nacl_root = FindBaseNaCl() |
os.environ['PATH'] = ('{root}/bin{sep}{path}' |
).format(root=args.pnacl_root, sep=os.pathsep, path=os.environ['PATH']) |
srcdir = ( |