OLD | NEW |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 | 2 |
3 import argparse | 3 import argparse |
4 import os | 4 import os |
5 import pipes | 5 import pipes |
6 import re | 6 import re |
7 import sys | 7 import sys |
8 | 8 |
9 from utils import shellcmd | 9 from utils import shellcmd |
10 from utils import FindBaseNaCl | 10 from utils import FindBaseNaCl |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 '(m1 and -1 are equivalent).' + | 81 '(m1 and -1 are equivalent).' + |
82 ' Default %(default)s.') | 82 ' Default %(default)s.') |
83 argparser.add_argument('--filetype', default='iasm', dest='filetype', | 83 argparser.add_argument('--filetype', default='iasm', dest='filetype', |
84 choices=['obj', 'asm', 'iasm'], | 84 choices=['obj', 'asm', 'iasm'], |
85 help='Output file type. Default %(default)s.') | 85 help='Output file type. Default %(default)s.') |
86 argparser.add_argument('--sandbox', dest='sandbox', action='store_true', | 86 argparser.add_argument('--sandbox', dest='sandbox', action='store_true', |
87 help='Enable sandboxing in the translator') | 87 help='Enable sandboxing in the translator') |
88 argparser.add_argument('--enable-block-profile', | 88 argparser.add_argument('--enable-block-profile', |
89 dest='enable_block_profile', action='store_true', | 89 dest='enable_block_profile', action='store_true', |
90 help='Enable basic block profiling.') | 90 help='Enable basic block profiling.') |
91 argparser.add_argument('--target', default='x8632', dest='target', | |
92 choices=['arm32', 'x8632'], | |
93 help='Tells Subzero to generate code for the ' | |
Jim Stichnoth
2015/10/15 23:34:21
Bikeshed:
help='Generate code for specified targ
John
2015/11/05 20:25:13
Done.
| |
94 'specified target.') | |
91 argparser.add_argument('--verbose', '-v', dest='verbose', | 95 argparser.add_argument('--verbose', '-v', dest='verbose', |
92 action='store_true', | 96 action='store_true', |
93 help='Display some extra debugging output') | 97 help='Display some extra debugging output') |
94 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], | 98 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], |
95 help='Extra arguments for Subzero') | 99 help='Extra arguments for Subzero') |
96 argparser.add_argument('--llc', dest='llc_args', action='append', | 100 argparser.add_argument('--llc', dest='llc_args', action='append', |
97 default=[], help='Extra arguments for llc') | 101 default=[], help='Extra arguments for llc') |
98 | 102 |
99 def main(): | 103 def main(): |
100 """Create a hybrid translation from Subzero and llc. | 104 """Create a hybrid translation from Subzero and llc. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 llcbin = '{base}/pnacl-llc'.format(base=path_addition) | 182 llcbin = '{base}/pnacl-llc'.format(base=path_addition) |
179 gold = 'le32-nacl-ld.gold' | 183 gold = 'le32-nacl-ld.gold' |
180 objcopy = 'le32-nacl-objcopy' | 184 objcopy = 'le32-nacl-objcopy' |
181 opt_level = args.optlevel | 185 opt_level = args.optlevel |
182 opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' } | 186 opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' } |
183 hybrid = args.include or args.exclude | 187 hybrid = args.include or args.exclude |
184 | 188 |
185 if hybrid and (args.force or | 189 if hybrid and (args.force or |
186 NewerThanOrNotThere(pexe, obj_llc) or | 190 NewerThanOrNotThere(pexe, obj_llc) or |
187 NewerThanOrNotThere(llcbin, obj_llc)): | 191 NewerThanOrNotThere(llcbin, obj_llc)): |
192 arch = { | |
193 'arm32': 'armv7' if args.sandbox else 'arm-nonsfi', | |
194 'x8632': 'x86-32' if args.sandbox else 'x86-32-linux', | |
195 }[args.target] | |
196 | |
188 # Only run pnacl-translate in hybrid mode. | 197 # Only run pnacl-translate in hybrid mode. |
189 shellcmd(['pnacl-translate', | 198 shellcmd(['pnacl-translate', |
190 '-split-module=1', | 199 '-split-module=1', |
191 '-ffunction-sections', | 200 '-ffunction-sections', |
192 '-fdata-sections', | 201 '-fdata-sections', |
193 '-c', | 202 '-c', |
194 '-arch', 'x86-32' if args.sandbox else 'x86-32-linux', | 203 '-arch', arch, |
195 '-O' + opt_level_map[opt_level], | 204 '-O' + opt_level_map[opt_level], |
196 '--pnacl-driver-append-LLC_FLAGS_EXTRA=-externalize', | 205 '--pnacl-driver-append-LLC_FLAGS_EXTRA=-externalize', |
197 '-o', obj_llc] + | 206 '-o', obj_llc] + |
198 (['--pnacl-driver-verbose'] if args.verbose else []) + | 207 (['--pnacl-driver-verbose'] if args.verbose else []) + |
199 args.llc_args + | 208 args.llc_args + |
200 [pexe], | 209 [pexe], |
201 echo=args.verbose) | 210 echo=args.verbose) |
202 if not args.sandbox: | 211 if not args.sandbox: |
203 shellcmd(( | 212 shellcmd(( |
204 '{objcopy} --redefine-sym _start=_user_start {obj}' | 213 '{objcopy} --redefine-sym _start=_user_start {obj}' |
205 ).format(objcopy=objcopy, obj=obj_llc), echo=args.verbose) | 214 ).format(objcopy=objcopy, obj=obj_llc), echo=args.verbose) |
206 # Generate llc syms file for consistency, even though it's not used. | 215 # Generate llc syms file for consistency, even though it's not used. |
207 shellcmd(( | 216 shellcmd(( |
208 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' | 217 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' |
209 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) | 218 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) |
210 | 219 |
211 if (args.force or | 220 if (args.force or |
212 NewerThanOrNotThere(pexe, obj_sz) or | 221 NewerThanOrNotThere(pexe, obj_sz) or |
213 NewerThanOrNotThere(pnacl_sz, obj_sz)): | 222 NewerThanOrNotThere(pnacl_sz, obj_sz)): |
214 # Run pnacl-sz regardless of hybrid mode. | 223 # Run pnacl-sz regardless of hybrid mode. |
215 shellcmd([pnacl_sz, | 224 shellcmd([pnacl_sz, |
216 '-O' + opt_level, | 225 '-O' + opt_level, |
217 '-bitcode-format=pnacl', | 226 '-bitcode-format=pnacl', |
218 '-filetype=' + args.filetype, | 227 '-filetype=' + args.filetype, |
219 '-o', obj_sz if args.filetype == 'obj' else asm_sz] + | 228 '-o', obj_sz if args.filetype == 'obj' else asm_sz, |
229 '-target=' + args.target] + | |
220 (['-externalize', | 230 (['-externalize', |
221 '-ffunction-sections', | 231 '-ffunction-sections', |
222 '-fdata-sections'] if hybrid else []) + | 232 '-fdata-sections'] if hybrid else []) + |
223 (['-sandbox'] if args.sandbox else []) + | 233 (['-sandbox'] if args.sandbox else []) + |
224 (['-enable-block-profile'] if | 234 (['-enable-block-profile'] if |
225 args.enable_block_profile and not args.sandbox else []) + | 235 args.enable_block_profile and not args.sandbox else []) + |
226 args.sz_args + | 236 args.sz_args + |
227 [pexe], | 237 [pexe], |
228 echo=args.verbose) | 238 echo=args.verbose) |
229 if args.filetype != 'obj': | 239 if args.filetype != 'obj': |
240 triple = { | |
241 'arm32': 'arm-nacl' if args.sandbox else 'arm', | |
242 'x8632': 'i686-nacl' if args.sandbox else 'i686', | |
243 }[args.target] | |
244 | |
230 shellcmd(( | 245 shellcmd(( |
231 'llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}' | 246 'llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}' |
232 ).format(asm=asm_sz, obj=obj_sz, | 247 ).format(asm=asm_sz, obj=obj_sz, triple=triple), |
233 triple='i686-nacl' if args.sandbox else 'i686'), | |
234 echo=args.verbose) | 248 echo=args.verbose) |
235 if not args.sandbox: | 249 if not args.sandbox: |
236 shellcmd(( | 250 shellcmd(( |
237 '{objcopy} --redefine-sym _start=_user_start {obj}' | 251 '{objcopy} --redefine-sym _start=_user_start {obj}' |
238 ).format(objcopy=objcopy, obj=obj_sz), echo=args.verbose) | 252 ).format(objcopy=objcopy, obj=obj_sz), echo=args.verbose) |
239 if hybrid: | 253 if hybrid: |
240 shellcmd(( | 254 shellcmd(( |
241 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' | 255 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' |
242 ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose) | 256 ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose) |
243 | 257 |
(...skipping 26 matching lines...) Expand all Loading... | |
270 ).format(objcopy=objcopy, | 284 ).format(objcopy=objcopy, |
271 whitelist=whitelist_sz, obj=obj_llc, | 285 whitelist=whitelist_sz, obj=obj_llc, |
272 weak=obj_llc_weak), | 286 weak=obj_llc_weak), |
273 echo=args.verbose) | 287 echo=args.verbose) |
274 else: | 288 else: |
275 shellcmd(( | 289 shellcmd(( |
276 '{objcopy} {obj} {weak}' | 290 '{objcopy} {obj} {weak}' |
277 ).format(objcopy=objcopy, obj=obj_llc, weak=obj_llc_weak), | 291 ).format(objcopy=objcopy, obj=obj_llc, weak=obj_llc_weak), |
278 echo=args.verbose) | 292 echo=args.verbose) |
279 obj_partial = pexe_base + '.o' | 293 obj_partial = pexe_base + '.o' |
294 ld = { | |
295 'arm32': 'arm-linux-gnueabihf-ld', | |
296 'x8632': 'ld', | |
297 }[args.target] | |
298 emulation = { | |
299 'arm32': 'armelf_linux_eabi', | |
300 'x8632': 'elf_i386', | |
301 }[args.target] | |
280 shellcmd(( | 302 shellcmd(( |
281 'ld -r -m elf_i386 -o {partial} {sz} {llc}' | 303 '{ld} -r -m {emulation} -o {partial} {sz} {llc}' |
282 ).format(partial=obj_partial, sz=obj_sz_weak, llc=obj_llc_weak), | 304 ).format(ld=ld, emulation=emulation, partial=obj_partial, |
305 sz=obj_sz_weak, llc=obj_llc_weak), | |
283 echo=args.verbose) | 306 echo=args.verbose) |
284 shellcmd(( | 307 shellcmd(( |
285 '{objcopy} -w --localize-symbol="*" {partial}' | 308 '{objcopy} -w --localize-symbol="*" {partial}' |
286 ).format(objcopy=objcopy, partial=obj_partial), | 309 ).format(objcopy=objcopy, partial=obj_partial), |
287 echo=args.verbose) | 310 echo=args.verbose) |
288 shellcmd(( | 311 shellcmd(( |
289 '{objcopy} --globalize-symbol={start} ' + | 312 '{objcopy} --globalize-symbol={start} ' + |
290 '--globalize-symbol=__Sz_block_profile_info {partial}' | 313 '--globalize-symbol=__Sz_block_profile_info {partial}' |
291 ).format(objcopy=objcopy, partial=obj_partial, | 314 ).format(objcopy=objcopy, partial=obj_partial, |
292 start='_start' if args.sandbox else '_user_start'), | 315 start='_start' if args.sandbox else '_user_start'), |
293 echo=args.verbose) | 316 echo=args.verbose) |
294 | 317 |
295 # Run the linker regardless of hybrid mode. | 318 # Run the linker regardless of hybrid mode. |
296 linker = ( | |
297 '{root}/../third_party/llvm-build/Release+Asserts/bin/clang' | |
298 ).format(root=nacl_root) | |
299 if args.sandbox: | 319 if args.sandbox: |
320 assert args.target in ['x8632'], \ | |
321 '-sandbox is not available for %s' % args.target | |
300 linklib = ('{root}/toolchain/linux_x86/pnacl_newlib_raw/translator/' + | 322 linklib = ('{root}/toolchain/linux_x86/pnacl_newlib_raw/translator/' + |
301 'x86-32/lib').format(root=nacl_root) | 323 'x86-32/lib').format(root=nacl_root) |
302 shellcmd(( | 324 shellcmd(( |
303 '{gold} -nostdlib --no-fix-cortex-a8 --eh-frame-hdr -z text ' + | 325 '{gold} -nostdlib --no-fix-cortex-a8 --eh-frame-hdr -z text ' + |
304 '--build-id --entry=__pnacl_start -static ' + | 326 '--build-id --entry=__pnacl_start -static ' + |
305 '{linklib}/crtbegin.o {partial} ' + | 327 '{linklib}/crtbegin.o {partial} ' + |
306 '{root}/toolchain_build/src/subzero/build/runtime/' + | 328 '{root}/toolchain_build/src/subzero/build/runtime/' + |
307 'szrt_sb_x8632.o ' + | 329 'szrt_sb_{target}.o ' + |
308 '{linklib}/libpnacl_irt_shim_dummy.a --start-group ' + | 330 '{linklib}/libpnacl_irt_shim_dummy.a --start-group ' + |
309 '{linklib}/libgcc.a {linklib}/libcrt_platform.a ' + | 331 '{linklib}/libgcc.a {linklib}/libcrt_platform.a ' + |
310 '--end-group {linklib}/crtend.o --undefined=_start ' + | 332 '--end-group {linklib}/crtend.o --undefined=_start ' + |
311 '--defsym=__Sz_AbsoluteZero=0 ' + | 333 '--defsym=__Sz_AbsoluteZero=0 ' + |
312 '-o {exe}' | 334 '-o {exe}' |
313 ).format(gold=gold, linklib=linklib, partial=obj_partial, exe=exe, | 335 ).format(gold=gold, linklib=linklib, partial=obj_partial, exe=exe, |
314 root=nacl_root), | 336 root=nacl_root, target=args.target), |
315 echo=args.verbose) | 337 echo=args.verbose) |
316 else: | 338 else: |
339 linker = { | |
340 'arm32': '/usr/bin/arm-linux-gnueabihf-g++', | |
341 'x8632': ('{root}/../third_party/llvm-build/Release+Asserts/bin/clang' | |
342 ).format(root=nacl_root) | |
343 }[args.target] | |
344 | |
345 extra_linker_args = ' '.join({ | |
346 'arm32': ['-mcpu=cortex-a9'], | |
347 'x8632': ['-m32'] | |
348 }[args.target]) | |
349 | |
350 lib_dir = { | |
351 'arm32': 'arm-linux', | |
352 'x8632': 'x86-32-linux', | |
353 }[args.target] | |
354 | |
317 shellcmd(( | 355 shellcmd(( |
318 '{ld} -m32 {partial} -o {exe} ' + | 356 '{ld} {ld_extra_args} {partial} -o {exe} ' + |
319 # Keep the rest of this command line (except szrt_native_x8632.o) in | 357 # Keep the rest of this command line (except szrt_native_x8632.o) in |
320 # sync with RunHostLD() in pnacl-translate.py. | 358 # sync with RunHostLD() in pnacl-translate.py. |
321 '{root}/toolchain/linux_x86/pnacl_newlib_raw/translator/' + | 359 '{root}/toolchain/linux_x86/pnacl_newlib_raw/translator/' + |
322 'x86-32-linux/lib/' + | 360 '{lib_dir}/lib/' + |
323 '{{unsandboxed_irt,irt_random,irt_query_list}}.o ' + | 361 '{{unsandboxed_irt,irt_random,irt_query_list}}.o ' + |
324 '{root}/toolchain_build/src/subzero/build/runtime/' + | 362 '{root}/toolchain_build/src/subzero/build/runtime/' + |
325 'szrt_native_x8632.o -lpthread -lrt ' + | 363 'szrt_native_{target}.o -lpthread -lrt ' + |
326 '-Wl,--defsym=__Sz_AbsoluteZero=0' | 364 '-Wl,--defsym=__Sz_AbsoluteZero=0' |
327 ).format(ld=linker, partial=obj_partial, exe=exe, root=nacl_root), | 365 ).format(ld=linker, ld_extra_args=extra_linker_args, |
366 partial=obj_partial, exe=exe, root=nacl_root, | |
367 target=args.target, lib_dir=lib_dir), | |
328 echo=args.verbose) | 368 echo=args.verbose) |
329 | 369 |
330 # Put the extra verbose printing at the end. | 370 # Put the extra verbose printing at the end. |
331 if args.verbose: | 371 if args.verbose: |
332 print 'PATH: {path}'.format(path=path_addition) | 372 print 'PATH: {path}'.format(path=path_addition) |
333 if hybrid: | 373 if hybrid: |
334 print 'include={regex}'.format(regex=re_include_str) | 374 print 'include={regex}'.format(regex=re_include_str) |
335 print 'exclude={regex}'.format(regex=re_exclude_str) | 375 print 'exclude={regex}'.format(regex=re_exclude_str) |
336 print 'default_match={dm}'.format(dm=default_match) | 376 print 'default_match={dm}'.format(dm=default_match) |
337 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) | 377 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) |
338 | 378 |
339 if __name__ == '__main__': | 379 if __name__ == '__main__': |
340 main() | 380 main() |
OLD | NEW |