OLD | NEW |
---|---|
1 # -*- python -*- | 1 # -*- python -*- |
2 # Copyright (c) 2014 The Native Client Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 Import('env') | 6 Import('env') |
7 | 7 |
8 if not env.Bit('bitcode'): | 8 if not env.Bit('bitcode'): |
9 Return() | 9 Return() |
10 # Translating the PSO to an ELF DSO doesn't work on x86-64 yet. The | 10 # Translating the PSO to an ELF DSO doesn't work on x86-64 yet. The |
11 # Gold linker complains that the input "requires dynamic R_X86_64_32 | 11 # Gold linker complains that the input "requires dynamic R_X86_64_32 |
12 # reloc against <blah> which may overflow at runtime". (In contrast, | 12 # reloc against <blah> which may overflow at runtime". (In contrast, |
13 # the BFD linker in the glibc toolchain does handle this relocation.) | 13 # the BFD linker in the glibc toolchain does handle this relocation.) |
14 # TODO(mseaborn): Fix this and enable the test for x86-64. | 14 # TODO(mseaborn): Fix this and enable the test for x86-64. |
15 if env.Bit('build_x86_64'): | 15 if env.Bit('build_x86_64'): |
16 Return() | 16 Return() |
17 # TODO(sbc): Enable this test for mips. | 17 # TODO(sbc): Enable this test for mips. |
18 if env.Bit('build_mips32'): | 18 if env.Bit('build_mips32'): |
19 Return() | 19 Return() |
20 # The sandboxed translator does not support translating PSOs yet. | 20 # The sandboxed translator does not support translating PSOs yet. |
21 if env.Bit('use_sandboxed_translator'): | 21 if env.Bit('use_sandboxed_translator'): |
22 Return() | 22 Return() |
23 | 23 |
24 def FinalizePso(dest, opt_result): | |
25 # Finalize to strip debugging info and to emit PNaCl bitcode. | |
26 return env.Command(dest + '.so', [opt_result], | |
27 '${PNACLFINALIZE} ${SOURCES} -o ${TARGET}') | |
24 | 28 |
Mark Seaborn
2016/03/30 23:24:57
Style nit: In Python it's preferred to have 2 empt
Sean Klein
2016/04/01 23:12:25
Done.
| |
25 def FinalizeAndTranslatePso(dest, opt_result): | 29 def TranslatePso(dest, finalized_result): |
26 # Finalize to strip debugging info and to emit PNaCl bitcode. | |
27 finalized_result = env.Command( | |
28 dest + '.final.pso', [opt_result], | |
29 '${PNACLFINALIZE} ${SOURCES} -o ${TARGET}') | |
30 # Translate to an ELF loadable object. | 30 # Translate to an ELF loadable object. |
31 return env.Command(dest + '.so', [finalized_result], | 31 return env.Command(dest + '.so.translated', [finalized_result], |
32 '${TRANSLATE} -pso ${SOURCES} -o ${TARGET}') | 32 '${TRANSLATE} -pso ${SOURCES} -o ${TARGET}') |
33 | 33 |
34 | 34 |
35 def MakeAndTranslatePso(dest, bitcode_file, llvm_passes): | 35 def MakeAndTranslatePso(dest, bitcode_file, llvm_passes): |
36 # Run opt to optionally apply PNaCl ABI simplifications to the IR and to | 36 # Run opt to optionally apply PNaCl ABI simplifications to the IR and to |
37 # run the PNaCl ABI checker. We are bypassing pnacl-ld for now because | 37 # run the PNaCl ABI checker. We are bypassing pnacl-ld for now because |
38 # its invocation of Gold internalizes __pnacl_pso_root, which we want to | 38 # its invocation of Gold internalizes __pnacl_pso_root, which we want to |
39 # keep externally-visible. | 39 # keep externally-visible. |
40 opt_result = env.Command( | 40 opt_result = env.Command( |
41 dest + '.nonfinal.pso', [bitcode_file], | 41 dest + '.nonfinal.pso', [bitcode_file], |
42 '${PNACLOPT} ' + llvm_passes + ' ' | 42 '${PNACLOPT} ' + llvm_passes + ' ' |
43 '-verify-pnaclabi-module -verify-pnaclabi-functions ' | 43 '-verify-pnaclabi-module -verify-pnaclabi-functions ' |
44 '-pnaclabi-allow-debug-metadata ' | 44 '-pnaclabi-allow-debug-metadata ' |
45 '${SOURCES} -o ${TARGET}') | 45 '${SOURCES} -o ${TARGET}') |
46 return FinalizeAndTranslatePso(dest, opt_result) | 46 finalized_result = FinalizePso(dest, opt_result) |
47 return TranslatePso(dest, finalized_result) | |
47 | 48 |
48 def PsoFromLLVMAssembly(base_name): | 49 def PsoFromLLVMAssembly(base_name): |
49 bitcode_file = env.Command( | 50 bitcode_file = env.Command( |
50 '%s.bc' % base_name, ['%s.ll' % base_name], | 51 '%s.bc' % base_name, ['%s.ll' % base_name], |
51 [Action('${ASCOM}', '${ASCOMSTR}')]) | 52 [Action('${ASCOM}', '${ASCOMSTR}')]) |
52 return MakeAndTranslatePso(base_name, [bitcode_file], | 53 return MakeAndTranslatePso(base_name, [bitcode_file], |
53 # Skip PNaCl passes because they add TLS functions. | 54 # Skip PNaCl passes because they add TLS functions. |
54 llvm_passes='') | 55 llvm_passes='') |
55 | 56 |
56 | 57 |
57 def MakeAndTranslatePll(dest, source_file): | 58 def MakePll(dest, source_file, dependencies): |
59 deps = '' | |
60 if dependencies != []: | |
Mark Seaborn
2016/03/30 23:24:57
"len(dependencies) != 0" is arguably more idiomati
Sean Klein
2016/04/01 23:12:25
Using "len(dependencies) != 0"
| |
61 deps += ' -L' + Dir('.').abspath | |
62 for d in dependencies: | |
63 deps += ' -l:' + d[0].name | |
58 nonfinal_pll = env.Command( | 64 nonfinal_pll = env.Command( |
59 dest + '.nonfinal.pll', [source_file], | 65 dest + '.nonfinal.pll', [source_file], |
60 '${CC} -shared ${SOURCES} -o ${TARGET}') | 66 '${CC} -shared ${SOURCES} -o ${TARGET}' + deps) |
61 return FinalizeAndTranslatePso(dest, nonfinal_pll) | 67 for d in dependencies: |
Mark Seaborn
2016/03/30 23:24:57
I think you can do
Depends(nonfinal_pll, dependenc
Sean Klein
2016/04/01 23:12:25
Done.
| |
68 # Linking the nonfinal_pll depends on the untranslated, finalized PLL (.so) | |
69 # dependencies existing. | |
70 Depends(nonfinal_pll, d) | |
71 return FinalizePso(dest, nonfinal_pll) | |
72 | |
73 def MakeAndTranslatePll(dest, source_file, dependencies): | |
74 finalized_pll = MakePll(dest, source_file, dependencies) | |
75 return TranslatePso(dest, finalized_pll) | |
62 | 76 |
63 # Under SFI NaCl, the loader currently depends on the allocate_code_data() | 77 # Under SFI NaCl, the loader currently depends on the allocate_code_data() |
64 # interface provided by the IRT. | 78 # interface provided by the IRT. |
65 is_broken = not env.Bit('tests_use_irt') and not env.Bit('nonsfi_nacl') | 79 is_broken = not env.Bit('tests_use_irt') and not env.Bit('nonsfi_nacl') |
66 | 80 |
67 dso1 = MakeAndTranslatePso( | 81 dso1 = MakeAndTranslatePso( |
68 'test_pso', [env.ComponentObject('test_pso.c')], | 82 'test_pso', [env.ComponentObject('test_pso.c')], |
69 llvm_passes='-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt') | 83 llvm_passes='-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt') |
70 dso2 = PsoFromLLVMAssembly('data_only_pso') | 84 dso2 = PsoFromLLVMAssembly('data_only_pso') |
71 dso3 = PsoFromLLVMAssembly('data_only_pso_largebss') | 85 dso3 = PsoFromLLVMAssembly('data_only_pso_largebss') |
(...skipping 10 matching lines...) Expand all Loading... | |
82 node, ['small_tests', 'toolchain_tests'], | 96 node, ['small_tests', 'toolchain_tests'], |
83 'run_pnacl_dynamic_loading_test', is_broken=is_broken) | 97 'run_pnacl_dynamic_loading_test', is_broken=is_broken) |
84 | 98 |
85 | 99 |
86 # Use of the ConvertToPSO pass requires this toolchain version. | 100 # Use of the ConvertToPSO pass requires this toolchain version. |
87 if env['TOOLCHAIN_FEATURE_VERSION'] < 24: | 101 if env['TOOLCHAIN_FEATURE_VERSION'] < 24: |
88 Return() | 102 Return() |
89 | 103 |
90 # TODO(smklein): These LLVM passes should be automatically applied by the | 104 # TODO(smklein): These LLVM passes should be automatically applied by the |
91 # drivers. Once support for dependencies has been plumbed through the drivers, | 105 # drivers. Once support for dependencies has been plumbed through the drivers, |
92 # use the "-l" linker flags and don't explicitly declare any LLVM passes. | 106 # use the "-l" linker flags and don't explicitly declare any LLVM passes. |
Mark Seaborn
2016/03/30 23:24:57
Since you're adding "-l" in this change, you could
Sean Klein
2016/04/01 23:12:25
Done. Using "test_pll_a" and "test_pll_b", since M
| |
93 test_pll = MakeAndTranslatePso( | 107 test_pll = MakeAndTranslatePso( |
94 'test_pll', [env.ComponentObject('test_pll.c')], | 108 'test_pll', [env.ComponentObject('test_pll.c')], |
95 llvm_passes='-nacl-global-cleanup -expand-varargs ' | 109 llvm_passes='-nacl-global-cleanup -expand-varargs ' |
96 '-rewrite-pnacl-library-calls -rewrite-llvm-intrinsic-calls ' | 110 '-rewrite-pnacl-library-calls -rewrite-llvm-intrinsic-calls ' |
97 '-convert-to-pso -convert-to-pso-deps=libfoo.so,libbar.so ' | 111 '-convert-to-pso -convert-to-pso-deps=libfoo.so,libbar.so ' |
98 '-pnacl-abi-simplify-postopt') | 112 '-pnacl-abi-simplify-postopt') |
99 | 113 test_pll_tls = MakeAndTranslatePll('test_pll_tls', 'test_pll_tls.c', []) |
100 test_pll_tls = MakeAndTranslatePll('test_pll_tls', 'test_pll_tls.c') | |
101 | 114 |
102 pll_symbols_test = env.ComponentProgram( | 115 pll_symbols_test = env.ComponentProgram( |
103 'pll_symbols_test', ['pll_symbols_test.cc'], | 116 'pll_symbols_test', ['pll_symbols_test.cc'], |
104 EXTRA_LIBS=['${NONIRT_LIBS}', 'pnacl_dynloader', 'pll_loader_lib']) | 117 EXTRA_LIBS=['${NONIRT_LIBS}', 'pnacl_dynloader', 'pll_loader_lib']) |
105 | 118 |
106 node = env.CommandSelLdrTestNacl( | 119 node = env.CommandSelLdrTestNacl( |
107 'pll_symbols_test.out', pll_symbols_test, [test_pll, test_pll_tls], | 120 'pll_symbols_test.out', pll_symbols_test, [test_pll, test_pll_tls], |
108 # Add '-a' to enable filesystem access for opening DSOs. | 121 # Add '-a' to enable filesystem access for opening DSOs. |
109 sel_ldr_flags=['-a']) | 122 sel_ldr_flags=['-a']) |
110 env.AddNodeToTestSuite( | 123 env.AddNodeToTestSuite( |
111 node, ['small_tests', 'toolchain_tests'], | 124 node, ['small_tests', 'toolchain_tests'], |
112 'run_pll_symbols_test', is_broken=is_broken) | 125 'run_pll_symbols_test', is_broken=is_broken) |
113 | 126 |
114 | 127 |
115 test_pll_a = MakeAndTranslatePll('test_pll_a', 'test_pll_a.c') | 128 test_pll_a_finalized = MakePll('test_pll_a', 'test_pll_a.c', []) |
116 test_pll_b = MakeAndTranslatePll('test_pll_b', 'test_pll_b.c') | 129 test_pll_a = TranslatePso('test_pll_a', test_pll_a_finalized) |
130 test_pll_b_finalized = MakePll('test_pll_b', 'test_pll_b.c', | |
131 [test_pll_a_finalized]) | |
132 test_pll_b = TranslatePso('test_pll_b', test_pll_b_finalized) | |
117 | 133 |
118 pll_loader_test = env.ComponentProgram( | 134 pll_loader_test = env.ComponentProgram( |
119 'pll_loader_test', ['pll_loader_test.cc'], | 135 'pll_loader_test', ['pll_loader_test.cc'], |
120 EXTRA_LIBS=['${NONIRT_LIBS}', 'pll_loader_lib']) | 136 EXTRA_LIBS=['${NONIRT_LIBS}', 'pll_loader_lib']) |
121 | 137 |
122 node = env.CommandSelLdrTestNacl( | 138 node = env.CommandSelLdrTestNacl( |
123 'pll_loader_test.out', pll_loader_test, | 139 'pll_loader_test.out', pll_loader_test, |
124 [Dir('.').abspath, 'test_pll_a.so', 'test_pll_b.so', 'test_pll_tls.so'], | 140 [Dir('.').abspath, 'test_pll_a.so', 'test_pll_b.so', 'test_pll_tls.so'], |
125 # Add '-a' to enable filesystem access for opening DSOs. | 141 # Add '-a' to enable filesystem access for opening DSOs. |
126 sel_ldr_flags=['-a'], | 142 sel_ldr_flags=['-a'], |
127 extra_deps=[test_pll_a, test_pll_b, test_pll_tls]) | 143 extra_deps=[test_pll_a, test_pll_b, test_pll_tls]) |
128 env.AddNodeToTestSuite( | 144 env.AddNodeToTestSuite( |
129 node, ['small_tests', 'toolchain_tests'], | 145 node, ['small_tests', 'toolchain_tests'], |
130 'run_pll_loader_test', is_broken=is_broken) | 146 'run_pll_loader_test', is_broken=is_broken) |
131 | 147 |
132 | 148 |
133 pll_libc = env.Command( | 149 pll_libc_nonfinal = env.Command( |
134 'libc${OBJSUFFIX}', | 150 'libc${OBJSUFFIX}', |
135 # libnacl should come first so that it can override definitions in libc. | 151 # libnacl should come first so that it can override definitions in libc. |
136 [env.File('${LIB_DIR}/libnacl.a'), | 152 [env.File('${LIB_DIR}/libnacl.a'), |
137 env.File('${NACL_SDK_LIB}/libc.a'), | 153 env.File('${NACL_SDK_LIB}/libc.a'), |
138 env.ComponentObject('libc_entry.c')], | 154 env.ComponentObject('libc_entry.c')], |
139 '${CC} -shared -Wl,--whole-archive ${SOURCES} -o ${TARGET}') | 155 '${CC} -shared -Wl,--whole-archive ${SOURCES} -o ${TARGET}') |
140 | 156 |
141 translated_pll_libc = FinalizeAndTranslatePso('translated_pll_libc', pll_libc) | 157 pll_libc_finalized = FinalizePso('pll_libc', pll_libc_nonfinal) |
142 translated_pll_hello_world = MakeAndTranslatePll( | 158 pll_libc = TranslatePso('pll_libc', pll_libc_finalized) |
143 'translated_pll_hello_world', | 159 |
144 '../hello_world/hello_world.c') | 160 pll_hello_world = MakeAndTranslatePll( |
161 'pll_hello_world', | |
162 '../hello_world/hello_world.c', | |
163 [pll_libc_finalized]) | |
145 | 164 |
146 # Ideally we would have this ComponentProgram() definition in | 165 # Ideally we would have this ComponentProgram() definition in |
147 # src/untrusted/pll_loader/nacl.scons instead; see the comment there for | 166 # src/untrusted/pll_loader/nacl.scons instead; see the comment there for |
148 # why we don't. | 167 # why we don't. |
149 pll_loader = env.ComponentProgram( | 168 pll_loader = env.ComponentProgram( |
150 'pll_loader', [], | 169 'pll_loader', [], |
151 EXTRA_LIBS=['${NONIRT_LIBS}', 'pll_loader_main', 'pll_loader_lib']) | 170 EXTRA_LIBS=['${NONIRT_LIBS}', 'pll_loader_main', 'pll_loader_lib']) |
152 | 171 |
153 node = env.CommandSelLdrTestNacl( | 172 node = env.CommandSelLdrTestNacl( |
154 'pll_hello_world_test.out', pll_loader, | 173 'pll_hello_world_test.out', pll_loader, |
155 [translated_pll_libc, translated_pll_hello_world], | 174 [Dir('.').abspath, 'pll_hello_world.so'], |
156 # Add '-a' to enable filesystem access for opening DSOs. | 175 # Add '-a' to enable filesystem access for opening DSOs. |
157 sel_ldr_flags=['-a'], | 176 sel_ldr_flags=['-a'], |
158 stdout_golden=env.File('../hello_world/hello_world.stdout')) | 177 stdout_golden=env.File('../hello_world/hello_world.stdout'), |
178 extra_deps=[pll_libc, pll_hello_world]) | |
159 env.AddNodeToTestSuite( | 179 env.AddNodeToTestSuite( |
160 node, ['small_tests', 'toolchain_tests'], | 180 node, ['small_tests', 'toolchain_tests'], |
161 'run_pll_hello_world_test', is_broken=is_broken) | 181 'run_pll_hello_world_test', is_broken=is_broken) |
182 | |
183 | |
184 test_pll_c_finalized = MakePll( | |
185 'test_pll_c', 'test_pll_c.c', [test_pll_a_finalized, test_pll_b_finalized]) | |
186 test_pll_c = TranslatePso('test_pll_c', test_pll_c_finalized) | |
187 | |
188 pll_dependencies_test = MakeAndTranslatePll( | |
189 'pll_dependencies_test', 'dependencies_test.c', | |
190 [pll_libc_finalized, test_pll_c_finalized]) | |
191 | |
192 node = env.CommandSelLdrTestNacl( | |
193 'pll_dependencies_test.out', pll_loader, | |
194 [Dir('.').abspath, 'pll_dependencies_test.so'], | |
195 # Add '-a' to enable filesystem access for opening DSOs. | |
196 sel_ldr_flags=['-a'], stdout_golden=env.File('dependencies_test.stdout'), | |
197 extra_deps=[pll_libc, test_pll_a, test_pll_b, test_pll_c, | |
198 pll_dependencies_test]) | |
Mark Seaborn
2016/03/30 23:24:57
Nit: indent to align with "["
Sean Klein
2016/04/01 23:12:25
Done.
| |
199 env.AddNodeToTestSuite( | |
200 node, ['small_tests', 'toolchain_tests'], 'run_pll_dependencies_test', | |
201 is_broken=is_broken) | |
OLD | NEW |