Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / toolchain / nacl.scons
1 # -*- python -*-
2 # Copyright (c) 2012 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 # force inclusion of entire library, so that we can validate it
9 # NOTE: This approach does not work for -lc because of tons of
10 #       undefined symbols which would have to be stubbed out
11 DEP_LIBS = ['nacl', 'srpc', 'imc_syscalls', 'platform', 'gio', 'pthread', 'm']
12
13 # -lgcc is not exposed to the bitcode in PNaCl
14 if env.Bit('bitcode'):
15   LIBGCC = []
16 else:
17   LIBGCC = ['-lgcc']
18
19 DEP_LINKFLAGS = (['-Wl,--whole-archive'] + LIBGCC +
20                    ['-l' + name for name in DEP_LIBS] +
21                    ['-Wl,--no-whole-archive'])
22
23 # TODO(robertm): get rid of -allow-asm once we can distinguish
24 #                real asms from the redirect ones used here
25 if env.Bit('bitcode'):
26   env.Append(CCFLAGS=['-allow-asm'])
27
28 # Test C++11 code with both supported C++ standard libraries.
29 cpp11_libs = ['libstdc++', 'libc++']
30 cpp11_envs = {}
31 for lib in cpp11_libs:
32   cpp11_envs[lib] = env.Clone()
33   cpp11_envs[lib].Append(CCFLAGS=['-std=c++11', '-stdlib=' + lib])
34   cpp11_envs[lib].Append(LINKFLAGS=['-stdlib=' + lib])
35
36 # All the libraries were already included via -l switches in LINKFLAGS.
37 # But we use them again in LIBS so scons knows about the dependencies.
38 # _LIBFLAGS is the internal variable that puts the expansion of LIBS
39 # into the command line; so by clearing that, we prevent scons from
40 # adding repeated -l switches at the end of the link.
41 nexe = env.ComponentProgram('dummy', 'dummy.c',
42                             EXTRA_LINKFLAGS=DEP_LINKFLAGS,
43                             LIBS=DEP_LIBS,
44                             _LIBFLAGS='')
45 node = env.CommandValidatorTestNacl('whole_archive_test.out',
46                                     image=nexe)
47 env.AddNodeToTestSuite(node,
48                        ['toolchain_tests', 'small_tests'],
49                        'run_whole_archive_test',
50                        # The old ncval doesn't like the new linker's style
51                        # of padding the code segment.  TODO(mcgrathr):
52                        # Remove this is_broken= when we the old ncval is no
53                        # longer ever built and used for this test.
54                        is_broken=(env.Bit('target_x86') and
55                                   not env.Bit('validator_ragel')))
56
57
58 def AddIntrinsicTest(test_env, src, exit_status,
59                      golden_file=None, test_suffix='', is_broken=False,
60                      EXTRA_LIBS=[]):
61   name = src.split('.')[0]
62   name += test_suffix
63
64   obj = test_env.ComponentObject(name, src)
65   nexe = test_env.ComponentProgram(
66       name, obj, EXTRA_LIBS=['${NONIRT_LIBS}'] + EXTRA_LIBS)
67   node = test_env.CommandSelLdrTestNacl(name + '.out',
68                                         nexe,
69                                         exit_status=exit_status,
70                                         stdout_golden=golden_file)
71   test_env.AddNodeToTestSuite(node,
72                               ['toolchain_tests','small_tests'],
73                               'run_' + name + '_test',
74                               is_broken=is_broken)
75
76
77 # Test various intrinsics.
78 AddIntrinsicTest(env, 'intrinsics.cc', '55'),
79 AddIntrinsicTest(env, 'float2.c', '0', golden_file=env.File('float2.stdout'))
80 AddIntrinsicTest(env, 'synchronization_sync.c', '0',
81                  # TODO(jfb) Blocked on bugs 3579 and 2981. This should
82                  # work on PNaCl because it avoids the broken 16-bit
83                  # instructions on x86-32 by using 32-bit instructions.
84                  # The test also exercises instructions that confuse valgrind.
85                  is_broken=((env.Bit('target_x86_32') and
86                              not env.Bit('bitcode')) or
87                             env.IsRunningUnderValgrind()))
88 AddIntrinsicTest(env, 'synchronization_volatile.c', '0')
89 if env.Bit('bitcode'):
90   # The following tests were only made to work on LLVM for
91   # PNaCl. Command-line flags and libraries need to be updated for GCC
92   # support.
93   # pthread is needed when building with libc++.
94   for lib in cpp11_envs:
95     AddIntrinsicTest(cpp11_envs[lib], 'condition_variable_cpp11.cc', '0',
96                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
97     AddIntrinsicTest(cpp11_envs[lib], 'future_cpp11.cc', '0',
98                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
99     AddIntrinsicTest(cpp11_envs[lib], 'mutex_cpp11.cc', '0',
100                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
101     AddIntrinsicTest(cpp11_envs[lib], 'synchronization_cpp11.cc', '0',
102                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
103     AddIntrinsicTest(cpp11_envs[lib], 'thread_cpp11.cc', '0',
104                      test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
105     if lib != 'libstdc++':
106       # TODO(jfb) Can't compile with libstdc++.
107       AddIntrinsicTest(cpp11_envs[lib], 'long_double_cpp11.cc', '0',
108                        test_suffix=lib, EXTRA_LIBS=['${PTHREAD_LIBS}'])
109
110 # This test redirects C function calls to llvm instrinsic functions,
111 # so they only work w/ PNaCl.
112 if env.Bit('bitcode'):
113   AddIntrinsicTest(env, 'llvm_bitmanip_intrinsics.c', '0',
114                    golden_file=env.File('llvm_bitmanip_intrinsics.stdout'))
115   AddIntrinsicTest(env, 'llvm_math_intrinsics.c', '0',
116                    golden_file=env.File('llvm_math_intrinsics.stdout'))
117   # Also test the math functions with -ffast-math, so we are a tiny bit more
118   # confident that sin() or __builtin_sin() doesn't get turned into
119   # something like llvm.sin.f64.
120   fastmath_env = env.Clone()
121   fastmath_env.Append(CCFLAGS=['-ffast-math'])
122   AddIntrinsicTest(fastmath_env, 'llvm_math_intrinsics.c', '0',
123                    golden_file=env.File('llvm_math_intrinsics.stdout'),
124                    test_suffix='_fast_math')
125
126 # Some of the intrinsic tests cover intrinsics that we do not want to
127 # support. For example, llvm.frameaddress. If that is the case, we will
128 # use the nonstable_env as our test_env in AddIntrinsicTest.
129 nonstable_env = env.Clone()
130 if env.Bit('bitcode'):
131   nonstable_env.Append(LINKFLAGS=['--pnacl-disable-abi-check'])
132 if nonstable_env.AllowNonStableBitcode():
133   # Consider llvm.frameaddress and llvm.returnaddress non-stable,
134   # since we may want to hide return and stack addresses in the future.
135   AddIntrinsicTest(nonstable_env, 'frame_addresses.c', '0'),
136   AddIntrinsicTest(nonstable_env, 'return_address.c', '55')
137
138
139 # initfini test
140 initfini_obj = env.ComponentObject('initfini.c')
141
142 def AddInitFiniTest(env, name, extra_libs):
143   nexe = env.ComponentProgram(name,
144                               [initfini_obj],
145                               EXTRA_LIBS=extra_libs + ['${NONIRT_LIBS}'])
146   golden_file = env.File(name + '.stdout')
147   node = env.CommandSelLdrTestNacl(name + '.out',
148                                    nexe,
149                                    stdout_golden=golden_file)
150   # This test checks the ".init_array" and ".fini_array" sections,
151   # which are an internal detail of how the toolchain works.  We do
152   # not support these sections in PNaCl's static linking ABI, because
153   # PNaCl connects up initializers at bitcode linking time.  PNaCl
154   # does support __attribute__((constructor)) and
155   # __attribute__((destructor)) which are tested via
156   # run_initfini_attributes_test below.
157   is_broken = env.Bit('bitcode') and env.Bit('nacl_static_link')
158   env.AddNodeToTestSuite(node,
159                          ['toolchain_tests', 'small_tests'],
160                          'run_' + name + '_test',
161                          is_broken=is_broken)
162
163 AddInitFiniTest(env, 'initfini_static', [])
164 if env.Bit('nacl_glibc') and not env.Bit('nacl_disable_shared'):
165   # Additional case: Add initfini_shared.c as a shared object.
166   # For a shared object, the init/fini arrays are executed by
167   # the dynamic loader. This exercises a different code path.
168   env.NaClSdkLibrary('initfini_s', 'initfini_shared.c')
169   AddInitFiniTest(env, 'initfini_shared', ['initfini_s'])
170
171
172 nexe = env.ComponentProgram(
173     'initfini_attributes', ['initfini_attributes.c'],
174     EXTRA_LIBS=['${NONIRT_LIBS}'])
175 node = env.CommandSelLdrTestNacl(
176     'initfini_attributes.out', nexe,
177     stdout_golden=env.File('initfini_attributes.stdout'))
178 env.AddNodeToTestSuite(
179     node, ['toolchain_tests', 'small_tests'],
180     'run_initfini_attributes_test',
181     # __attribute__((destructor)) is broken in nacl-glibc on x86-64.
182     # See http://code.google.com/p/nativeclient/issues/detail?id=3056
183     # TODO(mseaborn): Enable this test there when this is fixed.
184     is_broken=env.Bit('nacl_glibc') and env.Bit('target_x86_64'))
185
186
187 nexe = env.ComponentProgram('pthread_cleanup', 'pthread_cleanup.c',
188                             EXTRA_LIBS=['${PTHREAD_LIBS}',
189                                         '${NONIRT_LIBS}'])
190 node = env.CommandSelLdrTestNacl('pthread_cleanup.out', nexe)
191 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
192                        'run_pthread_cleanup_test')
193
194
195 # NOTE: the tests below break easily under valgrid and since
196 #       they do not exercise malloc/free we exclude
197 if env.IsRunningUnderValgrind():
198   Return()
199
200
201 # NOTE: we assume that the incoming env contains '-O2', '-fomit-frame-pointer'
202 def MakeEnv(env, use_opts, use_frames):
203   new_env = env.Clone()
204   # AddBiasForPNaCl() is only needed for stack_frame.cc and eh_return.c.
205   if new_env.Bit('bitcode'):
206     new_env.AddBiasForPNaCl()
207   new_env.FilterOut(CFLAGS=['-pedantic'])
208   new_env.FilterOut(CCFLAGS=['-pedantic'])
209   if use_frames:
210     new_env.FilterOut(CFLAGS=['-fomit-frame-pointer'])
211     new_env.FilterOut(CCFLAGS=['-fomit-frame-pointer'])
212     if env.Bit('bitcode'):
213       # To use frame pointers for PNaCl, we need to change the translate-flags.
214       new_env.Append(TRANSLATEFLAGS=[
215           '--pnacl-driver-set-LLC_FLAGS_EXTRA=-disable-fp-elim'])
216   else:
217     new_env.Append(CFLAGS=['-fomit-frame-pointer'])
218     new_env.Append(CCFLAGS=['-fomit-frame-pointer'])
219   if use_opts:
220     new_env.Append(CFLAGS=['-O2'])
221     new_env.Append(CCFLAGS=['-O2'])
222   else:
223     new_env.FilterOut(CFLAGS=['-O2'])
224     new_env.FilterOut(CCFLAGS=['-O2'])
225     new_env.FilterOut(LINKFLAGS=['-O3'])
226   return new_env
227
228 EH_ENVIRONMENTS_TO_TRY = []
229
230 base_eh_env = env.Clone()
231 supports_cxx11 = env.Bit('bitcode') or env.Bit('target_arm')
232 base_eh_env.Append(CPPDEFINES=[['SUPPORTS_CXX11', str(int(supports_cxx11))]])
233 if supports_cxx11:
234   # This flag is necessary for testing std::rethrow_exception(), at
235   # least when using libstdc++.
236   base_eh_env.Append(CXXFLAGS=['-std=gnu++11'])
237
238 if env.Bit('bitcode') and env['TOOLCHAIN_FEATURE_VERSION'] >= 1:
239   for lib in ('libstdc++', 'libc++'):
240     sjlj_eh_env = base_eh_env.Clone()
241     sjlj_eh_env.Append(LINKFLAGS=['--pnacl-exceptions=sjlj',
242                                   '-stdlib=%s' % lib])
243     sjlj_eh_env.Append(CCFLAGS=['-stdlib=%s' % lib])
244     EH_ENVIRONMENTS_TO_TRY.append(('sjlj_%s' % lib, sjlj_eh_env))
245
246 if env.Bit('bitcode'):
247   zerocost_eh_env = base_eh_env.Clone()
248   zerocost_eh_env.Append(LINKFLAGS=['--pnacl-allow-exceptions'])
249   zerocost_eh_env.Append(TRANSLATEFLAGS=['--pnacl-allow-exceptions'])
250 else:
251   zerocost_eh_env = base_eh_env
252 # Zero-cost C++ exception handling is not currently supported in
253 # PNaCl's stable ABI.
254 if zerocost_eh_env.AllowNonStableBitcode():
255   EH_ENVIRONMENTS_TO_TRY.extend(
256       [('noopt_frame', MakeEnv(zerocost_eh_env, False, True)),
257        ('noopt_noframe', MakeEnv(zerocost_eh_env, False, False)),
258        ('opt_frame', MakeEnv(zerocost_eh_env, True, True)),
259        ('opt_noframe', MakeEnv(zerocost_eh_env, True, False))])
260
261 for tag, env_to_try in EH_ENVIRONMENTS_TO_TRY:
262   for src in ['stack_frame.cc',
263               'eh_return.c',
264               'eh_virtual_dtor.cc',
265               'eh_loop_single.cc',
266               'eh_loop_many.cc',
267               'eh_catch_many.cc',
268               'eh_loop_break.cc',
269               'eh_floating_point.cc',
270               'eh_uncaught_exception.cc',
271               'eh_throw_tests.cc',
272               ]:
273
274     if not env.Bit('bitcode') and src in ['eh_return.c']:
275       # for some reason gcc does not allow us to use
276       #  __builtin_eh_return
277       continue
278
279     is_broken = False
280     if (env.Bit('bitcode') and
281         env.Bit('pnacl_generate_pexe') and
282         src in ['stack_frame.cc', 'eh_return.c']):
283       # stack_frame.cc and eh_return.c have bias see above
284       is_broken = True
285
286     if not env.Bit('bitcode') and src in ['stack_frame.cc']:
287       # This test makes pnacl specific assumptions which
288       # may not hold for the nacl-gcc TC
289       is_broken = True
290
291     # The following tests don't work as PNaCl ABI-stable pexes.
292     non_abi_stable_tests = [
293         'eh_floating_point.cc', # Uses vector types
294         'stack_frame.cc', # Uses llvm.eh.dwarf.cfa
295         'eh_return.c', # Uses llvm.eh.dwarf.cfa, and llvm.eh.return.i32
296         ]
297     if tag.startswith('sjlj_') and src in non_abi_stable_tests:
298       continue
299
300     if '--pnacl-exceptions=sjlj' in env_to_try['LINKFLAGS']:
301       if (src == 'eh_uncaught_exception.cc' and
302           env_to_try['TOOLCHAIN_FEATURE_VERSION'] < 2):
303         is_broken = True
304       if (src == 'eh_throw_tests.cc' and
305           env_to_try['TOOLCHAIN_FEATURE_VERSION'] < 3):
306         is_broken = True
307
308     name = src.split('.')[0] + '_' + tag
309     nobj = env_to_try.ComponentObject(name + '.o', src)
310     nexe = env_to_try.ComponentProgram(name, nobj,
311                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
312     node = env_to_try.CommandSelLdrTestNacl(name + '.out',
313                                             nexe,
314                                             exit_status='55')
315     env_to_try.AddNodeToTestSuite(
316         node, ['eh_tests', 'toolchain_tests', 'small_tests'],
317         'run_' + name  +'_test', is_broken=is_broken)
318
319
320 # Test that Exception Handling works with the calling conventions that
321 # match the PPAPI PNaCl IRT shim's calling conventions.
322 exc_env = env.Clone()
323 if exc_env.Bit('bitcode') and exc_env.AllowNonStableBitcode():
324   # Test what happens when all objects are bitcode w/ bitcode linking.
325   exc_env.Append(LINKFLAGS=['--pnacl-allow-exceptions'])
326   exc_env.Append(TRANSLATEFLAGS=['--pnacl-allow-exceptions'])
327   bobj1 = exc_env.ComponentObject('eh_separate_files1_bc.o',
328                                   'eh_separate_files1.cc')
329   bobj2 = exc_env.ComponentObject('eh_separate_files2_bc.o',
330                                   'eh_separate_files2.cc')
331   nexe = exc_env.ComponentProgram('eh_separate_files_bc',
332                                   [bobj1, bobj2],
333                                   EXTRA_LIBS=['${NONIRT_LIBS}'])
334   node = exc_env.CommandSelLdrTestNacl('eh_separate_files_bc.out',
335                                        nexe,
336                                        exit_status='55')
337   env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
338                          'run_eh_separate_files_bc_test')
339   # Also test ahead of time translation, which may be used when debugging.
340   if not env.Bit('pnacl_generate_pexe'):
341     native_env = exc_env.Clone()
342     native_env.PNaClForceNative()
343     testsuite = ['toolchain_tests', 'small_tests', 'nonpexe_tests']
344     nobj1 = native_env.ComponentObject('eh_separate_files1_native.o',
345                                        'eh_separate_files1.cc')
346     nobj2 = native_env.ComponentObject('eh_separate_files2_native.o',
347                                        'eh_separate_files2.cc')
348     nexe = native_env.ComponentProgram('eh_separate_files_native',
349                                        [nobj1, nobj2],
350                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
351     node = native_env.CommandSelLdrTestNacl('eh_separate_files_native.out',
352                                             nexe,
353                                             exit_status='55')
354     env.AddNodeToTestSuite(node,
355                            testsuite,
356                            'run_eh_separate_files_native_test')
357     # Test mixed objects, one native, one bitcode.
358     nexe = native_env.ComponentProgram('eh_separate_files_mixed1',
359                                        [bobj1, nobj2],
360                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
361     node = native_env.CommandSelLdrTestNacl('eh_separate_files_mixed1.out',
362                                             nexe,
363                                             exit_status='55')
364     env.AddNodeToTestSuite(node,
365                            testsuite,
366                            'run_eh_separate_files_mixed1_test')
367     # Test having the bitcode and native objects swapped.
368     nexe = native_env.ComponentProgram('eh_separate_files_mixed2',
369                                        [nobj1, bobj2],
370                                        EXTRA_LIBS=['${NONIRT_LIBS}'])
371     node = native_env.CommandSelLdrTestNacl('eh_separate_files_mixed2.out',
372                                             nexe,
373                                             exit_status='55')
374     env.AddNodeToTestSuite(node,
375                            testsuite,
376                            'run_eh_separate_files_mixed2_test')
377
378
379
380 abi_types_nexe = env.ComponentProgram('abi_types',
381                                       'abi_types.cc',
382                                       EXTRA_LIBS=['${NONIRT_LIBS}'])
383
384 node = env.CommandSelLdrTestNacl('abi_types_test.out',
385                                  abi_types_nexe)
386 env.AddNodeToTestSuite(node,
387                        ['toolchain_tests', 'small_tests'],
388                        'run_abi_types_test')
389
390 getpagesize_test_nexe = env.ComponentProgram(
391     'getpagesize_test', 'getpagesize_test.c',
392     EXTRA_LIBS=['${NONIRT_LIBS}'])
393 node = env.CommandSelLdrTestNacl('getpagesize_test.out', getpagesize_test_nexe)
394 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
395                        'run_getpagesize_test')
396
397 getid_test_nexe = env.ComponentProgram(
398     'getid_test', 'getid_test.c',
399     EXTRA_LIBS=['${NONIRT_LIBS}'])
400 node = env.CommandSelLdrTestNacl('getid_test.out', getid_test_nexe)
401 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
402                        'run_getid_test')
403
404 prefetch_test_nexe = env.ComponentProgram(
405     'prefetch_test', 'prefetch_test.c',
406     EXTRA_LIBS=['${NONIRT_LIBS}'])
407 node = env.CommandSelLdrTestNacl('prefetch_test.out', prefetch_test_nexe)
408 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
409                        'run_prefetch_test')
410
411
412 # Test that local variable dwarf info is preserved with linking and LTO.
413 # Force '-g' on in case it was not turned on for some reason, and lower
414 # optimization settings to prevent some optimizations that would convert
415 # locals from llvm allocas to registers.
416 # We may be able to remove this test once LLVM has an upstream regression test.
417 debug_env = env.Clone()
418 debug_env.Append(CFLAGS=['-g', '-O0'])
419 debug_env.Append(CCFLAGS=['-g', '-O0'])
420 debug_env.Append(LINKFLAGS=['-O0'])
421 # This requires preserving nonstable bitcode debug metadata.
422 if debug_env.AllowNonStableBitcode():
423   dwarf_local_var_nexe = debug_env.ComponentProgram(
424       'dwarf_local_var',
425       ['dwarf_local_var.c',
426        'dwarf_local_var_dummy.c'],
427       EXTRA_LIBS=['${NONIRT_LIBS}'])
428   # Sanity-check -- make sure it runs.
429   node = debug_env.CommandSelLdrTestNacl('dwarf_local_var_run.out',
430                                          dwarf_local_var_nexe,
431                                          exit_status=55)
432   debug_env.AddNodeToTestSuite(node,
433                                ['toolchain_tests', 'small_tests'],
434                                'run_dwarf_local_var_run_test')
435   node = debug_env.CommandTestFileDumpCheck('dwarf_local_var_objdump.out',
436                                             dwarf_local_var_nexe,
437                                             debug_env.File('dwarf_local_var.c'),
438                                             '-W')
439   debug_env.AddNodeToTestSuite(node,
440                                ['small_tests', 'toolchain_tests'],
441                                'run_dwarf_local_var_objdump_test')
442
443 if env.Bit('nacl_glibc'):
444   nexe = env.ComponentProgram('byteswap64', 'byteswap64.c',
445                               EXTRA_LIBS=['${NONIRT_LIBS}'])
446   node = env.CommandSelLdrTestNacl('byteswap64.out', nexe)
447   env.AddNodeToTestSuite(node,
448                          ['toolchain_tests', 'small_tests'],
449                          'run_byteswap64_test')
450
451 if env.Bit('nacl_glibc') or not env.Bit('bitcode'):
452   def AddAlignedCodeTest(name, object_file):
453     node = env.CommandTest(name + '.out',
454                            ['${PYTHON}', env.File('aligned_code.py'),
455                             '${OBJDUMP}', nexe],
456                            # don't run ${PYTHON} under the emulator.
457                            direct_emulation=False)
458     env.AddNodeToTestSuite(node,
459                            ['toolchain_tests', 'small_tests'],
460                            'run_' + name + '_test')
461   AddAlignedCodeTest('aligned_code',
462                      env.ComponentProgram('aligned_code', ['aligned_code.c'],
463                                           EXTRA_LIBS=['${NONIRT_LIBS}']))
464   if not env.Bit('nacl_disable_shared'):
465     AddAlignedCodeTest('aligned_code_lib',
466                        env.NaClSharedLibrary('aligned_code_lib',
467                                              ['aligned_code_lib.c']))
468
469 nexe = env.ComponentProgram('method_pointer_repr', 'method_pointer_repr.cc',
470                             EXTRA_LIBS=['${NONIRT_LIBS}'])
471 node = env.CommandSelLdrTestNacl('method_pointer_repr.out', nexe)
472 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
473                        'run_method_pointer_repr_test')
474
475 c99_env = env.Clone()
476 c99_env.Append(CFLAGS=['-std=c99'])
477 # VLA test is broken on nacl-gcc x86-64 (segfaults in test_two_recursion()).
478 # http://code.google.com/p/nativeclient/issues/detail?id=3527
479 vla_is_broken = not env.Bit('bitcode') and env.Bit('target_x86_64')
480 nexe = c99_env.ComponentProgram('vla', 'vla.c',
481                                 EXTRA_LIBS=['${NONIRT_LIBS}'])
482 node = env.CommandSelLdrTestNacl('vla.out', nexe,
483                                  stdout_golden=env.File('vla.stdout'))
484 env.AddNodeToTestSuite(node, ['toolchain_tests', 'small_tests'],
485                        'run_vla_test',
486                        is_broken=vla_is_broken)
487
488 if not env.Bit('pnacl_generate_pexe'):
489   asm_env = env.Clone()
490   if env.Bit('bitcode'):
491     asm_env.PNaClForceNative()
492     asm_env.AddBiasForPNaCl()
493   testsuite = ['toolchain_tests', 'small_tests', 'nonpexe_tests']
494
495   def FarCallObjects(env, suffix=''):
496     return [env.ComponentObject(file[:-2] + suffix + '.o', file)
497             for file in ['far_caller.c', 'far_padding.S', 'far_callee.c']]
498   nexe = asm_env.ComponentProgram('far_call', FarCallObjects(asm_env),
499                                   EXTRA_LIBS=['${NONIRT_LIBS}'])
500   node = asm_env.CommandSelLdrTestNacl('far_call.out', nexe)
501   # TODO(mcgrathr): Broken for bitcode pending fixes to gold; see
502   # https://code.google.com/p/nativeclient/issues/detail?id=3568
503   asm_env.AddNodeToTestSuite(node, testsuite,
504                              'run_far_call_test',
505                              is_broken=env.Bit('bitcode'))
506
507   # TODO(mcgrathr): Disabled for bitcode because pnacl-ld doesn't grok
508   # --pic-veneer.  Another tack to test this would be to generate a shared
509   # object and validate it, but -shared is not really supported either.
510   # Since PNaCl has no reason to generate PIC at all until there is some
511   # form of ELF shared object support (if that ever happens at all),
512   # perhaps we'll never really need to test this.
513   if not env.Bit('bitcode'):
514     pic_env = asm_env.Clone()
515     pic_env.Append(CFLAGS=['-fPIC'])
516     if pic_env.Bit('target_arm'):
517       pic_env.Append(LINKFLAGS=['-Wl,--pic-veneer'])
518     nexe = pic_env.ComponentProgram('far_call_pic',
519                                     FarCallObjects(pic_env, '_pic'),
520                                     EXTRA_LIBS=['${NONIRT_LIBS}'])
521     node = pic_env.CommandSelLdrTestNacl('far_call_pic.out', nexe)
522     pic_env.AddNodeToTestSuite(node, testsuite,
523                                'run_far_call_pic_test')
524
525   dummy_obj = asm_env.ComponentObject('nop_test_main.o', 'dummy.c')
526   nexe = asm_env.ComponentProgram('nop_test', [dummy_obj, 'nop_test.S'],
527                                   EXTRA_LIBS=['${NONIRT_LIBS}'])
528   node = asm_env.CommandSelLdrTestNacl('nop_test.out', nexe)
529   asm_env.AddNodeToTestSuite(node, testsuite,
530                              'run_nop_test')
531
532   # Test that both the layout and the nops are not munged by stripping.
533   stripped_nexe = asm_env.Command('strip_test.nexe', nexe,
534                                   '${STRIP} -o ${TARGET} ${SOURCES}')
535   node = asm_env.CommandSelLdrTestNacl('strip_test.out', stripped_nexe)
536   asm_env.AddNodeToTestSuite(node, testsuite,
537                              'run_strip_test')
538
539 if not env.Bit('nacl_disable_shared') and not env.Bit('nacl_static_link'):
540   env.NaClSharedLibrary('pic_constant_lib', ['pic_constant_lib.c'])
541   nexe = env.ComponentProgram('pic_constant', ['pic_constant.c'],
542                               EXTRA_LIBS=['pic_constant_lib', '${NONIRT_LIBS}'])
543   node = env.CommandSelLdrTestNacl('pic_constant.out', nexe)
544   env.AddNodeToTestSuite(node, testsuite,
545                          'run_pic_constant_test')
546
547 WRAP_LINK_FLAGS = ['-Wl,--wrap=foo', '-Wl,--wrap=bar']
548 env.ComponentLibrary('wrap_lib', ['wrap_lib1.c', 'wrap_lib2.c'])
549 nexe = env.ComponentProgram('wrap', ['wrap_main.c'],
550                             EXTRA_LINKFLAGS=WRAP_LINK_FLAGS,
551                             EXTRA_LIBS=['wrap_lib', '${NONIRT_LIBS}'])
552 node = env.CommandSelLdrTestNacl('wrap.out', nexe,
553                                  stdout_golden=env.File('wrap.stdout'))
554 env.AddNodeToTestSuite(node, ['toolchain_tests','small_tests'], 'run_wrap_test')
555
556 if (env.Bit('target_x86_32') and env.Bit('bitcode') and
557     not env.Bit('pnacl_generate_pexe') and
558     env['TOOLCHAIN_FEATURE_VERSION'] >= 7):
559   # This test compiles a file that will need to generate a call to a compiler-rt
560   # function (__udivdi3) on x86-32. Ensure that when we pre-translate to a
561   # native object file, libgcc is included in the bitcode link to satisfy the
562   # reference.
563   mixedlink_env = env.Clone()
564   mixedlink_env.Append(CCFLAGS=['--pnacl-allow-translate',
565                                 '--pnacl-allow-native',
566                                 '-arch', 'x86-32'])
567   mixedlink_env.Append(LINKFLAGS=['--pnacl-allow-translate',
568                                   '--pnacl-allow-native',
569                                   '-arch', 'x86-32'])
570   nexe = mixedlink_env.ComponentProgram('libgcc_mixed_link', 'needs_libgcc.c',
571                                         EXTRA_LIBS=['${NONIRT_LIBS}'])
572   node = mixedlink_env.CommandSelLdrTestNacl('libgcc_mixed_link.out', nexe,
573                                              ['9', '3'])
574   mixedlink_env.AddNodeToTestSuite(node, ['nonpexe_tests', 'small_tests'],
575                                    'run_libgcc_mixed_link_test')