Exemplo n.º 1
0
    def test_compile_native_objects(self):
        s = self.getFakeSourceFile()
        with self.getTemp(suffix='.o') as obj:
            # TODO(dschuff): Use something more descriptive instead of -arch
            # (i.e. something that indicates that a translation is requested)
            # and remove pnacl-allow-translate
            driver_tools.RunDriver('clang', [
                s.name, '-c', '-o', obj.name, '--target=x86_64-unknown-nacl',
                '-arch', 'x86-64', '--pnacl-allow-translate'
            ])
            self.assertTrue(filetype.IsNativeObject(obj.name))
            self.assertEqual(elftools.GetELFHeader(obj.name).arch, 'X8664')

            driver_tools.RunDriver('clang', [
                s.name, '-c', '-o', obj.name, '--target=i686-unknown-nacl',
                '-arch', 'x86-32', '--pnacl-allow-translate'
            ])
            self.assertTrue(filetype.IsNativeObject(obj.name))
            self.assertEqual(elftools.GetELFHeader(obj.name).arch, 'X8632')

            driver_tools.RunDriver('clang', [
                s.name, '-c', '-o', obj.name,
                '--target=armv7-unknown-nacl-gnueabi', '-arch', 'arm',
                '--pnacl-allow-translate'
            ])
            self.assertTrue(filetype.IsNativeObject(obj.name))
            self.assertEqual(elftools.GetELFHeader(obj.name).arch, 'ARM')

            # TODO(dschuff): This should be an error.
            driver_tools.RunDriver('clang', [
                s.name, '-c', '-o', obj.name, '--target=x86_64-unknown-nacl',
                '-arch', 'x86-32', '--pnacl-allow-translate'
            ])
            self.assertTrue(filetype.IsNativeObject(obj.name))
            self.assertEqual(elftools.GetELFHeader(obj.name).arch, 'X8632')
Exemplo n.º 2
0
def SplitLinkLine(inputs):
    """ Split the input list into bitcode and native objects (.o, .a)
  """
    normal = []
    native = []
    # Group flags need special handling because they need to go into the right
    # list based on the type of the inputs in the group. If the group has both
    # native and bitcode files (which is unfortunately the case for
    # irt_browser_lib) then the group flags need to go in both lists.
    if '--start-group' in inputs:
        start_group = inputs.index('--start-group')
        # Start with the inputs before the first group
        normal, native = SplitLinkLine(inputs[:start_group])
        try:
            end_group = inputs.index('--end-group')
        except ValueError:
            Log.Fatal("Found --start-group without matching --end-group")
        # Add the contents of the group together with the --{start,end}-group flags
        norm_group, native_group = SplitLinkLine(inputs[start_group +
                                                        1:end_group])
        if len(norm_group) > 0:
            normal.extend(['--start-group'] + norm_group + ['--end-group'])
        if len(native_group) > 0:
            native.extend(['--start-group'] + native_group + ['--end-group'])
        # Add the inputs after the first group
        norm_last, native_last = SplitLinkLine(inputs[end_group + 1:])
        return normal + norm_last, native + native_last

    # If no groups, split the inputs based on their type.
    for f in inputs:
        if ldtools.IsFlag(f):
            normal.append(f)
        elif filetype.IsNativeArchive(f) or filetype.IsNativeObject(f):
            native.append(f)
        else:
            normal.append(f)
    return (normal, native)