Commit 0fb613f8 by Jim Stichnoth

Subzero: Make the szbuild.py script more automatic.

One wants to omit the --init option to make things go faster, but then there's the risk that the pexe or llvm2ice or llc has changed and --init is actually necessary. This change automatically compares the modification timestamps of the pexe and the llvm2ice and llc binaries against the modification timestamps of the object files to determine whether re-translation is needed. The --init option forces re-translation regardless of timestamps. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/551373008
parent 2e8bfbb9
...@@ -9,6 +9,15 @@ import sys ...@@ -9,6 +9,15 @@ import sys
from utils import shellcmd from utils import shellcmd
from utils import FindBaseNaCl from utils import FindBaseNaCl
def NewerThanOrNotThere(old_path, new_path):
"""Returns whether old_path is newer than new_path.
Also returns true if either path doesn't exist.
"""
if not (os.path.exists(old_path) and os.path.exists(new_path)):
return True
return os.path.getmtime(old_path) > os.path.getmtime(new_path)
def BuildRegex(patterns, syms): def BuildRegex(patterns, syms):
"""Build a regular expression string for inclusion or exclusion. """Build a regular expression string for inclusion or exclusion.
...@@ -79,14 +88,14 @@ def main(): ...@@ -79,14 +88,14 @@ def main():
notation, so e.g. use '0:10' or ':10' for the first 10 lines of notation, so e.g. use '0:10' or ':10' for the first 10 lines of
the file, or '1' for the second line of the file. the file, or '1' for the second line of the file.
The --init argument does first-time initialization for the pexe, This script uses file modification timestamps to determine whether
including creation of the Subzero symbol file that is implicitly llc and Subzero re-translation are needed. It checks timestamps
used in the --include and --exclude arguments. It can be removed of llc, llvm2ice, and the pexe against the translated object files
from the command line for subsequent executions if the pexe to determine the minimal work necessary. The --force option
doesn't change. suppresses those checks and re-translates everything.
This scripts augments PATH so that various PNaCl and LLVM tools This script augments PATH so that various PNaCl and LLVM tools can
can be run. These extra paths are within the native_client tree. be run. These extra paths are within the native_client tree.
When changes are made to these tools, copy them this way: When changes are made to these tools, copy them this way:
cd native_client cd native_client
toolchain_build/toolchain_build_pnacl.py llvm_i686_linux \\ toolchain_build/toolchain_build_pnacl.py llvm_i686_linux \\
...@@ -96,8 +105,8 @@ def main(): ...@@ -96,8 +105,8 @@ def main():
description=' ' + main.__doc__, description=' ' + main.__doc__,
formatter_class=argparse.RawTextHelpFormatter) formatter_class=argparse.RawTextHelpFormatter)
argparser.add_argument('pexe', help='Finalized pexe to translate') argparser.add_argument('pexe', help='Finalized pexe to translate')
argparser.add_argument('--init', dest='init', action='store_true', argparser.add_argument('--force', dest='force', action='store_true',
help='Perform first-time setup for the pexe') help='Force all re-translations of the pexe')
argparser.add_argument('--include', '-i', default=[], dest='include', argparser.add_argument('--include', '-i', default=[], dest='include',
action='append', action='append',
help='Subzero symbols to include ' + help='Subzero symbols to include ' +
...@@ -145,9 +154,16 @@ def main(): ...@@ -145,9 +154,16 @@ def main():
sym_sz_unescaped = pexe_base_unescaped + '.sym.sz.txt' sym_sz_unescaped = pexe_base_unescaped + '.sym.sz.txt'
whitelist_sz = pexe_base + '.wl.sz.txt' whitelist_sz = pexe_base + '.wl.sz.txt'
whitelist_sz_unescaped = pexe_base_unescaped + '.wl.sz.txt' whitelist_sz_unescaped = pexe_base_unescaped + '.wl.sz.txt'
llvm2ice = (
if args.init: '{root}/toolchain_build/src/subzero/llvm2ice'
).format(root=nacl_root)
llcbin = (
'{root}/toolchain/linux_x86/pnacl_newlib/host_x86_32/bin/llc'
).format(root=nacl_root)
opt_level = args.optlevel opt_level = args.optlevel
if args.force or NewerThanOrNotThere(pexe, obj_llc) or \
NewerThanOrNotThere(llcbin, obj_llc):
opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' } opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' }
shellcmd(( shellcmd((
'pnacl-translate -ffunction-sections -c -arch x86-32-linux ' + 'pnacl-translate -ffunction-sections -c -arch x86-32-linux ' +
...@@ -159,10 +175,14 @@ def main(): ...@@ -159,10 +175,14 @@ def main():
'objcopy --redefine-sym _start=_user_start {obj}' 'objcopy --redefine-sym _start=_user_start {obj}'
).format(obj=obj_llc), echo=args.verbose) ).format(obj=obj_llc), echo=args.verbose)
shellcmd(( shellcmd((
'{root}/toolchain_build/src/subzero/llvm2ice ' + 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
'-O{level} -bitcode-format=pnacl -disable-globals ' + ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose)
if args.force or NewerThanOrNotThere(pexe, obj_sz) or \
NewerThanOrNotThere(llvm2ice, obj_sz):
shellcmd((
'{l2i} -O{level} -bitcode-format=pnacl -disable-globals ' +
'-externalize -ffunction-sections {pexe} -o {asm}' '-externalize -ffunction-sections {pexe} -o {asm}'
).format(root=nacl_root,level=opt_level, pexe=pexe, asm=asm_sz), ).format(l2i=llvm2ice, level=opt_level, pexe=pexe, asm=asm_sz),
echo=args.verbose) echo=args.verbose)
shellcmd(( shellcmd((
'llvm-mc -arch=x86 -x86-asm-syntax=intel -filetype=obj -o {obj} ' + 'llvm-mc -arch=x86 -x86-asm-syntax=intel -filetype=obj -o {obj} ' +
...@@ -174,9 +194,6 @@ def main(): ...@@ -174,9 +194,6 @@ def main():
shellcmd(( shellcmd((
'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
).format(obj=obj_sz, sym=sym_sz), echo=args.verbose) ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose)
shellcmd((
'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
).format(obj=obj_llc, sym=sym_llc), echo=args.verbose)
with open(sym_sz_unescaped) as f: with open(sym_sz_unescaped) as f:
sz_syms = f.read().splitlines() sz_syms = f.read().splitlines()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment