| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 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 | 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 # IMPORTANT NOTE: If you make local mods to this file, you must run: | 6 # IMPORTANT NOTE: If you make local mods to this file, you must run: |
| 7 # % pnacl/build.sh driver | 7 # % pnacl/build.sh driver |
| 8 # in order for them to take effect in the scons build. This command | 8 # in order for them to take effect in the scons build. This command |
| 9 # updates the copy in the toolchain/ tree. | 9 # updates the copy in the toolchain/ tree. |
| 10 # | 10 # |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 'DEFAULTLIBS': '${ALLOW_CXX_EXCEPTIONS ? ' + | 90 'DEFAULTLIBS': '${ALLOW_CXX_EXCEPTIONS ? ' + |
| 91 '${LIBGCC_EH}} -l:libgcc.a ${MISC_LIBS}', | 91 '${LIBGCC_EH}} -l:libgcc.a ${MISC_LIBS}', |
| 92 | 92 |
| 93 'MISC_LIBS': | 93 'MISC_LIBS': |
| 94 # TODO(pdox): | 94 # TODO(pdox): |
| 95 # Move libcrt_platform into the __pnacl namespace, | 95 # Move libcrt_platform into the __pnacl namespace, |
| 96 # with stubs to access it from newlib. | 96 # with stubs to access it from newlib. |
| 97 '${LIBMODE_NEWLIB ? -l:libcrt_platform.a} ', | 97 '${LIBMODE_NEWLIB ? -l:libcrt_platform.a} ', |
| 98 | 98 |
| 99 # Determine whether or not to use bitcode metadata to generate .so stubs | |
| 100 # for the final link. | |
| 101 'USE_META': '0', | |
| 102 | |
| 103 'TRIPLE' : '${TRIPLE_%ARCH%}', | 99 'TRIPLE' : '${TRIPLE_%ARCH%}', |
| 104 'TRIPLE_ARM' : 'armv7a-none-nacl-gnueabi', | 100 'TRIPLE_ARM' : 'armv7a-none-nacl-gnueabi', |
| 105 'TRIPLE_X8632': 'i686-none-nacl-gnu', | 101 'TRIPLE_X8632': 'i686-none-nacl-gnu', |
| 106 'TRIPLE_X8664': 'x86_64-none-nacl-gnu', | 102 'TRIPLE_X8664': 'x86_64-none-nacl-gnu', |
| 107 'TRIPLE_MIPS32': 'mipsel-none-nacl-gnu', | 103 'TRIPLE_MIPS32': 'mipsel-none-nacl-gnu', |
| 108 | 104 |
| 109 'LLC_FLAGS_COMMON': '${PIC ? -relocation-model=pic} ' + | 105 'LLC_FLAGS_COMMON': '${PIC ? -relocation-model=pic} ' + |
| 110 # -force-tls-non-pic makes the code generator (llc) | 106 # -force-tls-non-pic makes the code generator (llc) |
| 111 # do the work that would otherwise be done by | 107 # do the work that would otherwise be done by |
| 112 # linker rewrites which are quite messy in the nacl | 108 # linker rewrites which are quite messy in the nacl |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 # do auto feature detection based on CPUID, but constrained by what is | 156 # do auto feature detection based on CPUID, but constrained by what is |
| 161 # accepted by NaCl validators. | 157 # accepted by NaCl validators. |
| 162 'LLC_MCPU' : '-mcpu=${LLC_MCPU_%ARCH%}', | 158 'LLC_MCPU' : '-mcpu=${LLC_MCPU_%ARCH%}', |
| 163 'LLC_MCPU_ARM' : 'cortex-a9', | 159 'LLC_MCPU_ARM' : 'cortex-a9', |
| 164 'LLC_MCPU_X8632' : 'pentium4', | 160 'LLC_MCPU_X8632' : 'pentium4', |
| 165 'LLC_MCPU_X8664' : 'core2', | 161 'LLC_MCPU_X8664' : 'core2', |
| 166 'LLC_MCPU_MIPS32' : 'mips32r2', | 162 'LLC_MCPU_MIPS32' : 'mips32r2', |
| 167 | 163 |
| 168 # Note: this is only used in the unsandboxed case | 164 # Note: this is only used in the unsandboxed case |
| 169 'RUN_LLC' : '${LLVM_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' | 165 'RUN_LLC' : '${LLVM_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' |
| 170 '${input} -o ${output} ' + | 166 '${input} -o ${output} ', |
| 171 '-metadata-text ${output}.meta', | |
| 172 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC | 167 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC |
| 173 # for testing. Defaults to 1Gbps (effectively unlimited). | 168 # for testing. Defaults to 1Gbps (effectively unlimited). |
| 174 'BITCODE_STREAM_RATE' : '1000000000', | 169 'BITCODE_STREAM_RATE' : '1000000000', |
| 175 } | 170 } |
| 176 | 171 |
| 177 | 172 |
| 178 TranslatorPatterns = [ | 173 TranslatorPatterns = [ |
| 179 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), | 174 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), |
| 180 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), | 175 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), |
| 181 | 176 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 ( '--noirt', "env.set('USE_IRT', '0')\n" | 211 ( '--noirt', "env.set('USE_IRT', '0')\n" |
| 217 "env.append('LD_FLAGS', '--noirt')"), | 212 "env.append('LD_FLAGS', '--noirt')"), |
| 218 ( '--noirtshim', "env.set('USE_IRT_SHIM', '0')"), | 213 ( '--noirtshim', "env.set('USE_IRT_SHIM', '0')"), |
| 219 ( '--newlib-shared-experiment', "env.set('NEWLIB_SHARED_EXPERIMENT', '1')"), | 214 ( '--newlib-shared-experiment', "env.set('NEWLIB_SHARED_EXPERIMENT', '1')"), |
| 220 ( '(--pnacl-nativeld=.+)', "env.append('LD_FLAGS', $0)"), | 215 ( '(--pnacl-nativeld=.+)', "env.append('LD_FLAGS', $0)"), |
| 221 | 216 |
| 222 # Allowing C++ exception handling causes a specific set of native objects to | 217 # Allowing C++ exception handling causes a specific set of native objects to |
| 223 # get linked into the nexe. | 218 # get linked into the nexe. |
| 224 ( '--pnacl-allow-exceptions', "env.set('ALLOW_CXX_EXCEPTIONS', '1')"), | 219 ( '--pnacl-allow-exceptions', "env.set('ALLOW_CXX_EXCEPTIONS', '1')"), |
| 225 | 220 |
| 226 # Toggle the use of ELF-stubs / bitcode metadata, which represent real .so | |
| 227 # files in the final native link. | |
| 228 # There may be cases where this will not work (e.g., when the final link | |
| 229 # includes native .o files, where its imports / exports were not known | |
| 230 # at bitcode link time, and not added to the bitcode metadata). | |
| 231 ( '-usemeta', "env.set('USE_META', '1')"), | |
| 232 ( '-nousemeta', "env.set('USE_META', '0')"), | |
| 233 | |
| 234 ( '-rpath-link=(.+)', "env.append('LD_FLAGS', '-L'+$0)"), | 221 ( '-rpath-link=(.+)', "env.append('LD_FLAGS', '-L'+$0)"), |
| 235 | 222 |
| 236 ( '-fPIC', "env.set('PIC', '1')"), | 223 ( '-fPIC', "env.set('PIC', '1')"), |
| 237 | 224 |
| 238 ( '-Wl,(.*)', "env.append('LD_FLAGS', *($0).split(','))"), | 225 ( '-Wl,(.*)', "env.append('LD_FLAGS', *($0).split(','))"), |
| 239 ( '-bitcode-stream-rate=([0-9]+)', "env.set('BITCODE_STREAM_RATE', $0)"), | 226 ( '-bitcode-stream-rate=([0-9]+)', "env.set('BITCODE_STREAM_RATE', $0)"), |
| 240 | 227 |
| 241 ( '(-.*)', driver_tools.UnrecognizedOption), | 228 ( '(-.*)', driver_tools.UnrecognizedOption), |
| 242 | 229 |
| 243 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), | 230 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 if infile: | 458 if infile: |
| 472 inputs = ListReplace(inputs, | 459 inputs = ListReplace(inputs, |
| 473 '__BITCODE__', | 460 '__BITCODE__', |
| 474 '--llc-translated-file=' + infile) | 461 '--llc-translated-file=' + infile) |
| 475 ToggleDefaultCommandlineLD(inputs, infile) | 462 ToggleDefaultCommandlineLD(inputs, infile) |
| 476 env.set('ld_inputs', *inputs) | 463 env.set('ld_inputs', *inputs) |
| 477 args = env.get('LD_ARGS') + ['-o', outfile] | 464 args = env.get('LD_ARGS') + ['-o', outfile] |
| 478 if not env.getbool('SHARED') and env.getbool('STDLIB'): | 465 if not env.getbool('SHARED') and env.getbool('STDLIB'): |
| 479 args += env.get('LD_ARGS_ENTRY') | 466 args += env.get('LD_ARGS_ENTRY') |
| 480 args += env.get('LD_FLAGS') | 467 args += env.get('LD_FLAGS') |
| 481 # If there is bitcode, there is also a metadata file. | |
| 482 if infile and env.getbool('USE_META'): | |
| 483 args += ['--metadata', '%s.meta' % infile] | |
| 484 driver_tools.RunDriver('nativeld', args) | 468 driver_tools.RunDriver('nativeld', args) |
| 485 | 469 |
| 486 def RunLLC(infile, outfile, filetype): | 470 def RunLLC(infile, outfile, filetype): |
| 487 env.push() | 471 env.push() |
| 488 env.setmany(input=infile, output=outfile, filetype=filetype) | 472 env.setmany(input=infile, output=outfile, filetype=filetype) |
| 489 if env.getbool('SANDBOXED'): | 473 if env.getbool('SANDBOXED'): |
| 490 is_shared, soname, needed = RunLLCSandboxed() | 474 is_shared, soname, needed = RunLLCSandboxed() |
| 491 env.pop() | 475 env.pop() |
| 492 # soname and dt_needed libs are returned from LLC and passed to LD | 476 # soname and dt_needed libs are returned from LLC and passed to LD |
| 493 driver_tools.SetBitcodeMetadata(infile, is_shared, soname, needed) | 477 driver_tools.SetBitcodeMetadata(infile, is_shared, soname, needed) |
| 494 else: | 478 else: |
| 495 driver_tools.Run("${RUN_LLC}") | 479 driver_tools.Run("${RUN_LLC}") |
| 496 # As a side effect, this creates a temporary file | |
| 497 if not env.getbool('SAVE_TEMPS'): | |
| 498 TempFiles.add(outfile + '.meta') | |
| 499 env.pop() | 480 env.pop() |
| 500 return 0 | 481 return 0 |
| 501 | 482 |
| 502 def RunLLCSandboxed(): | 483 def RunLLCSandboxed(): |
| 503 driver_tools.CheckTranslatorPrerequisites() | 484 driver_tools.CheckTranslatorPrerequisites() |
| 504 infile = env.getone('input') | 485 infile = env.getone('input') |
| 505 outfile = env.getone('output') | 486 outfile = env.getone('output') |
| 506 if not driver_tools.IsBitcode(infile): | 487 if not driver_tools.IsBitcode(infile): |
| 507 Log.Fatal('Input to sandboxed translator must be bitcode') | 488 Log.Fatal('Input to sandboxed translator must be bitcode') |
| 508 script = MakeSelUniversalScriptForLLC(infile, outfile) | 489 script = MakeSelUniversalScriptForLLC(infile, outfile) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 555 |
| 575 ADVANCED OPTIONS: | 556 ADVANCED OPTIONS: |
| 576 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. | 557 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. |
| 577 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as | 558 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as |
| 578 turns cpu features on and off. | 559 turns cpu features on and off. |
| 579 -S Generate native assembly only. | 560 -S Generate native assembly only. |
| 580 -c Generate native object file only. | 561 -c Generate native object file only. |
| 581 --pnacl-sb Use the translator which runs inside the NaCl sandbox. | 562 --pnacl-sb Use the translator which runs inside the NaCl sandbox. |
| 582 -O[0-3] Change translation-time optimization level. | 563 -O[0-3] Change translation-time optimization level. |
| 583 """ | 564 """ |
| OLD | NEW |