2 # Copyright (c) 2013 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.
8 # This test only tests PNaCl's nonpexe mode with native object files/archives
9 if not env.Bit('bitcode') or env.Bit('pnacl_generate_pexe'):
12 # This file fails with "--mode=dbg-host,nacl,nacl_irt_test
13 # pnacl_generate_pexe=0 bitcode=1", so disable it for that case.
14 # TODO(uekawa): Investigate why this fails in that case and re-enable.
15 if env.Bit('tests_use_irt'):
20 bc_env.Replace(CCFLAGS=[], LINKFLAGS=[])
21 bc_env.Append(EXTRA_LIBS=['${NONIRT_LIBS}'])
22 native_env = env.Clone()
23 native_env.Replace(CCFLAGS=[], LINKFLAGS=[])
24 native_env.PNaClForceNative()
25 native_env.Append(EXTRA_LIBS=['${NONIRT_LIBS}'])
27 # The main object depends on symbols found in lib a and lib b (sym_a and sym_b).
28 # Lib a also depends on a sym_b2 which is also in lib b, but in a different
29 # object than sym_b. (This means that putting b first will fail unless they are
32 bc_a = bc_env.ComponentObject('sym_a', ['sym_a.c'])
33 bc_b = bc_env.ComponentObject('sym_b', ['sym_b.c'])
34 bc_b2 = bc_env.ComponentObject('sym_b2', ['sym_b2.c'])
35 bclib_a = bc_env.Replicate("${LIB_DIR}",
36 bc_env.ComponentLibrary('bcsym_a', [bc_a]))
37 bclib_b = bc_env.Replicate("${LIB_DIR}",
38 bc_env.ComponentLibrary('bcsym_b', [bc_b, bc_b2]))
39 bc_main = bc_env.ComponentObject('main', ['main.c'])
41 native_a = native_env.ComponentObject('sym_a', ['sym_a.c'])
42 native_b = native_env.ComponentObject('sym_b', ['sym_b.c'])
43 native_b2 = native_env.ComponentObject('sym_b2', ['sym_b2.c'])
44 nativelib_a = native_env.Replicate(
46 native_env.ComponentLibrary('nativesym_a', [native_a]))
47 nativelib_b = native_env.Replicate(
49 native_env.ComponentLibrary('nativesym_b', [native_b, native_b2]))
50 native_main = native_env.ComponentObject('main', ['main.c'])
53 # Test with both archives as bitcode
54 both_env = native_env.Clone()
55 # _LIBFLAGS is the internal scons variable that gets the libs flags like -lfoo.
56 # Because it takes the LIBS and prepends -l to them, there is no way to insert
57 # flags like -Wl,--start-group (also the LINKFLAGS come before the main object
58 # so sneaking libs in there is no good either)
59 both_env.Append(_LIBFLAGS=['-lbcsym_a', '-lbcsym_b'])
60 # Because we can't properly put these libs into EXTRA_LIBS, we have to add them
61 # to IMPLICIT_LIBS to make sure they get built.
62 both_env.Append(IMPLICIT_LIBS=[bclib_a, bclib_b])
63 tests.append(('archive_bitcode',
64 both_env.ComponentProgram('bitcode', [bc_main])))
66 # Link one archive as native, one as bitcode
67 mixed_env = native_env.Clone()
68 mixed_env.Append(_LIBFLAGS=['-lbcsym_a', '-lnativesym_b'])
69 mixed_env.Append(IMPLICIT_LIBS=[bclib_a, nativelib_b])
70 tests.append(('archive_mixed',
71 mixed_env.ComponentProgram('mixed', [bc_main])))
73 # Both archives are bitcode, in a group
74 bcgroup_env = native_env.Clone()
75 bcgroup_env.Append(_LIBFLAGS=['-Wl,--start-group',
76 '-lbcsym_b', '-lbcsym_a',
78 bcgroup_env.Append(IMPLICIT_LIBS=[bclib_a, bclib_b])
79 tests.append(('archive_bitcode_group',
80 bcgroup_env.ComponentProgram('bitcode_group', [bc_main])))
82 # One bitcode, one native, in a group
83 mixedgroup_env = native_env.Clone()
84 mixedgroup_env.Append(_LIBFLAGS=['-Wl,--start-group',
85 '-lbcsym_b', '-lnativesym_a',
87 mixedgroup_env.Append(IMPLICIT_LIBS=[bclib_b, nativelib_a])
88 tests.append(('archive_mixed_group',
89 mixedgroup_env.ComponentProgram('mixed_group', [bc_main])))
91 # One bitcode, one native, in a group (but switch which one is bitcode)
92 mixedgroup_reverse_env = native_env.Clone()
93 mixedgroup_reverse_env.Append(_LIBFLAGS=['-Wl,--start-group',
94 '-lnativesym_b', '-lbcsym_a',
96 mixedgroup_reverse_env.Append(IMPLICIT_LIBS=[bclib_a, nativelib_b])
97 tests.append(('archive_mixed_group_reverse',
98 mixedgroup_reverse_env.ComponentProgram(
99 'mixed_group_reverse', [bc_main])))
102 nativegroup_env = native_env.Clone()
103 nativegroup_env.Append(_LIBFLAGS=['-Wl,--start-group',
104 '-lnativesym_b', '-lnativesym_a',
106 nativegroup_env.Append(IMPLICIT_LIBS=[nativelib_a, nativelib_b])
107 tests.append(('archive_native_group',
108 nativegroup_env.ComponentProgram(
109 'native_group', [native_main])))
113 # Test mixing bitcode and native objects with TLS
114 tls_def_bc = bc_env.ComponentObject('tls_def', ['tls_def.c'])
115 tls_use_bc = bc_env.ComponentObject('tls_use', ['tls_use.c'])
116 tls_def_native = native_env.ComponentObject('tls_def', ['tls_def.c'])
117 tls_use_native = native_env.ComponentObject('tls_use', ['tls_use.c'])
119 tests.append(('tls_all_native',
120 native_env.ComponentProgram(
121 'tls_all_native', [tls_def_native, tls_use_native])))
123 tests.append(('tls_def_native',
124 native_env.ComponentProgram(
125 'tls_def_native', [tls_def_native, tls_use_bc])))
127 tests.append(('tls_use_native',
128 native_env.ComponentProgram(
129 'tls_use_native', [tls_use_native, tls_def_bc])))
132 for name, prog in tests:
133 node = env.CommandSelLdrTestNacl(name + '.out', prog)
134 env.AddNodeToTestSuite(node, ['small_tests', 'toolchain_tests',
136 'run_' + name + '_test')