예제 #1
0
 def checkLLCTranslateFlags(self, pexe, arch, flags, expected_flags):
     ''' Given a |pexe| the |arch| for translation and additional pnacl-translate
 |flags|, check that the commandline for LLC really contains the
 |expected_flags|.  This ensures that the pnacl-translate script
 does not drop certain flags accidentally. '''
     # TODO(jvoung): Get rid of INHERITED_DRIVER_ARGS, which leaks across runs.
     env.set('INHERITED_DRIVER_ARGS', '')
     temp_output = self.getTemp()
     # Major hack to prevent DriverExit() from aborting the test.
     # The test will surely DriverLog.Fatal() because dry-run currently
     # does not handle anything that involves invoking a subprocess and
     # grepping the stdout/stderr since it never actually invokes
     # the subprocess. Unfortunately, pnacl-translate does grep the output of
     # the sandboxed LLC run, so we can only go that far with --dry-run.
     capture_out = cStringIO.StringIO()
     driver_log.Log.CaptureToStream(capture_out)
     backup_exit = sys.exit
     sys.exit = driver_test_utils.FakeExit
     self.assertRaises(driver_test_utils.DriverExitException,
                       driver_tools.RunDriver, 'translate', [
                           '--pnacl-driver-verbose', '--dry-run', '-arch',
                           arch, pexe.name, '-o', temp_output.name
                       ] + flags)
     driver_log.Log.ResetStreams()
     out = capture_out.getvalue()
     sys.exit = backup_exit
     for f in expected_flags:
         self.assertTrue(re.search(f, out),
                         msg='Searching for regex %s in %s' % (f, out))
     return
예제 #2
0
def main(argv):
    env.update(EXTRA_ENV)
    driver_tools.ParseArgs(argv, PATTERNS)

    inputs = env.get('INPUTS')

    if len(inputs) == 0:
        Log.Fatal("No input files given")

    for infile in inputs:
        driver_tools.CheckPathLength(infile)
        env.push()
        env.set('input', infile)

        # For frozen PNaCl bitcode, use 'llvm-nm -bitcode-format=pnacl'. For all
        # other formats, use the binutils nm with our gold plugin.
        # Update: llvm-nm -bitcode-format=pnacl is currently disabled.
        if filetype.IsPNaClBitcode(infile):
            Log.Fatal(
                'nm on finalized bitcode is currently disabled.\n'
                'See: https://code.google.com/p/nativeclient/issues/detail?id=3993'
            )
        else:
            env.set('TOOLNAME', '${NM}')
            env.append('FLAGS', '--plugin=${GOLD_PLUGIN_SO}')

        driver_tools.Run('"${TOOLNAME}" ${FLAGS} ${input}')
        env.pop()

    # only reached in case of no errors
    return 0
 def checkLLCTranslateFlags(self, pexe, arch, flags,
                            expected_flags):
   ''' Given a |pexe| the |arch| for translation and additional pnacl-translate
   |flags|, check that the commandline for LLC really contains the
   |expected_flags|.  This ensures that the pnacl-translate script
   does not drop certain flags accidentally. '''
   # TODO(jvoung): Get rid of INHERITED_DRIVER_ARGS, which leaks across runs.
   env.set('INHERITED_DRIVER_ARGS', '')
   temp_output = self.getTemp()
   # Major hack to prevent DriverExit() from aborting the test.
   # The test will surely DriverLog.Fatal() because dry-run currently
   # does not handle anything that involves invoking a subprocess and
   # grepping the stdout/stderr since it never actually invokes
   # the subprocess. Unfortunately, pnacl-translate does grep the output of
   # the sandboxed LLC run, so we can only go that far with --dry-run.
   capture_out = cStringIO.StringIO()
   driver_log.Log.CaptureToStream(capture_out)
   backup_exit = sys.exit
   sys.exit = driver_test_utils.FakeExit
   self.assertRaises(driver_test_utils.DriverExitException,
                     driver_tools.RunDriver,
                     'translate',
                     ['--pnacl-driver-verbose',
                      '--dry-run',
                      '-arch', arch,
                      pexe.name,
                      '-o', temp_output.name] + flags)
   driver_log.Log.ResetStreams()
   out = capture_out.getvalue()
   sys.exit = backup_exit
   for f in expected_flags:
     self.assertTrue(re.search(f, out),
                     msg='Searching for regex %s in %s' % (f, out))
   return
예제 #4
0
def main(argv):
  env.update(EXTRA_ENV)

  ParseArgs(argv, LDPatterns)

  GetArch(required=True)
  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  if output == '':
    output = pathtools.normalize('a.out')

  # Expand all parameters
  # This resolves -lfoo into actual filenames,
  # and expands linker scripts into command-line arguments.
  inputs = ldtools.ExpandInputs(inputs,
                                env.get('SEARCH_DIRS'),
                                env.getbool('STATIC'),
                                ldtools.LibraryTypes.NATIVE)

  env.push()
  env.set('inputs', *inputs)
  env.set('output', output)

  if env.getbool('SANDBOXED'):
    RunLDSandboxed()
  else:
    Run('${RUN_LD}')
  env.pop()
  # only reached in case of no errors
  return 0
def main(argv):
  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, PATTERNS)
  inputs = env.get('INPUTS')
  if len(inputs) == 0:
    Log.Fatal("No input files given")

  for infile in inputs:
    driver_tools.CheckPathLength(infile)
    env.push()
    env.set('input', infile)
    if filetype.IsLLVMBitcode(infile):
      # Hack to support newlib build.
      # Newlib determines whether the toolchain supports .init_array, etc., by
      # compiling a small test and looking for a specific section tidbit using
      # "readelf -S". Since pnacl compiles to bitcode, readelf isn't available.
      # (there is a line: "if ${READELF} -S conftest | grep -e INIT_ARRAY"
      # in newlib's configure file).
      # TODO(sehr): we may want to implement a whole readelf on bitcode.
      flags = env.get('FLAGS')
      if len(flags) == 1 and flags[0] == '-S':
        print 'INIT_ARRAY'
        return 0
      Log.Fatal('Cannot handle pnacl-readelf %s' % str(argv))
      return 1
    driver_tools.Run('"${READELF}" ${FLAGS} ${input}')
    env.pop()

  # only reached in case of no errors
  return 0
예제 #6
0
def main(argv):
  env.update(EXTRA_ENV)
  ParseArgs(argv, PATTERNS)
  inputs = env.get('INPUTS')
  if len(inputs) == 0:
    Log.Fatal("No input files given")

  for infile in inputs:
    env.push()
    env.set('input', infile)
    if filetype.IsLLVMBitcode(infile):
      # Hack to support newlib build.
      # Newlib determines whether the toolchain supports .init_array, etc., by
      # compiling a small test and looking for a specific section tidbit using
      # "readelf -S". Since pnacl compiles to bitcode, readelf isn't available.
      # (there is a line: "if ${READELF} -S conftest | grep -e INIT_ARRAY"
      # in newlib's configure file).
      # TODO(sehr): we may want to implement a whole readelf on bitcode.
      flags = env.get('FLAGS')
      if len(flags) == 1 and flags[0] == '-S':
        print 'INIT_ARRAY'
        return 0
      Log.Fatal('Cannot handle pnacl-readelf %s' % str(argv))
      return 1
    Run('"${READELF}" ${FLAGS} ${input}')
    env.pop()

  # only reached in case of no errors
  return 0
예제 #7
0
def main(argv):
    env.update(EXTRA_ENV)

    ParseArgs(argv, LDPatterns)

    GetArch(required=True)
    inputs = env.get('INPUTS')
    output = env.getone('OUTPUT')

    if output == '':
        output = pathtools.normalize('a.out')

    # Expand all parameters
    # This resolves -lfoo into actual filenames,
    # and expands linker scripts into command-line arguments.
    inputs = ldtools.ExpandInputs(inputs, env.get('SEARCH_DIRS'),
                                  env.getbool('STATIC'),
                                  ldtools.LibraryTypes.NATIVE)

    env.push()
    env.set('inputs', *inputs)
    env.set('output', output)

    if env.getbool('SANDBOXED'):
        RunLDSandboxed()
    else:
        Run('${RUN_LD}')
    env.pop()
    # only reached in case of no errors
    return 0
예제 #8
0
def main(argv):
  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, PATTERNS)

  inputs = env.get('INPUTS')

  if len(inputs) == 0:
    Log.Fatal("No input files given")

  for infile in inputs:
    driver_tools.CheckPathLength(infile)
    env.push()
    env.set('input', infile)

    # For frozen PNaCl bitcode, use 'llvm-nm -bitcode-format=pnacl'. For all
    # other formats, use the binutils nm with our gold plugin.
    # Update: llvm-nm -bitcode-format=pnacl is currently disabled.
    if filetype.IsPNaClBitcode(infile):
      Log.Fatal(
          'nm on finalized bitcode is currently disabled.\n'
          'See: https://code.google.com/p/nativeclient/issues/detail?id=3993')
    else:
      env.set('TOOLNAME', '${NM}')
      env.append('FLAGS', '--plugin=${GOLD_PLUGIN_SO}')

    driver_tools.Run('"${TOOLNAME}" ${FLAGS} ${input}')
    env.pop()

  # only reached in case of no errors
  return 0
예제 #9
0
 def setUp(self):
     super(TestDefaultOutputFilename, self).setUp()
     driver_test_utils.ApplyTestEnvOverrides(env)
     env.set('SHARED', '0')
     # Driver mode flags to test.  Having no mode flag at all is expected to
     # generate an a.out file, but that is currently hard to test
     # without actually running clang, the bitcode linker, pnacl-llc, then
     # the native linker.
     self.driver_flags = ['-E', '-S', '-c']
 def setUp(self):
   super(TestDefaultOutputFilename, self).setUp()
   driver_test_utils.ApplyTestEnvOverrides(env)
   env.set('SHARED', '0')
   # Driver mode flags to test.  Having no mode flag at all is expected to
   # generate an a.out file, but that is currently hard to test
   # without actually running clang, the bitcode linker, pnacl-llc, then
   # the native linker.
   self.driver_flags = ['-E', '-S', '-c']
예제 #11
0
def SetArch(arch):
  arch = FixArch(arch)
  env.set('ARCH', arch)

  nonsfi_nacl = False
  if arch.endswith('_NONSFI'):
    arch = arch[:-len('_NONSFI')]
    nonsfi_nacl = True
  env.set('BASE_ARCH', arch)
  env.setbool('NONSFI_NACL', nonsfi_nacl)
 def test_ClangHelpMessage(self):
   env.set('SCRIPT_NAME', 'pnacl-clang')
   help_str = pnacl_clang.get_help(self.default_argv)
   self.assertNotEqual(help_str, driver_tools.HelpNotAvailable())
   self.assertTrue(len(help_str) > 0)
   # Clang also has a '--help-full'.
   if driver_test_utils.CanRunHost():
     help_full_str = pnacl_clang.get_help(['driver', '--help-full'])
     self.assertNotEqual(help_full_str, driver_tools.HelpNotAvailable())
     self.assertTrue(len(help_full_str) > 0)
예제 #13
0
 def test_ClangHelpMessage(self):
     env.set('SCRIPT_NAME', 'pnacl-clang')
     help_str = pnacl_clang.get_help(self.default_argv)
     self.assertNotEqual(help_str, driver_tools.HelpNotAvailable())
     self.assertTrue(len(help_str) > 0)
     # Clang also has a '--help-full'.
     if driver_test_utils.CanRunHost():
         help_full_str = pnacl_clang.get_help(['driver', '--help-full'])
         self.assertNotEqual(help_full_str, driver_tools.HelpNotAvailable())
         self.assertTrue(len(help_full_str) > 0)
예제 #14
0
def SetArch(arch):
  arch = FixArch(arch)
  env.set('ARCH', arch)

  nonsfi_nacl = False
  if arch.endswith('_NONSFI'):
    arch = arch[:-len('_NONSFI')]
    nonsfi_nacl = True
  env.set('BASE_ARCH', arch)
  env.setbool('NONSFI_NACL', nonsfi_nacl)
예제 #15
0
def main(argv):
  env.update(EXTRA_ENV)

  ParseArgs(argv, LDPatterns)

  GetArch(required=True)
  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  if output == '':
    output = pathtools.normalize('a.out')

  # As we will modify the output file in-place for non-SFI, we output
  # the file to a temporary file first and then rename it. Otherwise,
  # build systems such as make assume the output file is ready even
  # if the last build failed during the in-place update.
  tmp_output = output + '.tmp'

  # Expand all parameters
  # This resolves -lfoo into actual filenames,
  # and expands linker scripts into command-line arguments.
  inputs = ldtools.ExpandInputs(inputs,
                                env.get('SEARCH_DIRS'),
                                True,
                                ldtools.LibraryTypes.NATIVE)

  env.push()
  env.set('inputs', *inputs)
  env.set('output', tmp_output)

  if env.getbool('SANDBOXED'):
    RunLDSandboxed()
  else:
    Run('${RUN_LD}')

  if env.getbool('NONSFI_NACL'):
    # Remove PT_INTERP in non-SFI binaries as we never use host's
    # dynamic linker/loader.
    #
    # This is necessary otherwise we get a statically linked
    # executable that is not directly runnable by Linux, because Linux
    # tries to load the non-existent file that PT_INTERP points to.
    #
    # This is fairly hacky.  It would be better if the linker provided
    # an option for omitting PT_INTERP (e.g. "--dynamic-linker ''").
    RemoveInterpProgramHeader(tmp_output)
  if driver_tools.IsWindowsPython() and os.path.exists(output):
    # On Windows (but not on Unix), the os.rename() call would fail if the
    # output file already exists.
    os.remove(output)
  os.rename(tmp_output, output)
  env.pop()
  # only reached in case of no errors
  return 0
 def test_SaveTempsNotWiped(self):
   """Test that driver-generated temp files don't get wiped w/ "-save-temps".
   """
   env.push()
   env.set('SAVE_TEMPS', '1')
   t_gen_out, t_gen_in = self.nameGenTemps()
   # Now wipe!
   driver_temps.TempFiles.wipe()
   env.pop()
   # They are *not* gone.
   self.assertTrue(os.path.exists(t_gen_out))
   self.assertTrue(os.path.exists(t_gen_in))
예제 #17
0
 def test_SaveTempsNotWiped(self):
     """Test that driver-generated temp files don't get wiped w/ "-save-temps".
 """
     env.push()
     env.set('SAVE_TEMPS', '1')
     t_gen_out, t_gen_in = self.nameGenTemps()
     # Now wipe!
     driver_temps.TempFiles.wipe()
     env.pop()
     # They are *not* gone.
     self.assertTrue(os.path.exists(t_gen_out))
     self.assertTrue(os.path.exists(t_gen_in))
예제 #18
0
def RunLD(infile, outfile):
    inputs = env.get('INPUTS')
    if infile:
        inputs = ListReplace(inputs, '__BITCODE__',
                             '--llc-translated-file=' + infile)
    ToggleDefaultCommandlineLD(inputs, infile)
    env.set('ld_inputs', *inputs)
    args = env.get('LD_ARGS') + ['-o', outfile]
    if not env.getbool('SHARED') and env.getbool('STDLIB'):
        args += env.get('LD_ARGS_ENTRY')
    args += env.get('LD_FLAGS')
    driver_tools.RunDriver('nativeld', args)
예제 #19
0
 def test_ARHelpMessage(self):
     # Some of the help messages use the 'SCRIPT_NAME' env var, so set that.
     # We probably don't want to depend on this global env across tests,
     # but that's what we have now and it's convenient.
     env.set('SCRIPT_NAME', 'pnacl-ar')
     help_str = pnacl_ar.get_help(self.default_argv)
     # Ideally we would be able to test the content better, but for now
     # this at least tests that no exception is raised, etc.
     self.assertNotEqual(help_str, driver_tools.HelpNotAvailable())
     # Use assertTrue x > 0 instead of assertGreater(x, 0) since some of
     # our bots don't have python 2.7.
     self.assertTrue(len(help_str) > 0)
 def test_ARHelpMessage(self):
   # Some of the help messages use the 'SCRIPT_NAME' env var, so set that.
   # We probably don't want to depend on this global env across tests,
   # but that's what we have now and it's convenient.
   env.set('SCRIPT_NAME', 'pnacl-ar')
   help_str = pnacl_ar.get_help(self.default_argv)
   # Ideally we would be able to test the content better, but for now
   # this at least tests that no exception is raised, etc.
   self.assertNotEqual(help_str, driver_tools.HelpNotAvailable())
   # Use assertTrue x > 0 instead of assertGreater(x, 0) since some of
   # our bots don't have python 2.7.
   self.assertTrue(len(help_str) > 0)
예제 #21
0
    def checkCompileTranslateFlags(self,
                                   pexe,
                                   arch,
                                   flags,
                                   expected_flags,
                                   invert_match=False,
                                   expected_args=(),
                                   expected_output_file_count=None):
        ''' Given a |pexe| the |arch| for translation and additional pnacl-translate
    |flags|, check that the commandline for LLC really contains the
    |expected_flags|.  This ensures that the pnacl-translate script
    does not drop certain flags accidentally. '''
        # TODO(jvoung): Get rid of INHERITED_DRIVER_ARGS, which leaks across runs.
        env.set('INHERITED_DRIVER_ARGS', '')
        temp_output = self.getTemp()
        # Major hack to prevent DriverExit() from aborting the test.
        # The test will surely DriverLog.Fatal() because dry-run currently
        # does not handle anything that involves invoking a subprocess and
        # grepping the stdout/stderr since it never actually invokes
        # the subprocess. Unfortunately, pnacl-translate does grep the output of
        # the sandboxed LLC run, so we can only go that far with --dry-run.
        capture_out = cStringIO.StringIO()
        driver_log.Log.CaptureToStream(capture_out)
        backup_exit = sys.exit
        sys.exit = driver_test_utils.FakeExit
        self.assertRaises(driver_test_utils.DriverExitException,
                          driver_tools.RunDriver, 'pnacl-translate', [
                              '--pnacl-driver-verbose', '--dry-run', '-arch',
                              arch, pexe.name, '-o', temp_output.name
                          ] + flags)
        driver_log.Log.ResetStreams()
        out = capture_out.getvalue()
        sys.exit = backup_exit
        for f in expected_flags:
            message = 'Searching for regex %s in %s' % (f, out)
            match = re.search(f, out, re.S)
            if not invert_match:
                self.assertTrue(match, msg=message)
            else:
                self.assertFalse(match, msg=message)

        # Check for some env vars that are passed to the sandboxed translator.
        args_got = re.findall(
            r'-E NACL_IRT_PNACL_TRANSLATOR_COMPILE_ARG_\d*=([^ ]*)', out)
        for arg in expected_args:
            self.assertIn(arg, args_got, repr(out))

        if expected_output_file_count is not None:
            output_files_got = re.findall(
                r'-E NACL_IRT_PNACL_TRANSLATOR_COMPILE_OUTPUT_\d*=([^ ]*)',
                out)
            self.assertEquals(len(output_files_got),
                              expected_output_file_count)
예제 #22
0
def main(argv):
    env.update(EXTRA_ENV)

    ParseArgs(argv, LDPatterns)

    GetArch(required=True)
    inputs = env.get('INPUTS')
    output = env.getone('OUTPUT')

    if output == '':
        output = pathtools.normalize('a.out')

    # As we will modify the output file in-place for non-SFI, we output
    # the file to a temporary file first and then rename it. Otherwise,
    # build systems such as make assume the output file is ready even
    # if the last build failed during the in-place update.
    tmp_output = output + '.tmp'

    # Expand all parameters
    # This resolves -lfoo into actual filenames,
    # and expands linker scripts into command-line arguments.
    inputs = ldtools.ExpandInputs(inputs, env.get('SEARCH_DIRS'), True,
                                  ldtools.LibraryTypes.NATIVE)

    env.push()
    env.set('inputs', *inputs)
    env.set('output', tmp_output)

    if env.getbool('SANDBOXED'):
        RunLDSandboxed()
    else:
        Run('${RUN_LD}')

    if env.getbool('NONSFI_NACL'):
        # Remove PT_INTERP in non-SFI binaries as we never use host's
        # dynamic linker/loader.
        #
        # This is necessary otherwise we get a statically linked
        # executable that is not directly runnable by Linux, because Linux
        # tries to load the non-existent file that PT_INTERP points to.
        #
        # This is fairly hacky.  It would be better if the linker provided
        # an option for omitting PT_INTERP (e.g. "--dynamic-linker ''").
        RemoveInterpProgramHeader(tmp_output)
    if driver_tools.IsWindowsPython() and os.path.exists(output):
        # On Windows (but not on Unix), the os.rename() call would fail if the
        # output file already exists.
        os.remove(output)
    os.rename(tmp_output, output)
    env.pop()
    # only reached in case of no errors
    return 0
예제 #23
0
def AddInputFileStdin():
    global stdin_count

    # When stdin is an input, -x or -E must be given.
    forced_type = filetype.GetForcedFileType()
    if not forced_type:
        # Only allowed if -E is specified.
        forced_type = 'c'
        env.set('NEED_DASH_E', '1')

    stdin_name = '__stdin%d__' % stdin_count
    env.append('INPUTS', stdin_name)
    filetype.ForceFileType(stdin_name, forced_type)
    stdin_count += 1
예제 #24
0
def SetStdLib(*args):
  """Set the C++ Standard Library."""
  lib = args[0]
  assert(lib == 'libc++' or lib == 'libstdc++')
  env.set('STDLIB', lib)
  env.set('STDLIB_TRUNC', lib[3:])
  if lib == 'libc++':
    env.set('STDLIB_IDIR', 'v1')
    # libc++ depends on pthread for C++11 features as well as some
    # exception handling (which may get removed later by the PNaCl ABI
    # simplification) and initialize-once.
    env.set('PTHREAD', '1')
  elif lib == 'libstdc++':
    env.set('STDLIB_IDIR', '4.6.2')
예제 #25
0
def SetStdLib(*args):
  """Set the C++ Standard Library."""
  lib = args[0]
  assert(lib == 'libc++' or lib == 'libstdc++')
  env.set('STDLIB', lib)
  env.set('STDLIB_TRUNC', lib[3:])
  if lib == 'libc++':
    env.set('STDLIB_IDIR', 'v1')
    # libc++ depends on pthread for C++11 features as well as some
    # exception handling (which may get removed later by the PNaCl ABI
    # simplification) and initialize-once.
    env.set('PTHREAD', '1')
  elif lib == 'libstdc++':
    env.set('STDLIB_IDIR', '4.6.2')
예제 #26
0
def RunLD(infile, outfile):
    inputs = env.get("INPUTS")
    if infile:
        inputs = ListReplace(inputs, "__BITCODE__", "--llc-translated-file=" + infile)
    ToggleDefaultCommandlineLD(inputs, infile)
    env.set("ld_inputs", *inputs)
    args = env.get("LD_ARGS") + ["-o", outfile]
    if not env.getbool("SHARED") and env.getbool("STDLIB"):
        args += env.get("LD_ARGS_ENTRY")
    args += env.get("LD_FLAGS")
    # If there is bitcode, there is also a metadata file.
    if infile and env.getbool("USE_META"):
        args += ["--metadata", "%s.meta" % infile]
    driver_tools.RunDriver("nativeld", args)
예제 #27
0
def AddInputFileStdin():
  global stdin_count

  # When stdin is an input, -x or -E must be given.
  forced_type = filetype.GetForcedFileType()
  if not forced_type:
    # Only allowed if -E is specified.
    forced_type = 'c'
    env.set('NEED_DASH_E', '1')

  stdin_name = '__stdin%d__' % stdin_count
  env.append('INPUTS', stdin_name)
  filetype.ForceFileType(stdin_name, forced_type)
  stdin_count += 1
예제 #28
0
def DriverMain(module, argv):
    # TODO(robertm): this is ugly - try to get rid of this
    if '--pnacl-driver-verbose' in argv:
        Log.IncreaseVerbosity()
        env.set('LOG_VERBOSE', '1')

    # driver_path has the form: /foo/bar/pnacl_root/newlib/bin/pnacl-clang
    driver_path = pathtools.abspath(pathtools.normalize(argv[0]))
    driver_bin = pathtools.dirname(driver_path)
    script_name = pathtools.basename(driver_path)
    env.set('SCRIPT_NAME', script_name)
    env.set('DRIVER_PATH', driver_path)
    env.set('DRIVER_BIN', driver_bin)

    Log.SetScriptName(script_name)

    ReadConfig()

    if IsWindowsPython():
        SetupCygwinLibs()

    # skip tool name
    argv = argv[1:]

    # Handle help info
    if ('--help' in argv or '-h' in argv or '-help' in argv
            or '--help-full' in argv):
        help_func = getattr(module, 'get_help', None)
        if not help_func:
            Log.Fatal(HelpNotAvailable())
        helpstr = help_func(argv)
        print helpstr
        return 0

    return module.main(argv)
예제 #29
0
  def checkCompileTranslateFlags(self, pexe, arch, flags,
                                 expected_flags, invert_match=False,
                                 expected_args=(),
                                 expected_output_file_count=None):
    ''' Given a |pexe| the |arch| for translation and additional pnacl-translate
    |flags|, check that the commandline for LLC really contains the
    |expected_flags|.  This ensures that the pnacl-translate script
    does not drop certain flags accidentally. '''
    # TODO(jvoung): Get rid of INHERITED_DRIVER_ARGS, which leaks across runs.
    env.set('INHERITED_DRIVER_ARGS', '')
    temp_output = self.getTemp()
    # Major hack to prevent DriverExit() from aborting the test.
    # The test will surely DriverLog.Fatal() because dry-run currently
    # does not handle anything that involves invoking a subprocess and
    # grepping the stdout/stderr since it never actually invokes
    # the subprocess. Unfortunately, pnacl-translate does grep the output of
    # the sandboxed LLC run, so we can only go that far with --dry-run.
    capture_out = cStringIO.StringIO()
    driver_log.Log.CaptureToStream(capture_out)
    backup_exit = sys.exit
    sys.exit = driver_test_utils.FakeExit
    self.assertRaises(driver_test_utils.DriverExitException,
                      driver_tools.RunDriver,
                      'pnacl-translate',
                      ['--pnacl-driver-verbose',
                       '--dry-run',
                       '-arch', arch,
                       pexe.name,
                       '-o', temp_output.name] + flags)
    driver_log.Log.ResetStreams()
    out = capture_out.getvalue()
    sys.exit = backup_exit
    for f in expected_flags:
      message = 'Searching for regex %s in %s' % (f, out)
      match = re.search(f, out, re.S)
      if not invert_match:
        self.assertTrue(match, msg=message)
      else:
        self.assertFalse(match, msg=message)

    # Check for some env vars that are passed to the sandboxed translator.
    args_got = re.findall(
        r'-E NACL_IRT_PNACL_TRANSLATOR_COMPILE_ARG_\d*=([^ ]*)', out)
    for arg in expected_args:
      self.assertIn(arg, args_got, repr(out))

    if expected_output_file_count is not None:
      output_files_got = re.findall(
          r'-E NACL_IRT_PNACL_TRANSLATOR_COMPILE_OUTPUT_\d*=([^ ]*)', out)
      self.assertEquals(len(output_files_got), expected_output_file_count)
예제 #30
0
def AddInputFileStdin():
    global stdin_count

    # When stdin is an input, -x or -E must be given.
    forced_type = GetForcedFileType()
    if not forced_type:
        # Only allowed if -E is specified.
        forced_type = "c"
        env.set("NEED_DASH_E", "1")

    stdin_name = "__stdin%d__" % stdin_count
    env.append("INPUTS", stdin_name)
    ForceFileType(stdin_name, forced_type)
    stdin_count += 1
예제 #31
0
def RunLD(infile, outfile):
  inputs = env.get('INPUTS')
  if infile:
    # Put llc-translated-file at the beginning of the inputs so that it will
    # pull in all needed symbols from any native archives that may also be
    # in the input list. This is in case there are any mixed groups of bitcode
    # and native archives in the link (as is the case with irt_browser_lib)
    inputs.remove('__BITCODE__')
    inputs = ['--llc-translated-file=' + infile] + inputs
  env.set('ld_inputs', *inputs)
  args = env.get('LD_ARGS') + ['-o', outfile]
  if env.getbool('USE_STDLIB'):
    args += env.get('LD_ARGS_ENTRY')
  args += env.get('LD_FLAGS')
  driver_tools.RunDriver('nativeld', args)
예제 #32
0
def main(argv):
  env.set('ARGS', *argv)
  if filetype.IsLLVMBitcode(argv[1]):
    # Hack to support newlib build.
    # Newlib determines whether the toolchain supports .init_array, etc., by
    # compiling a small test and looking for a specific section tidbit using
    # readelf.  Since pnacl compiles to bitcode, readelf isn't available.
    # TODO(sehr): we may want to implement a whole readelf on bitcode.
    if len(argv) == 2 and argv[0] == '-S':
      print 'INIT_ARRAY'
      return 0
    return 1
  Run('${READELF} ${ARGS}')
  # only reached in case of no errors
  return 0
예제 #33
0
def RunLD(infile, outfile):
  inputs = env.get('INPUTS')
  if infile:
    # Put llc-translated-file at the beginning of the inputs so that it will
    # pull in all needed symbols from any native archives that may also be
    # in the input list. This is in case there are any mixed groups of bitcode
    # and native archives in the link (as is the case with irt_browser_lib)
    inputs.remove('__BITCODE__')
    inputs = ['--llc-translated-file=' + infile] + inputs
  env.set('ld_inputs', *inputs)
  args = env.get('LD_ARGS') + ['-o', outfile]
  if env.getbool('USE_STDLIB'):
    args += env.get('LD_ARGS_ENTRY')
  args += env.get('LD_FLAGS')
  driver_tools.RunDriver('nativeld', args)
예제 #34
0
def RunLD(infile, outfile):
  inputs = env.get('INPUTS')
  if infile:
    inputs = ListReplace(inputs,
                         '__BITCODE__',
                         '--llc-translated-file=' + infile)
  ToggleDefaultCommandlineLD(inputs, infile)
  env.set('ld_inputs', *inputs)
  args = env.get('LD_ARGS') + ['-o', outfile]
  if not env.getbool('SHARED') and env.getbool('STDLIB'):
    args += env.get('LD_ARGS_ENTRY')
  args += env.get('LD_FLAGS')
  # If there is bitcode, there is also a metadata file.
  if infile and env.getbool('USE_META'):
    args += ['--metadata', '%s.meta' % infile]
  driver_tools.RunDriver('nativeld', args)
예제 #35
0
파일: pnacl-ar.py 프로젝트: mYoda/CustomBrs
def main(argv):
    if len(argv) == 0:
        print get_help(argv)
        return 1

    env.update(EXTRA_ENV)
    driver_tools.ParseArgs(argv, PATTERNS)

    # Note: --plugin must come after the command flags, but before the filename.
    #       (definitely confirmed that it cannot go before the command)
    #       for now assume command is just the very first args
    args = env.get('ARGS')
    command = args.pop(0)
    env.set('COMMAND', command)
    env.set('ARGS', *args)
    driver_tools.Run('"${AR}" ${COMMAND} --plugin=${GOLD_PLUGIN_SO} ${ARGS}')
    # only reached in case of no errors
    return 0
예제 #36
0
def main(argv):
  if len(argv) ==  0:
    print get_help(argv)
    return 1

  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, PATTERNS)

  # Note: --plugin must come after the command flags, but before the filename.
  #       (definitely confirmed that it cannot go before the command)
  #       for now assume command is just the very first args
  args = env.get('ARGS')
  command = args.pop(0)
  env.set('COMMAND', command)
  env.set('ARGS', *args)
  driver_tools.Run('"${AR}" ${COMMAND} --plugin=${GOLD_PLUGIN_SO} ${ARGS}')
  # only reached in case of no errors
  return 0
예제 #37
0
def main(argv):
  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, ASPatterns)
  arch = driver_tools.GetArch()

  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  for path in inputs + [output]:
    driver_tools.CheckPathLength(path)

  num_inputs = len(inputs)
  if num_inputs > 1:
    Log.Fatal('Expecting exactly one input file')
  elif num_inputs == 1:
    the_input = inputs[0]
  else:
    # stdin
    the_input = '-'


  if arch:
    output_type = 'o'
  else:
    output_type = 'po'

  if output == '':
    output = 'a.out'

  env.push()
  env.set('input', the_input)
  env.set('output', output)

  if output_type == 'po':
    # .ll to .po
    driver_tools.Run("${RUN_LLVM_AS}")
  else:
    # .s to .o
    driver_tools.Run("${RUN_LLVM_MC}")
  env.pop()
  # only reached in case of no errors
  return 0
예제 #38
0
def BuildSharedLib():
  # Shared libs must be built PIC
  Env.set('GENERATE_PIC', '1')
  inputs = Env.get('INPUTS')
  if len(inputs) == 0:
    Log.Fatal('No input specified.')
  if not Env.getbool('GENERATE_PIC'):
    Log.Fatal('Shared libs must be build in pic mode. Use -fPIC')
  if Env.getone('SONAME_FLAG') == '':
    Log.Fatal('Shared libs must be given a soname.')

  pso_command = ProcessBuildCommand(BUILD_COMMAND_PSO_FROM_BC)
  DumpCommand("@bc->pso", pso_command)
  # suppress_arch is needed to prevent clang to inherit the
  # -arch argument
  driver_tools.RunDriver('clang', pso_command, suppress_arch=True)

  so_command = ProcessBuildCommand(BUILD_COMMAND_SO_FROM_PSO)
  DumpCommand("@pso->so", so_command)
  driver_tools.RunDriver('translate', so_command)
예제 #39
0
def main(argv):
    env.update(EXTRA_ENV)
    driver_tools.ParseArgs(argv, ASPatterns)
    arch = driver_tools.GetArch()

    inputs = env.get("INPUTS")
    output = env.getone("OUTPUT")

    for path in inputs + [output]:
        driver_tools.CheckPathLength(path)

    num_inputs = len(inputs)
    if num_inputs > 1:
        Log.Fatal("Expecting exactly one input file")
    elif num_inputs == 1:
        the_input = inputs[0]
    else:
        # stdin
        the_input = "-"

    if arch:
        output_type = "o"
    else:
        output_type = "po"

    if output == "":
        output = "a.out"

    env.push()
    env.set("input", the_input)
    env.set("output", output)

    if output_type == "po":
        # .ll to .po
        driver_tools.Run("${RUN_LLVM_AS}")
    else:
        # .s to .o
        driver_tools.Run("${RUN_LLVM_MC}")
    env.pop()
    # only reached in case of no errors
    return 0
예제 #40
0
 def checkLDOptNumRuns(self, bitcode, flags, num_runs):
   """ Given a |bitcode| file the |arch| and additional pnacl-ld |flags|,
   check that opt will only be run |num_runs| times. """
   # TODO(jvoung): Get rid of INHERITED_DRIVER_ARGS, which leaks across runs.
   env.set('INHERITED_DRIVER_ARGS', '')
   temp_output = self.getTemp()
   capture_out = cStringIO.StringIO()
   driver_log.Log.CaptureToStream(capture_out)
   driver_tools.RunDriver('pnacl-ld',
                          ['--pnacl-driver-verbose',
                           '--dry-run',
                           bitcode.name,
                           '-o', temp_output.name] + flags)
   driver_log.Log.ResetStreams()
   out = capture_out.getvalue()
   split_out = out.splitlines()
   count = 0
   for line in split_out:
     if re.search('Running: .*opt( |\.exe)', line):
       count += 1
   self.assertEqual(num_runs, count)
예제 #41
0
def main(argv):
    env.update(EXTRA_ENV)
    driver_tools.ParseArgs(argv, PATTERNS)

    inputs = env.get('INPUTS')

    if len(inputs) == 0:
        Log.Fatal("No input files given")

    for infile in inputs:
        env.push()
        env.set('input', infile)

        # For frozen PNaCl bitcode, use 'llvm-nm -bitcode-format=pnacl'. For all
        # other formats, use the binutils nm with our gold plugin.
        if filetype.IsPNaClBitcode(infile):
            env.set('TOOLNAME', '${LLVM_NM}')
            env.append('FLAGS', '-bitcode-format=pnacl')
        else:
            env.set('TOOLNAME', '${NM}')
            env.append('FLAGS', '--plugin=${GOLD_PLUGIN_SO}')

        driver_tools.Run('"${TOOLNAME}" ${FLAGS} ${input}')
        env.pop()

    # only reached in case of no errors
    return 0
예제 #42
0
def main(argv):
  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, PATTERNS)

  inputs = env.get('INPUTS')

  if len(inputs) == 0:
    Log.Fatal("No input files given")

  for infile in inputs:
    env.push()
    env.set('input', infile)

    # For frozen PNaCl bitcode, use 'llvm-nm -bitcode-format=pnacl'. For all
    # other formats, use the binutils nm with our gold plugin.
    if filetype.IsPNaClBitcode(infile):
      env.set('TOOLNAME', '${LLVM_NM}')
      env.append('FLAGS', '-bitcode-format=pnacl')
    else:
      env.set('TOOLNAME', '${NM}')
      env.append('FLAGS', '--plugin=${GOLD_PLUGIN_SO}')

    driver_tools.Run('"${TOOLNAME}" ${FLAGS} ${input}')
    env.pop()

  # only reached in case of no errors
  return 0
예제 #43
0
def main(argv):
    env.update(EXTRA_ENV)
    driver_tools.ParseArgs(argv, DISPatterns)

    inputs = env.get('INPUTS')
    output = env.getone('OUTPUT')

    if len(inputs) == 0:
        Log.Fatal("No input files given")

    if len(inputs) > 1 and output != '':
        Log.Fatal("Cannot have -o with multiple inputs")

    for infile in inputs:
        env.push()
        env.set('input', infile)
        env.set('output', output)

        # When we output to stdout, set redirect_stdout and set log_stdout
        # to False to bypass the driver's line-by-line handling of stdout
        # which is extremely slow when you have a lot of output

        if (filetype.IsLLVMBitcode(infile) or filetype.IsPNaClBitcode(infile)):
            bitcodetype = 'PNaCl' if filetype.IsPNaClBitcode(
                infile) else 'LLVM'
            format = bitcodetype.lower()

            if env.has('FILE_TYPE'):
                sys.stdout.write('%s: %s bitcode\n' % (infile, bitcodetype))
                continue
            env.append('FLAGS', '-bitcode-format=' + format)
            if output == '':
                # LLVM by default outputs to a file if -o is missing
                # Let's instead output to stdout
                env.set('output', '-')
                env.append('FLAGS', '-f')
            driver_tools.Run('${LLVM_DIS} ${FLAGS} ${input} -o ${output}')
        elif filetype.IsELF(infile):
            if env.has('FILE_TYPE'):
                sys.stdout.write('%s: ELF\n' % infile)
                continue
            flags = env.get('FLAGS')
            if len(flags) == 0:
                env.append('FLAGS', '-d')
            if output == '':
                # objdump to stdout
                driver_tools.Run('"${OBJDUMP}" ${FLAGS} ${input}')
            else:
                # objdump always outputs to stdout, and doesn't recognize -o
                # Let's add this feature to be consistent.
                fp = DriverOpen(output, 'w')
                driver_tools.Run('${OBJDUMP} ${FLAGS} ${input}',
                                 redirect_stdout=fp)
                DriverClose(fp)
        else:
            Log.Fatal('Unknown file type')
        env.pop()
    # only reached in case of no errors
    return 0
예제 #44
0
def main(argv):
  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, ASPatterns)
  arch = driver_tools.GetArch()

  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  num_inputs = len(inputs)
  if num_inputs > 1:
    Log.Fatal('Expecting exactly one input file')
  elif num_inputs == 1:
    the_input = inputs[0]
  else:
    # stdin
    the_input = '-'


  if arch:
    output_type = 'o'
  else:
    output_type = 'po'

  if output == '':
    output = 'a.out'

  env.push()
  env.set('input', the_input)
  env.set('output', output)

  if output_type == 'po':
    # .ll to .po
    driver_tools.Run("${RUN_LLVM_AS}")
  else:
    # .s to .o
    driver_tools.Run("${RUN_LLVM_MC}")
  env.pop()
  # only reached in case of no errors
  return 0
예제 #45
0
def main(argv):
  env.update(EXTRA_ENV)
  driver_tools.ParseArgs(argv, DISPatterns)

  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  if len(inputs) == 0:
    Log.Fatal("No input files given")

  if len(inputs) > 1 and output != '':
    Log.Fatal("Cannot have -o with multiple inputs")

  for infile in inputs:
    env.push()
    env.set('input', infile)
    env.set('output', output)

    # When we output to stdout, set redirect_stdout and set log_stdout
    # to False to bypass the driver's line-by-line handling of stdout
    # which is extremely slow when you have a lot of output

    if (filetype.IsLLVMBitcode(infile) or
        filetype.IsPNaClBitcode(infile)):
      bitcodetype = 'PNaCl' if filetype.IsPNaClBitcode(infile) else 'LLVM'
      format = bitcodetype.lower()

      if env.has('FILE_TYPE'):
        sys.stdout.write('%s: %s bitcode\n' % (infile, bitcodetype))
        continue
      env.append('FLAGS', '-bitcode-format=' + format)
      if output == '':
        # LLVM by default outputs to a file if -o is missing
        # Let's instead output to stdout
        env.set('output', '-')
        env.append('FLAGS', '-f')
      driver_tools.Run('${LLVM_DIS} ${FLAGS} ${input} -o ${output}')
    elif filetype.IsELF(infile):
      if env.has('FILE_TYPE'):
        sys.stdout.write('%s: ELF\n' % infile)
        continue
      flags = env.get('FLAGS')
      if len(flags) == 0:
        env.append('FLAGS', '-d')
      if output == '':
        # objdump to stdout
        driver_tools.Run('"${OBJDUMP}" ${FLAGS} ${input}')
      else:
        # objdump always outputs to stdout, and doesn't recognize -o
        # Let's add this feature to be consistent.
        fp = DriverOpen(output, 'w')
        driver_tools.Run('${OBJDUMP} ${FLAGS} ${input}', redirect_stdout=fp)
        DriverClose(fp)
    else:
      Log.Fatal('Unknown file type')
    env.pop()
  # only reached in case of no errors
  return 0
예제 #46
0
def DriverMain(module, argv):
  # TODO(robertm): this is ugly - try to get rid of this
  if '--pnacl-driver-verbose' in argv:
    Log.IncreaseVerbosity()
    env.set('LOG_VERBOSE', '1')

  # driver_path has the form: /foo/bar/pnacl_root/newlib/bin/pnacl-clang
  driver_path = pathtools.abspath(pathtools.normalize(argv[0]))
  driver_bin = pathtools.dirname(driver_path)
  script_name = pathtools.basename(driver_path)
  env.set('SCRIPT_NAME', script_name)
  env.set('DRIVER_PATH', driver_path)
  env.set('DRIVER_BIN', driver_bin)

  Log.SetScriptName(script_name)

  ReadConfig()

  if IsWindowsPython():
    SetupCygwinLibs()

  # skip tool name
  argv = argv[1:]

  # Handle help info
  if ('--help' in argv or
      '-h' in argv or
      '-help' in argv or
      '--help-full' in argv):
    help_func = getattr(module, 'get_help', None)
    if not help_func:
      Log.Fatal(HelpNotAvailable())
    helpstr = help_func(argv)
    print helpstr
    return 0

  return module.main(argv)
예제 #47
0
def SetTarget(*args):
  arch = ParseTriple(args[0])
  env.set('FRONTEND_TRIPLE', args[0])
  AddLDFlag('--target=' + args[0])
예제 #48
0
def AddDiagnosticFlag(*args):
  env.append('CC_FLAGS', *args)
  env.set('DIAGNOSTIC', '1')
예제 #49
0
def main(argv):
    env.update(EXTRA_ENV)
    CheckSetup()
    ParseArgs(argv, CustomPatterns + GCCPatterns)

    # "configure", especially when run as part of a toolchain bootstrap
    # process, will invoke gcc with various diagnostic options and
    # parse the output. In these cases we do not alter the incoming
    # commandline. It is also important to not emit spurious messages.
    if env.getbool('DIAGNOSTIC'):
        if env.getbool('SHOW_VERSION'):
            code, stdout, stderr = Run(env.get('CC') + env.get('CC_FLAGS'),
                                       redirect_stdout=subprocess.PIPE)
            out = stdout.split('\n')
            nacl_version = ReadDriverRevision()
            out[0] += ' nacl-version=%s' % nacl_version
            stdout = '\n'.join(out)
            print stdout,
        else:
            Run(env.get('CC') + env.get('CC_FLAGS'))
        return 0

    unmatched = env.get('UNMATCHED')
    if len(unmatched) > 0:
        UnrecognizedOption(*unmatched)

    # 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 not env.get('STDLIB'):
        # Default C++ Standard Library.
        SetStdLib('libc++')

    inputs = env.get('INPUTS')
    output = env.getone('OUTPUT')

    if len(inputs) == 0:
        if env.getbool('VERBOSE'):
            # -v can be invoked without any inputs. Runs the original
            # command without modifying the commandline for this case.
            Run(env.get('CC') + env.get('CC_FLAGS'))
            return 0
        else:
            Log.Fatal('No input files')

    gcc_mode = env.getone('GCC_MODE')
    output_type = DriverOutputTypes(gcc_mode, compiling_to_native)
    needs_linking = (gcc_mode == '')

    if env.getbool('NEED_DASH_E') and gcc_mode != '-E':
        Log.Fatal("-E or -x required when input is from stdin")

    # There are multiple input files and no linking is being done.
    # There will be multiple outputs. Handle this case separately.
    if not needs_linking:
        # Filter out flags
        inputs = [f for f in inputs if not IsFlag(f)]
        if output != '' and len(inputs) > 1:
            Log.Fatal(
                'Cannot have -o with -c, -S, or -E and multiple inputs: %s',
                repr(inputs))

        for f in inputs:
            if IsFlag(f):
                continue
            intype = filetype.FileType(f)
            if not filetype.IsSourceType(intype):
                if ((output_type == 'pp' and intype != 'S')
                        or (output_type == 'll')
                        or (output_type == 'po' and intype != 'll') or
                    (output_type == 's' and intype not in ('ll', 'po', 'S'))
                        or (output_type == 'o'
                            and intype not in ('ll', 'po', 'S', 's'))):
                    Log.Fatal("%s: Unexpected type of file for '%s'",
                              pathtools.touser(f), gcc_mode)

            if output == '':
                f_output = DefaultOutputName(f, output_type)
            else:
                f_output = output

            namegen = TempNameGen([f], f_output)
            CompileOne(f, output_type, namegen, f_output)
        return 0

    # Linking case
    assert (needs_linking)
    assert (output_type in ('pso', 'so', 'pexe', 'nexe'))

    if output == '':
        output = pathtools.normalize('a.out')
    namegen = TempNameGen(inputs, output)

    # Compile all source files (c/c++/ll) to .po
    for i in xrange(0, len(inputs)):
        if IsFlag(inputs[i]):
            continue
        intype = filetype.FileType(inputs[i])
        if filetype.IsSourceType(intype) or intype == 'll':
            inputs[i] = CompileOne(inputs[i], 'po', namegen)

    # Compile all .s/.S to .o
    if env.getbool('ALLOW_NATIVE'):
        for i in xrange(0, len(inputs)):
            if IsFlag(inputs[i]):
                continue
            intype = filetype.FileType(inputs[i])
            if intype in ('s', 'S'):
                inputs[i] = CompileOne(inputs[i], 'o', namegen)

    # We should only be left with .po and .o and libraries
    for f in inputs:
        if IsFlag(f):
            continue
        intype = filetype.FileType(f)
        if intype in ('o', 's', 'S') or filetype.IsNativeArchive(f):
            if not env.getbool('ALLOW_NATIVE'):
                Log.Fatal(
                    '%s: Native object files not allowed in link. '
                    'Use --pnacl-allow-native to override.',
                    pathtools.touser(f))
        assert (intype in ('po', 'o', 'so', 'ldscript')
                or filetype.IsArchive(f))

    # Fix the user-specified linker arguments
    ld_inputs = []
    for f in inputs:
        if f.startswith('-Xlinker='):
            ld_inputs.append(f[len('-Xlinker='):])
        elif f.startswith('-Wl,'):
            ld_inputs += f[len('-Wl,'):].split(',')
        else:
            ld_inputs.append(f)

    if env.getbool('ALLOW_NATIVE'):
        ld_inputs.append('--pnacl-allow-native')

    # Invoke the linker
    env.set('ld_inputs', *ld_inputs)

    ld_args = env.get('LD_ARGS')
    ld_flags = env.get('LD_FLAGS')

    RunDriver('ld', ld_flags + ld_args + ['-o', output])
    return 0
예제 #50
0
def AddVersionFlag(*args):
    env.set('SHOW_VERSION', '1')
    AddDiagnosticFlag(*args)
예제 #51
0
def SetTarget(*args):
    arch = ParseTriple(args[0])
    env.set('FRONTEND_TRIPLE', args[0])
    AddLDFlag('--target=' + args[0])
예제 #52
0
def AddDiagnosticFlag(*args):
    env.append('CC_FLAGS', *args)
    env.set('DIAGNOSTIC', '1')
예제 #53
0
파일: pnacl-ld.py 프로젝트: subhanshuja/ofa
def SetLibTarget(*args):
  arch = ParseTriple(args[0])
  if arch != 'le32':
    env.set('BCLIB_ARCH', arch)
예제 #54
0
def AddVersionFlag(*args):
  env.set('SHOW_VERSION', '1')
  AddDiagnosticFlag(*args)
 def setUp(self):
   super(TestFixPrivateLibs, self).setUp()
   driver_test_utils.ApplyTestEnvOverrides(env)
   env.set('USE_IRT', '1')
예제 #56
0
def main(argv):
  env.update(EXTRA_ENV)
  CheckSetup()
  ParseArgs(argv, CustomPatterns + GCCPatterns)

  # "configure", especially when run as part of a toolchain bootstrap
  # process, will invoke gcc with various diagnostic options and
  # parse the output. In these cases we do not alter the incoming
  # commandline. It is also important to not emit spurious messages.
  if env.getbool('DIAGNOSTIC'):
    if env.getbool('SHOW_VERSION'):
      code, stdout, stderr = Run(env.get('CC') + env.get('CC_FLAGS'),
                                 redirect_stdout=subprocess.PIPE)
      out = stdout.split('\n')
      nacl_version = ReadDriverRevision()
      out[0] += ' nacl-version=%s' % nacl_version
      stdout = '\n'.join(out)
      print stdout,
    else:
      Run(env.get('CC') + env.get('CC_FLAGS'))
    return 0

  unmatched = env.get('UNMATCHED')
  if len(unmatched) > 0:
    UnrecognizedOption(*unmatched)

  # 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 not env.get('STDLIB'):
    # Default C++ Standard Library.
    SetStdLib('libc++')

  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  if len(inputs) == 0:
    if env.getbool('VERBOSE'):
      # -v can be invoked without any inputs. Runs the original
      # command without modifying the commandline for this case.
      Run(env.get('CC') + env.get('CC_FLAGS'))
      return 0
    else:
      Log.Fatal('No input files')

  gcc_mode = env.getone('GCC_MODE')
  output_type = DriverOutputTypes(gcc_mode, compiling_to_native)
  needs_linking = (gcc_mode == '')

  if env.getbool('NEED_DASH_E') and gcc_mode != '-E':
    Log.Fatal("-E or -x required when input is from stdin")

  # There are multiple input files and no linking is being done.
  # There will be multiple outputs. Handle this case separately.
  if not needs_linking:
    # Filter out flags
    inputs = [f for f in inputs if not IsFlag(f)]
    if output != '' and len(inputs) > 1:
      Log.Fatal('Cannot have -o with -c, -S, or -E and multiple inputs: %s',
                repr(inputs))

    for f in inputs:
      if IsFlag(f):
        continue
      intype = filetype.FileType(f)
      if not filetype.IsSourceType(intype):
        if ((output_type == 'pp' and intype != 'S') or
            (output_type == 'll') or
            (output_type == 'po' and intype != 'll') or
            (output_type == 's' and intype not in ('ll','po','S')) or
            (output_type == 'o' and intype not in ('ll','po','S','s'))):
          Log.Fatal("%s: Unexpected type of file for '%s'",
                    pathtools.touser(f), gcc_mode)

      if output == '':
        f_output = DefaultOutputName(f, output_type)
      else:
        f_output = output

      namegen = TempNameGen([f], f_output)
      CompileOne(f, output_type, namegen, f_output)
    return 0

  # Linking case
  assert(needs_linking)
  assert(output_type in ('pso','so','pexe','nexe'))

  if output == '':
    output = pathtools.normalize('a.out')
  namegen = TempNameGen(inputs, output)

  # Compile all source files (c/c++/ll) to .po
  for i in xrange(0, len(inputs)):
    if IsFlag(inputs[i]):
      continue
    intype = filetype.FileType(inputs[i])
    if filetype.IsSourceType(intype) or intype == 'll':
      inputs[i] = CompileOne(inputs[i], 'po', namegen)

  # Compile all .s/.S to .o
  if env.getbool('ALLOW_NATIVE'):
    for i in xrange(0, len(inputs)):
      if IsFlag(inputs[i]):
        continue
      intype = filetype.FileType(inputs[i])
      if intype in ('s','S'):
        inputs[i] = CompileOne(inputs[i], 'o', namegen)

  # We should only be left with .po and .o and libraries
  for f in inputs:
    if IsFlag(f):
      continue
    intype = filetype.FileType(f)
    if intype in ('o','s','S') or filetype.IsNativeArchive(f):
      if not env.getbool('ALLOW_NATIVE'):
        Log.Fatal('%s: Native object files not allowed in link. '
                  'Use --pnacl-allow-native to override.', pathtools.touser(f))
    assert(intype in ('po','o','so','ldscript') or filetype.IsArchive(f))

  # Fix the user-specified linker arguments
  ld_inputs = []
  for f in inputs:
    if f.startswith('-Xlinker='):
      ld_inputs.append(f[len('-Xlinker='):])
    elif f.startswith('-Wl,'):
      ld_inputs += f[len('-Wl,'):].split(',')
    else:
      ld_inputs.append(f)

  if env.getbool('ALLOW_NATIVE'):
    ld_inputs.append('--pnacl-allow-native')

  # Invoke the linker
  env.set('ld_inputs', *ld_inputs)

  ld_args = env.get('LD_ARGS')
  ld_flags = env.get('LD_FLAGS')

  RunDriver('ld', ld_flags + ld_args + ['-o', output])
  return 0
예제 #57
0
파일: pnacl-ld.py 프로젝트: subhanshuja/ofa
def main(argv):
  env.update(EXTRA_ENV)
  ParseArgs(argv, LDPatterns)
  # If the user passed -arch, then they want native output.
  arch_flag_given = GetArch() is not None

  # Both LD_FLAGS_NATIVE and TRANSLATE_FLAGS_USER affect
  # the translation process. If they are non-empty,
  # then --pnacl-allow-native must be given.
  allow_native = env.getbool('ALLOW_NATIVE')
  native_flags = env.get('LD_FLAGS_NATIVE') + env.get('TRANSLATE_FLAGS_USER')
  if len(native_flags) > 0:
    if not allow_native:
      flagstr = ' '.join(native_flags)
      Log.Fatal('"%s" affects translation. '
                'To allow, specify --pnacl-allow-native' % flagstr)

  if allow_native:
    if not arch_flag_given:
      Log.Fatal("--pnacl-allow-native given, but translation "
                "is not happening (missing -arch?)")
    if env.getbool('SHARED'):
      Log.Fatal('Native shared libraries are not supported with pnacl-ld.')

  if env.getbool('SHARED'):
    if env.getbool('RELOCATABLE'):
      Log.Fatal('-r/-relocatable and -shared may not be passed together.')
    env.set('RELOCATABLE', '1')

  # Overriding the lib target uses native-flavored bitcode libs rather than the
  # portable bitcode libs. It is currently only tested/supported for
  # building the IRT.
  if not IsPortable():
    env.set('BASE_USR', "${BASE_USR_ARCH}")
    env.set('BASE_LIB', "${BASE_LIB_ARCH}")

  if env.getbool('RELOCATABLE'):
    env.set('STATIC', '0')

  inputs = env.get('INPUTS')
  output = env.getone('OUTPUT')

  if output == '':
    output = pathtools.normalize('a.out')

  if not arch_flag_given:
    # If -arch is not given, assume X86-32.
    # This is because gold requires an arch (even for bitcode linking).
    SetArch('X8632')
  assert(GetArch() is not None)

  inputs = FixPrivateLibs(inputs)

  # Expand all parameters
  # This resolves -lfoo into actual filenames,
  # and expands linker scripts into command-line arguments.
  inputs = ldtools.ExpandInputs(inputs,
                                env.get('SEARCH_DIRS'),
                                env.getbool('STATIC'),
                                # Once all glibc bitcode link is purely
                                # bitcode (e.g., even libc_nonshared.a)
                                # we may be able to restrict this more.
                                # This is also currently used by
                                # pnacl_generate_pexe=0 with glibc,
                                # for user libraries.
                                ldtools.LibraryTypes.ANY)
  plls, inputs = FilterPlls(inputs)
  plls = [os.path.basename(pll) for pll in plls]

  if not env.getbool('SHARED') and plls != []:
    Log.Fatal('Passing a PLL to the linker requires the "-shared" option.')

  # Make sure the inputs have matching arch.
  CheckInputsArch(inputs)

  regular_inputs, native_objects = SplitLinkLine(inputs)

  if env.getbool('RELOCATABLE'):
    bitcode_type = 'po'
    native_type = 'o'
  else:
    bitcode_type = 'pexe'
    native_type = 'nexe'

  if native_objects and not allow_native:
    argstr = ' '.join(native_objects)
    Log.Fatal("Native objects '%s' detected in the link. "
              "To allow, specify --pnacl-allow-native" % argstr)

  tng = TempNameGen([], output)

  # Do the bitcode link.
  if HasBitcodeInputs(inputs):
    chain = DriverChain(inputs, output, tng)
    chain.add(LinkBC, 'pre_opt.' + bitcode_type)

    # Some ABI simplification passes assume the whole program is
    # available (e.g. -expand-varargs, -nacl-expand-ctors and
    # -nacl-expand-tls).  While we could try running a subset of
    # simplification passes when linking native objects, we don't
    # do this because it complicates testing.  For example,
    # it requires '-expand-constant-expr' to be able to handle
    # 'landingpad' instructions.
    # However, if we aren't using biased bitcode, then at least -expand-byval
    # must be run to work with the PPAPI shim calling convention, and
    # -expand-varargs is needed because after LLVM 3.5 the x86-32 backend does
    # not expand the llvm.va_arg intrinsic correctly.
    # (see https://code.google.com/p/nativeclient/issues/detail?id=3913#c24)
    abi_simplify = (env.getbool('STATIC') and
                    len(native_objects) == 0 and
                    not env.getbool('ALLOW_NEXE_BUILD_ID') and
                    IsPortable())
    still_need_expand_byval = IsPortable() and env.getbool('STATIC')
    still_need_expand_varargs = (still_need_expand_byval and
                                 len(native_objects) == 0)

    # A list of groups of args. Each group should contain a pass to run
    # along with relevant flags that go with that pass.
    opt_args = []
    if env.getbool('SHARED'):
      pre_simplify_shared = [
        # The following is a subset of "-pnacl-abi-simplify-preopt".  We don't
        # want to run the full "-pnacl-abi-simplify-preopt" because it
        # internalizes symbols that we want to export via "-convert-to-pso".
        '-nacl-global-cleanup',
        '-expand-varargs',
        '-rewrite-pnacl-library-calls',
        '-rewrite-llvm-intrinsic-calls',
        '-convert-to-pso',
      ]
      # ConvertToPso takes a list of comma-separated PLL dependencies as an
      # argument.
      if plls != []:
        pre_simplify_shared += ['-convert-to-pso-deps=' + ','.join(plls)]
      opt_args.append(pre_simplify_shared)
      # Post-opt is required, since '-convert-to-pso' adds metadata which must
      # be simplified before finalization. Additionally, all functions must be
      # simplified in the post-opt passes.
      abi_simplify = True
    elif abi_simplify:
      pre_simplify = ['-pnacl-abi-simplify-preopt']
      if env.getone('CXX_EH_MODE') == 'sjlj':
        pre_simplify += ['-enable-pnacl-sjlj-eh']
      else:
        assert env.getone('CXX_EH_MODE') == 'none'
      opt_args.append(pre_simplify)
    else:
      # '-lowerinvoke' prevents use of C++ exception handling, which
      # is not yet supported in the PNaCl ABI.  '-simplifycfg' removes
      # landingpad blocks made unreachable by '-lowerinvoke'.
      #
      # We run this in order to remove 'resume' instructions,
      # otherwise these are translated to calls to _Unwind_Resume(),
      # which will not be available at native link time.
      opt_args.append(['-lowerinvoke', '-simplifycfg'])
      if still_need_expand_varargs:
        opt_args.append(['-expand-varargs'])

    if env.getone('OPT_LEVEL') != '' and env.getone('OPT_LEVEL') != '0':
      opt_args.append(env.get('OPT_FLAGS'))
    if env.getone('STRIP_MODE') != 'none':
      opt_args.append(env.get('STRIP_FLAGS'))

    if abi_simplify:
      post_simplify = ['-pnacl-abi-simplify-postopt']
      if not env.getbool('DISABLE_ABI_CHECK'):
        post_simplify += [
            '-verify-pnaclabi-module',
            '-verify-pnaclabi-functions',
            # A flag for the above -verify-pnaclabi-* passes.
            '-pnaclabi-allow-debug-metadata']
      opt_args.append(post_simplify)
    elif still_need_expand_byval:
      # We may still need -expand-byval to match the PPAPI shim
      # calling convention.
      opt_args.append(['-expand-byval'])
    if len(opt_args) != 0:
      if env.getbool('RUN_PASSES_SEPARATELY'):
        for i, group in enumerate(opt_args):
          chain.add(DoLLVMPasses(group),
                    'simplify_%d.%s' % (i, bitcode_type))
      else:
        flattened_opt_args = [flag for group in opt_args for flag in group]
        chain.add(DoLLVMPasses(flattened_opt_args),
                  'simplify_and_opt.' + bitcode_type)
  else:
    chain = DriverChain('', output, tng)

  if env.getbool('FINALIZE'):
    chain.add(DoFinalize, 'finalize.' + bitcode_type)

  # If -arch is also specified, invoke pnacl-translate afterwards.
  if arch_flag_given:
    env.set('NATIVE_OBJECTS', *native_objects)
    chain.add(DoTranslate, native_type)

  chain.run()

  if bitcode_type == 'pexe' and not arch_flag_given:
    # Mark .pexe files as executable.
    # Some versions of 'configure' expect this.
    SetExecutableMode(output)
  return 0