Commit 16178a14 by Jim Stichnoth

Subzero: Remove the need for a separate NaCl SDK installation.

Now it assumes tests are being run from within the Subzero portion of the native_client tree, and sets up PATH to find PNaCl tools relative to there. It may be necessary to do a one-time setup to be able to build pexes: pnacl/build.sh sdk newlib or the equivalent scons commands. If the tool chain is updated, propagate the changes via: toolchain_build/toolchain_build_pnacl.py llvm_i686_linux --install=toolchain/linux_x86/pnacl_newlib BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/525603002
parent c0fdc27c
...@@ -90,7 +90,7 @@ check-lit: llvm2ice ...@@ -90,7 +90,7 @@ check-lit: llvm2ice
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
check: check-lit check: check-lit
(cd crosstest; LLVM_BIN_PATH=$(LLVM_BIN_PATH) ./runtests.sh) (cd crosstest; ./runtests.sh)
# TODO: Fix the use of wildcards. # TODO: Fix the use of wildcards.
# Assumes clang-format is within $PATH. # Assumes clang-format is within $PATH.
......
...@@ -9,6 +9,7 @@ import tempfile ...@@ -9,6 +9,7 @@ import tempfile
sys.path.insert(0, '../pydir') sys.path.insert(0, '../pydir')
from utils import shellcmd from utils import shellcmd
from utils import FindBaseNaCl
if __name__ == '__main__': if __name__ == '__main__':
"""Builds a cross-test binary that allows functions translated by """Builds a cross-test binary that allows functions translated by
...@@ -55,11 +56,6 @@ if __name__ == '__main__': ...@@ -55,11 +56,6 @@ if __name__ == '__main__':
argparser.add_argument('--dir', required=False, default='.', argparser.add_argument('--dir', required=False, default='.',
metavar='OUTPUT_DIR', metavar='OUTPUT_DIR',
help='Output directory for all files') help='Output directory for all files')
argparser.add_argument('--llvm-bin-path', required=False,
default=os.environ.get('LLVM_BIN_PATH'),
metavar='PATH',
help='Path to LLVM executables like llc ' +
'(defaults to $LLVM_BIN_PATH)')
argparser.add_argument('--crosstest-bitcode', required=False, argparser.add_argument('--crosstest-bitcode', required=False,
default=1, type=int, default=1, type=int,
help='Compile non-subzero crosstest object file ' + help='Compile non-subzero crosstest object file ' +
...@@ -67,10 +63,15 @@ if __name__ == '__main__': ...@@ -67,10 +63,15 @@ if __name__ == '__main__':
'If 0, then compile it straight from source.') 'If 0, then compile it straight from source.')
args = argparser.parse_args() args = argparser.parse_args()
nacl_root = FindBaseNaCl()
# Prepend host_x86_32/bin to $PATH.
os.environ['PATH'] = nacl_root + \
'/toolchain/linux_x86/pnacl_newlib/host_x86_32/bin' + \
os.pathsep + os.environ['PATH']
objs = [] objs = []
remove_internal = re.compile('^define internal ') remove_internal = re.compile('^define internal ')
fix_target = re.compile('le32-unknown-nacl') fix_target = re.compile('le32-unknown-nacl')
llvm_bin_path = args.llvm_bin_path
for arg in args.test: for arg in args.test:
base, ext = os.path.splitext(arg) base, ext = os.path.splitext(arg)
if ext == '.ll': if ext == '.ll':
...@@ -101,7 +102,7 @@ if __name__ == '__main__': ...@@ -101,7 +102,7 @@ if __name__ == '__main__':
'--prefix=' + args.prefix, '--prefix=' + args.prefix,
'-o=' + asm_sz, '-o=' + asm_sz,
bitcode]) bitcode])
shellcmd([os.path.join(llvm_bin_path, 'llvm-mc'), shellcmd(['llvm-mc',
'-arch=' + arch_map[args.target], '-arch=' + arch_map[args.target],
'-x86-asm-syntax=intel', '-x86-asm-syntax=intel',
'-filetype=obj', '-filetype=obj',
...@@ -125,7 +126,7 @@ if __name__ == '__main__': ...@@ -125,7 +126,7 @@ if __name__ == '__main__':
if not args.crosstest_bitcode: if not args.crosstest_bitcode:
objs.append(arg) objs.append(arg)
elif use_llc: elif use_llc:
shellcmd([os.path.join(llvm_bin_path, 'llc'), shellcmd(['llc'
'-filetype=obj', '-filetype=obj',
'-o=' + obj_llc, '-o=' + obj_llc,
bitcode]) bitcode])
...@@ -134,6 +135,6 @@ if __name__ == '__main__': ...@@ -134,6 +135,6 @@ if __name__ == '__main__':
objs.append(bitcode) objs.append(bitcode)
linker = 'clang' if os.path.splitext(args.driver)[1] == '.c' else 'clang++' linker = 'clang' if os.path.splitext(args.driver)[1] == '.c' else 'clang++'
shellcmd([os.path.join(llvm_bin_path, linker), '-g', '-m32', args.driver] + shellcmd([linker, '-g', '-m32', args.driver] +
objs + objs +
['-lm', '-lpthread', '-o', os.path.join(args.dir, args.output)]) ['-lm', '-lpthread', '-o', os.path.join(args.dir, args.output)])
...@@ -19,7 +19,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -19,7 +19,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=simple_loop.c \ --test=simple_loop.c \
--driver=simple_loop_main.c \ --driver=simple_loop_main.c \
--output=simple_loop_O${optlevel}_${attribute} --output=simple_loop_O${optlevel}_${attribute}
...@@ -28,7 +27,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -28,7 +27,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=mem_intrin.cpp \ --test=mem_intrin.cpp \
--driver=mem_intrin_main.cpp \ --driver=mem_intrin_main.cpp \
--output=mem_intrin_O${optlevel}_${attribute} --output=mem_intrin_O${optlevel}_${attribute}
...@@ -37,7 +35,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -37,7 +35,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_arith.cpp \ --test=test_arith.cpp \
--test=test_arith_frem.ll \ --test=test_arith_frem.ll \
--test=test_arith_sqrt.ll \ --test=test_arith_sqrt.ll \
...@@ -48,7 +45,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -48,7 +45,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_bitmanip.cpp --test=test_bitmanip_intrin.ll \ --test=test_bitmanip.cpp --test=test_bitmanip_intrin.ll \
--driver=test_bitmanip_main.cpp \ --driver=test_bitmanip_main.cpp \
--output=test_bitmanip_O${optlevel}_${attribute} --output=test_bitmanip_O${optlevel}_${attribute}
...@@ -56,7 +52,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -56,7 +52,6 @@ for optlevel in ${OPTLEVELS} ; do
./crosstest.py -O${optlevel} --mattr ${attribute} \ ./crosstest.py -O${optlevel} --mattr ${attribute} \
--prefix=Subzero_ --target=x8632 \ --prefix=Subzero_ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_calling_conv.cpp \ --test=test_calling_conv.cpp \
--driver=test_calling_conv_main.cpp \ --driver=test_calling_conv_main.cpp \
--output=test_calling_conv_O${optlevel}_${attribute} --output=test_calling_conv_O${optlevel}_${attribute}
...@@ -65,7 +60,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -65,7 +60,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_cast.cpp --test=test_cast_to_u1.ll \ --test=test_cast.cpp --test=test_cast_to_u1.ll \
--driver=test_cast_main.cpp \ --driver=test_cast_main.cpp \
--output=test_cast_O${optlevel}_${attribute} --output=test_cast_O${optlevel}_${attribute}
...@@ -74,7 +68,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -74,7 +68,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_fcmp.pnacl.ll \ --test=test_fcmp.pnacl.ll \
--driver=test_fcmp_main.cpp \ --driver=test_fcmp_main.cpp \
--output=test_fcmp_O${optlevel}_${attribute} --output=test_fcmp_O${optlevel}_${attribute}
...@@ -83,7 +76,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -83,7 +76,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_global.cpp \ --test=test_global.cpp \
--driver=test_global_main.cpp \ --driver=test_global_main.cpp \
--output=test_global_O${optlevel}_${attribute} --output=test_global_O${optlevel}_${attribute}
...@@ -92,7 +84,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -92,7 +84,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_icmp.cpp --test=test_icmp_i1vec.ll \ --test=test_icmp.cpp --test=test_icmp_i1vec.ll \
--driver=test_icmp_main.cpp \ --driver=test_icmp_main.cpp \
--output=test_icmp_O${optlevel}_${attribute} --output=test_icmp_O${optlevel}_${attribute}
...@@ -101,7 +92,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -101,7 +92,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_select.ll \ --test=test_select.ll \
--driver=test_select_main.cpp \ --driver=test_select_main.cpp \
--output=test_select_O${optlevel}_${attribute} --output=test_select_O${optlevel}_${attribute}
...@@ -110,7 +100,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -110,7 +100,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_stacksave.c \ --test=test_stacksave.c \
--driver=test_stacksave_main.c \ --driver=test_stacksave_main.c \
--output=test_stacksave_O${optlevel}_${attribute} --output=test_stacksave_O${optlevel}_${attribute}
...@@ -122,7 +111,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -122,7 +111,6 @@ for optlevel in ${OPTLEVELS} ; do
--prefix=Subzero_ \ --prefix=Subzero_ \
--target=x8632 \ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_sync_atomic.cpp \ --test=test_sync_atomic.cpp \
--crosstest-bitcode=0 \ --crosstest-bitcode=0 \
--driver=test_sync_atomic_main.cpp \ --driver=test_sync_atomic_main.cpp \
...@@ -131,7 +119,6 @@ for optlevel in ${OPTLEVELS} ; do ...@@ -131,7 +119,6 @@ for optlevel in ${OPTLEVELS} ; do
./crosstest.py -O${optlevel} --mattr ${attribute} \ ./crosstest.py -O${optlevel} --mattr ${attribute} \
--prefix=Subzero_ --target=x8632 \ --prefix=Subzero_ --target=x8632 \
--dir="${OUTDIR}" \ --dir="${OUTDIR}" \
--llvm-bin-path="${LLVM_BIN_PATH}" \
--test=test_vector_ops.ll \ --test=test_vector_ops.ll \
--driver=test_vector_ops_main.cpp \ --driver=test_vector_ops_main.cpp \
--output=test_vector_ops_O${optlevel}_${attribute} --output=test_vector_ops_O${optlevel}_${attribute}
......
...@@ -2,35 +2,24 @@ ...@@ -2,35 +2,24 @@
import argparse import argparse
import os import os
import sys
import tempfile import tempfile
from utils import shellcmd from utils import shellcmd
from utils import FindBaseNaCl
if __name__ == '__main__': if __name__ == '__main__':
argparser = argparse.ArgumentParser() argparser = argparse.ArgumentParser()
argparser.add_argument('cfile', nargs='+', type=str, argparser.add_argument('cfile', nargs='+', type=str,
help='C file(s) to convert') help='C file(s) to convert')
argparser.add_argument('--nacl_sdk_root', nargs='?', type=str,
help='Path to NACL_SDK_ROOT')
argparser.add_argument('--dir', nargs='?', type=str, default='.', argparser.add_argument('--dir', nargs='?', type=str, default='.',
help='Output directory') help='Output directory')
argparser.add_argument('--disable-verify', action='store_true') argparser.add_argument('--disable-verify', action='store_true')
args = argparser.parse_args() args = argparser.parse_args()
nacl_sdk_root = os.environ.get('NACL_SDK_ROOT', None) nacl_root = FindBaseNaCl()
if args.nacl_sdk_root: # Prepend bin to $PATH.
nacl_sdk_root = os.path.expanduser(args.nacl_sdk_root) os.environ['PATH'] = (
nacl_root + '/toolchain/linux_x86/pnacl_newlib/bin' + os.pathsep +
if not nacl_sdk_root or not os.path.exists(nacl_sdk_root): os.pathsep + os.environ['PATH'])
print '''\
Please set the NACL_SDK_ROOT environment variable or pass the path through
--nacl_sdk_root to point to a valid Native Client SDK installation.'''
sys.exit(1)
includes_path = os.path.join(nacl_sdk_root, 'include')
toolchain_path = os.path.join(nacl_sdk_root, 'toolchain', 'linux_pnacl')
clang_path = os.path.join(toolchain_path, 'bin64', 'pnacl-clang')
opt_path = os.path.join(toolchain_path, 'host_x86_64', 'bin', 'opt')
tempdir = tempfile.mkdtemp() tempdir = tempfile.mkdtemp()
...@@ -40,11 +29,10 @@ Please set the NACL_SDK_ROOT environment variable or pass the path through ...@@ -40,11 +29,10 @@ Please set the NACL_SDK_ROOT environment variable or pass the path through
pnaclname = basename + '.pnacl.ll' pnaclname = basename + '.pnacl.ll'
pnaclname = os.path.join(args.dir, pnaclname) pnaclname = os.path.join(args.dir, pnaclname)
shellcmd(clang_path + ' -O2 -I{0} -c {1} -o {2}'.format( shellcmd('pnacl-clang -O2 -c {0} -o {1}'.format(cname, llname))
includes_path, cname, llname)) shellcmd('pnacl-opt ' +
shellcmd(opt_path + '-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' +
' -pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' + ('' if args.disable_verify else
('' if args.disable_verify else ' -verify-pnaclabi-module -verify-pnaclabi-functions') +
' -verify-pnaclabi-module -verify-pnaclabi-functions') + ' -pnaclabi-allow-debug-metadata'
' -pnaclabi-allow-debug-metadata -disable-simplify-libcalls' ' {0} -S -o {1}'.format(llname, pnaclname))
' {0} -S -o {1}'.format(llname, pnaclname))
import os
import subprocess import subprocess
import sys import sys
...@@ -10,3 +11,12 @@ def shellcmd(command, echo=True): ...@@ -10,3 +11,12 @@ def shellcmd(command, echo=True):
stdout_result = subprocess.check_output(command, shell=True) stdout_result = subprocess.check_output(command, shell=True)
if echo: sys.stdout.write(stdout_result) if echo: sys.stdout.write(stdout_result)
return stdout_result return stdout_result
def FindBaseNaCl():
"""Find the base native_client/ directory."""
nacl = 'native_client'
path_list = os.getcwd().split(os.sep)
if nacl not in path_list:
return None
last_index = len(path_list) - path_list[::-1].index(nacl)
return os.sep.join(path_list[:last_index])
...@@ -42,8 +42,8 @@ config.substitutions.append( ...@@ -42,8 +42,8 @@ config.substitutions.append(
config.substitutions.append(('%llvm2ice', llvm2icetool)) config.substitutions.append(('%llvm2ice', llvm2icetool))
config.substitutions.append(('%szdiff', os.path.join(bin_root, 'szdiff.py'))) config.substitutions.append(('%szdiff', os.path.join(bin_root, 'szdiff.py')))
llvmbintools = [r"\bFileCheck\b", r"\bllvm-mc\b", r"\bllvm-objdump\b", llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b",
r"\bnot\b", r"\bpnacl-freeze\b"] r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b"]
for tool in llvmbintools: for tool in llvmbintools:
# The re.sub() line is adapted from one of LLVM's lit.cfg files. # The re.sub() line is adapted from one of LLVM's lit.cfg files.
......
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