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