Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / pnacl_dynamic_loading / nacl.scons
1 # -*- python -*-
2 # Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 Import('env')
7
8 if not env.Bit('bitcode'):
9   Return()
10 if env['TOOLCHAIN_FEATURE_VERSION'] < 6:
11   Return()
12 # Translating the PSO to an ELF DSO doesn't work on x86-64 yet.  The
13 # Gold linker complains that the input "requires dynamic R_X86_64_32
14 # reloc against <blah> which may overflow at runtime".  (In contrast,
15 # the BFD linker in the glibc toolchain does handle this relocation.)
16 # TODO(mseaborn): Fix this and enable the test for x86-64.
17 if env.Bit('target_x86_64'):
18   Return()
19 # The sandboxed translator does not support translating PSOs yet.
20 if env.Bit('use_sandboxed_translator'):
21   Return()
22 # The PNaCl dynamic loader currently only supports SFI NaCl's memory layout.
23 if env.Bit('nonsfi_nacl'):
24   Return()
25
26
27 def MakeAndTranslatePso(dest, bitcode_file, do_simplify):
28   # Run opt to apply PNaCl ABI simplifications to the IR and to run the
29   # PNaCl ABI checker.  We are bypassing pnacl-ld for now because its
30   # invocation of Gold internalizes __pnacl_pso_root, which we want to keep
31   # externally-visible.
32   passes = ''
33   if do_simplify:
34     passes = '-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt '
35   opt_result = env.Command(
36       dest + '.nonfinal.pso', [bitcode_file],
37       '${PNACLOPT} ' + passes +
38       '-verify-pnaclabi-module -verify-pnaclabi-functions '
39       '-pnaclabi-allow-debug-metadata '
40       '${SOURCES} -o ${TARGET}')
41   # Finalize to strip debugging info and to emit PNaCl bitcode.
42   finalized_result = env.Command(
43       dest + '.final.pso', [opt_result],
44       '${PNACLFINALIZE} ${SOURCES} -o ${TARGET}')
45   # Translate to an ELF loadable object.
46   translated_dso = env.Command(dest + '.so', [finalized_result],
47                                '${TRANSLATE} -pso ${SOURCES} -o ${TARGET}')
48   return translated_dso
49
50
51 def PsoFromLLVMAssembly(base_name):
52   bitcode_file = env.Command(
53       '%s.bc' % base_name, ['%s.ll' % base_name],
54       [Action('${ASCOM}', '${ASCOMSTR}')])
55   return MakeAndTranslatePso(base_name, [bitcode_file],
56                              # Skip PNaCl passes because they add TLS functions.
57                              do_simplify=False)
58
59
60 dso1 = MakeAndTranslatePso('test_pso', [env.ComponentObject('test_pso.c')],
61                            do_simplify=True)
62 dso2 = PsoFromLLVMAssembly('data_only_pso')
63 dso3 = PsoFromLLVMAssembly('data_only_pso_largebss')
64
65 dynloader_test = env.ComponentProgram(
66     'dynloader_test', ['dynloader_test.c'],
67     EXTRA_LIBS=['${NONIRT_LIBS}', 'pnacl_dynloader', 'platform'])
68
69 node = env.CommandSelLdrTestNacl(
70     'dynloader_test.out', dynloader_test, [dso1, dso2, dso3],
71     # Add '-a' to enable filesystem access for opening DSOs.
72     sel_ldr_flags=['-a'])
73 env.AddNodeToTestSuite(
74     node, ['small_tests', 'toolchain_tests'],
75     'run_pnacl_dynamic_loading_test',
76     # The loader currently depends on the allocate_code_data() interface
77     # provided by the IRT.
78     is_broken=not env.Bit('tests_use_irt'))