import multiprocessing
import os
import pathtools
-import shutil
from driver_env import env
from driver_log import Log
from driver_temps import TempFiles
-import re
import subprocess
EXTRA_ENV = {
- 'PIC': '${ARCH == X8632_NONSFI ? 1 : 0}',
+ 'PIC': '${NONSFI_NACL}',
# Determine if we should build nexes compatible with the IRT
'USE_IRT' : '1',
'DEFAULTLIBS': '${ALLOW_ZEROCOST_CXX_EH ? -l:libgcc_eh.a} ' +
'-l:libgcc.a -l:libcrt_platform.a ',
- 'TRIPLE' : '${TRIPLE_%ARCH%}',
- 'TRIPLE_ARM' : 'armv7a-none-nacl-gnueabihf',
- 'TRIPLE_X8632': 'i686-none-nacl-gnu',
- 'TRIPLE_X8664': 'x86_64-none-nacl-gnu',
- 'TRIPLE_MIPS32': 'mipsel-none-nacl-gnu',
- 'TRIPLE_X8632_LINUX': 'i686-linux-gnu',
- 'TRIPLE_X8632_NONSFI': 'i686-linux-gnu',
-
# BE CAREFUL: anything added here can introduce skew between
# the pnacl-translate commandline tool and the in-browser translator.
# See: llvm/tools/pnacl-llc/srpc_main.cpp and
# case and hence have not been implemented in gold
'${PIC ? -force-tls-non-pic} ',
- 'LLC_FLAGS_ARM' :
- ('-arm-reserve-r9 -sfi-disable-cp ' +
- '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data ' +
- '-no-inline-jumptables -float-abi=hard -mattr=+neon'),
-
- 'LLC_FLAGS_X8632' : '',
- 'LLC_FLAGS_X8664' : '',
-
- 'LLC_FLAGS_MIPS32': '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data',
-
- # When linking against Linux glibc, don't use %gs:0 to read the
- # thread pointer because that's not compatible with glibc's use of
- # %gs.
- 'LLC_FLAGS_X8632_LINUX' : '-mtls-use-call',
- # Similarly, Non-SFI Mode currently offers no optimized path for
- # reading the thread pointer.
- 'LLC_FLAGS_X8632_NONSFI' : '-mtls-use-call',
-
# LLC flags which set the target and output type.
'LLC_FLAGS_TARGET' : '-mtriple=${TRIPLE} -filetype=${outfiletype}',
'OPT_LEVEL' : '',
# faster translation == slower code
- 'LLC_FLAGS_FAST' : '${LLC_FLAGS_FAST_%ARCH%}'
+ 'LLC_FLAGS_FAST' : '-O0'
# This, surprisingly, makes a measurable difference
' -tail-merge-threshold=20',
- 'LLC_FLAGS_FAST_X8632': '-O0 ',
- 'LLC_FLAGS_FAST_X8664': '-O0 ',
- 'LLC_FLAGS_FAST_ARM': '-O0 ',
- 'LLC_FLAGS_FAST_MIPS32': '-fast-isel',
- 'LLC_FLAGS_FAST_X8632_LINUX': '-O0',
- 'LLC_FLAGS_FAST_X8632_NONSFI': '-O0',
-
- 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_%ARCH%} ' +
+ 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_ARCH} ' +
'${LLC_FLAGS_EXTRA}',
- # CPU that is representative of baseline feature requirements for NaCl
- # and/or chrome. We may want to make this more like "-mtune"
- # by specifying both "-mcpu=X" and "-mattr=+feat1,-feat2,...".
- # Note: this may be different from the in-browser translator, which may
- # do auto feature detection based on CPUID, but constrained by what is
- # accepted by NaCl validators.
- 'LLC_MCPU' : '-mcpu=${LLC_MCPU_%ARCH%}',
- 'LLC_MCPU_ARM' : 'cortex-a9',
- 'LLC_MCPU_X8632' : 'pentium4',
- 'LLC_MCPU_X8664' : 'core2',
- 'LLC_MCPU_MIPS32' : 'mips32r2',
- 'LLC_MCPU_X8632_LINUX' : '${LLC_MCPU_X8632}',
- 'LLC_MCPU_X8632_NONSFI' : '${LLC_MCPU_X8632}',
-
# Note: this is only used in the unsandboxed case
'RUN_LLC' : '${LLVM_PNACL_LLC} ${LLC_FLAGS} ${LLC_MCPU} '
'${input} -o ${output} ',
]
+def SetUpArch():
+ base_arch = env.getone('BASE_ARCH')
+ env.set('TARGET_OS', 'nacl')
+ if base_arch.endswith('_LINUX'):
+ base_arch = base_arch[:-len('_LINUX')]
+ env.set('TARGET_OS', 'linux')
+ elif base_arch.endswith('_MAC'):
+ base_arch = base_arch[:-len('_MAC')]
+ env.set('TARGET_OS', 'mac')
+
+ if env.getbool('NONSFI_NACL'):
+ triple_map = {
+ 'nacl':
+ {'X8632': 'i686-linux-gnu',
+ 'ARM': 'armv7a-linux-gnueabihf'}}
+ else:
+ triple_map = {
+ 'nacl':
+ {'X8632': 'i686-none-nacl-gnu',
+ 'X8664': 'x86_64-none-nacl-gnu',
+ 'ARM': 'armv7a-none-nacl-gnueabihf',
+ 'MIPS32': 'mipsel-none-nacl-gnu'},
+ 'linux': {'X8632': 'i686-linux-gnu'},
+ 'mac': {'X8632': 'i686-apple-darwin'}}
+ env.set('TRIPLE', triple_map[env.getone('TARGET_OS')][base_arch])
+
+ # CPU that is representative of baseline feature requirements for NaCl
+ # and/or chrome. We may want to make this more like "-mtune"
+ # by specifying both "-mcpu=X" and "-mattr=+feat1,-feat2,...".
+ # Note: this may be different from the in-browser translator, which may
+ # do auto feature detection based on CPUID, but constrained by what is
+ # accepted by NaCl validators.
+ cpu_map = {
+ 'X8632': 'pentium4',
+ 'X8664': 'core2',
+ 'ARM': 'cortex-a9',
+ 'MIPS32': 'mips32r2'}
+ env.set('LLC_MCPU', '-mcpu=%s' % cpu_map[base_arch])
+
+ llc_flags_map = {
+ 'ARM': ['-arm-reserve-r9', '-sfi-disable-cp', '-sfi-load', '-sfi-store',
+ '-sfi-stack', '-sfi-branch', '-sfi-data',
+ '-no-inline-jumptables', '-float-abi=hard', '-mattr=+neon'],
+ # Once PNaCl's build of compiler-rt (libgcc.a) defines __aeabi_*
+ # functions, we can drop the following ad-hoc option.
+ 'ARM_NONSFI': ['-arm-enable-aeabi-functions=0'],
+ 'MIPS32': ['-sfi-load', '-sfi-store', '-sfi-stack',
+ '-sfi-branch', '-sfi-data']}
+ env.set('LLC_FLAGS_ARCH', *llc_flags_map.get(env.getone('ARCH'), []))
+ # When linking against a host OS's libc (such as Linux glibc), don't
+ # use %gs:0 to read the thread pointer because that won't be
+ # compatible with the libc's use of %gs:0. Similarly, Non-SFI Mode
+ # currently offers no optimized path for reading the thread pointer.
+ if env.getone('TARGET_OS') != 'nacl' or env.getbool('NONSFI_NACL'):
+ env.append('LLC_FLAGS_ARCH', '-mtls-use-call')
+
+
def main(argv):
env.update(EXTRA_ENV)
driver_tools.ParseArgs(argv, TranslatorPatterns)
driver_tools.GetArch(required = True)
+ SetUpArch()
inputs = env.get('INPUTS')
output = env.getone('OUTPUT')
elif int(env.getone('SPLIT_MODULE')) < 1:
Log.Fatal('Value given for -split-module must be > 0')
if (env.getbool('ALLOW_LLVM_BITCODE_INPUT') or
- env.getone('ARCH') == 'X8632_LINUX' or
+ env.getone('TARGET_OS') != 'nacl' or
env.getbool('USE_EMULATOR')):
# When llvm input is allowed, the pexe may not be ABI-stable, so do not
- # split it. For now also do not support threading non-SFI baremetal mode.
- # Non-ABI-stable pexes may have symbol naming and visibility issues that the
- # current splitting scheme doesn't account for.
- # If the link would require a non-standard command line, do not split the
- # modules because the sandboxed linker doesn't support that combination.
+ # split it. Non-ABI-stable pexes may have symbol naming and visibility
+ # issues that the current splitting scheme doesn't account for.
+ #
+ # For now, also do not enable multi-threaded translation when TARGET_OS !=
+ # 'nacl', since in these cases we will be using the host toolchain's
+ # linker.
+ #
# The x86->arm emulator is very flaky when threading is used, so don't
# do module splitting when using it.
env.set('SPLIT_MODULE', '1')
TempFiles.add(filename)
env.append('INPUTS', filename)
- if env.getone('ARCH') == 'X8632_LINUX':
+ if env.getone('TARGET_OS') != 'nacl':
RunHostLD(ofile, output)
else:
RunLD(ofile, output)
driver_tools.RunDriver('nativeld', args)
def RunHostLD(infile, outfile):
- driver_tools.Run(['objcopy', '--redefine-sym', '_start=_user_start', infile])
- lib_dir = env.getone('BASE_LIB_NATIVE') + 'x86-32-linux'
- driver_tools.Run(['gcc', '-m32', infile,
- os.path.join(lib_dir, 'unsandboxed_irt.o'),
- '-lpthread',
- '-lrt', # For clock_gettime()
- '-o', outfile])
+ if env.getone('TARGET_OS') == 'linux':
+ driver_tools.Run(['objcopy', '--redefine-sym', '_start=_user_start',
+ infile])
+ lib_dir = (env.getone('BASE_LIB_NATIVE')
+ + 'x86-32-%s' % env.getone('TARGET_OS'))
+ args = ['gcc', '-m32', infile, '-o', outfile,
+ os.path.join(lib_dir, 'unsandboxed_irt.o'), '-lpthread']
+ if env.getone('TARGET_OS') == 'linux':
+ args.append('-lrt') # For clock_gettime()
+ driver_tools.Run(args)
def RunLLC(infile, outfile, outfiletype):
env.push()