Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / pnacl / driver / pnacl-driver.py
index 86319b0..5621fb1 100755 (executable)
@@ -2,17 +2,17 @@
 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
-#
-# IMPORTANT NOTE: If you make local mods to this file, you must run:
-#   %  pnacl/build.sh driver
-# in order for them to take effect in the scons build.  This command
-# updates the copy in the toolchain/ tree.
-#
-
-from driver_tools import *
+
+import re
+import subprocess
+
+from driver_tools import AddHostBinarySearchPath, DefaultOutputName, \
+    DriverChain, GetArch, ParseArgs, ParseTriple, Run, RunDriver, RunWithEnv, \
+    TempNameGen, UnrecognizedOption
 from driver_env import env
-from driver_log import Log
+from driver_log import DriverOpen, Log
 import filetype
+import pathtools
 
 EXTRA_ENV = {
   'ALLOW_TRANSLATE': '0',  # Allow bitcode translation before linking.
@@ -71,6 +71,7 @@ EXTRA_ENV = {
   'BIAS_MIPS32' : '-D__MIPS__ -D__mips__ -D__MIPSEL__',
   'BIAS_X8632'  : '-D__i386__ -D__i386 -D__i686 -D__i686__ -D__pentium4__',
   'BIAS_X8664'  : '-D__amd64__ -D__amd64 -D__x86_64__ -D__x86_64 -D__core2__',
+  'BIAS_ARM_NONSFI': '${BIAS_ARM} -D__native_client_nonsfi__',
   'BIAS_X8632_NONSFI': '${BIAS_X8632} -D__native_client_nonsfi__',
   'FRONTEND_TRIPLE' : 'le32-unknown-nacl',
 
@@ -263,7 +264,6 @@ CustomPatterns = [
   ( '(--pnacl-allow-nexe-build-id)', AddLDFlag),
   ( '(--pnacl-disable-abi-check)',  AddLDFlag),
   ( '(--pnacl-disable-pass=.+)',    AddLLVMPassDisableFlag),
-  ( '(--pnacl-allow-dev-intrinsics)', AddLDFlag),
 ]
 
 GCCPatterns = [
@@ -447,7 +447,6 @@ def DriverOutputTypes(driver_flag, compiling_to_native):
 
 
 def ReadDriverRevision():
-  nacl_version = 'unknown'
   rev_file = env.getone('DRIVER_REV_FILE')
   # Might be an SVN version or a GIT hash (depending on the NaCl src client)
   nacl_ver = DriverOpen(rev_file, 'rb').readlines()[0]
@@ -492,8 +491,14 @@ def main(argv):
   # If -arch was given, we are compiling directly to native code
   compiling_to_native = GetArch() is not None
 
-  if env.getbool('ALLOW_NATIVE') and not compiling_to_native:
-    Log.Fatal("--pnacl-allow-native without -arch is not meaningful.")
+  if env.getbool('ALLOW_NATIVE'):
+    if not compiling_to_native:
+      Log.Fatal("--pnacl-allow-native without -arch is not meaningful.")
+    # For native/mixed links, also bring in the native libgcc to avoid link
+    # failure if pre-translated native code needs functions from it.
+    env.append('LD_FLAGS', env.eval('-L${LIBS_NATIVE_ARCH}'))
+    env.append('STDLIBS', '-lgcc')
+
 
   if not env.get('STDLIB'):
     # Default C++ Standard Library.
@@ -604,7 +609,7 @@ def main(argv):
   ld_args = env.get('LD_ARGS')
   ld_flags = env.get('LD_FLAGS')
 
-  RunDriver('ld', ld_flags + ld_args + ['-o', output])
+  RunDriver('pnacl-ld', ld_flags + ld_args + ['-o', output])
   return 0
 
 def IsFlag(f):
@@ -635,12 +640,13 @@ def RunLLVMAS(infile, output):
     infile = '-'
   # This is a bitcode only step - so get rid of "-arch xxx" which
   # might be inherited from the current invocation
-  RunDriver('as', [infile, '-o', output], suppress_inherited_arch_args=True)
+  RunDriver('pnacl-as', [infile, '-o', output],
+            suppress_inherited_arch_args=True)
 
 def RunNativeAS(infile, output):
   if IsStdinInput(infile):
     infile = '-'
-  RunDriver('as', [infile, '-o', output])
+  RunDriver('pnacl-as', [infile, '-o', output])
 
 def RunTranslate(infile, output, mode):
   if not env.getbool('ALLOW_TRANSLATE'):
@@ -652,13 +658,13 @@ def RunTranslate(infile, output, mode):
                                        infile, '-o', output]
   if env.getbool('PIC'):
     args += ['-fPIC']
-  RunDriver('translate', args)
+  RunDriver('pnacl-translate', args)
 
 
 def RunOpt(infile, outfile, pass_list):
   filtered_list = [pass_option for pass_option in pass_list
                    if pass_option not in env.get('LLVM_PASSES_TO_DISABLE')]
-  RunDriver('opt', filtered_list + [infile, '-o', outfile])
+  RunDriver('pnacl-opt', filtered_list + [infile, '-o', outfile])
 
 
 def SetupChain(chain, input_type, output_type):