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 # |
11 | 11 |
12 import driver_tools | 12 import driver_tools |
13 import filetype | 13 import filetype |
14 import ldtools | 14 import ldtools |
| 15 import os |
15 import pathtools | 16 import pathtools |
16 import shutil | 17 import shutil |
17 from driver_env import env | 18 from driver_env import env |
18 from driver_log import Log, TempFiles | 19 from driver_log import Log, TempFiles |
19 | 20 |
20 import re | 21 import re |
21 import subprocess | 22 import subprocess |
22 | 23 |
23 EXTRA_ENV = { | 24 EXTRA_ENV = { |
24 'PIC' : '0', | 25 'PIC' : '0', |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 '${CRTEND}', | 91 '${CRTEND}', |
91 | 92 |
92 'DEFAULTLIBS': '${ALLOW_CXX_EXCEPTIONS ? ' + | 93 'DEFAULTLIBS': '${ALLOW_CXX_EXCEPTIONS ? ' + |
93 '${LIBGCC_EH}} -l:libgcc.a -l:libcrt_platform.a ', | 94 '${LIBGCC_EH}} -l:libgcc.a -l:libcrt_platform.a ', |
94 | 95 |
95 'TRIPLE' : '${TRIPLE_%ARCH%}', | 96 'TRIPLE' : '${TRIPLE_%ARCH%}', |
96 'TRIPLE_ARM' : 'armv7a-none-nacl-gnueabi', | 97 'TRIPLE_ARM' : 'armv7a-none-nacl-gnueabi', |
97 'TRIPLE_X8632': 'i686-none-nacl-gnu', | 98 'TRIPLE_X8632': 'i686-none-nacl-gnu', |
98 'TRIPLE_X8664': 'x86_64-none-nacl-gnu', | 99 'TRIPLE_X8664': 'x86_64-none-nacl-gnu', |
99 'TRIPLE_MIPS32': 'mipsel-none-nacl-gnu', | 100 'TRIPLE_MIPS32': 'mipsel-none-nacl-gnu', |
| 101 'TRIPLE_LINUX_X8632': 'i686-linux-gnu', |
100 | 102 |
101 'LLC_FLAGS_COMMON': '${PIC ? -relocation-model=pic} ' + | 103 'LLC_FLAGS_COMMON': '${PIC ? -relocation-model=pic} ' + |
102 # -force-tls-non-pic makes the code generator (llc) | 104 # -force-tls-non-pic makes the code generator (llc) |
103 # do the work that would otherwise be done by | 105 # do the work that would otherwise be done by |
104 # linker rewrites which are quite messy in the nacl | 106 # linker rewrites which are quite messy in the nacl |
105 # case and hence have not been implemented in gold | 107 # case and hence have not been implemented in gold |
106 '${PIC && !SHARED ? -force-tls-non-pic} ' + | 108 '${PIC && !SHARED ? -force-tls-non-pic} ' + |
107 # this translates the pexe one function at a time | 109 # this translates the pexe one function at a time |
108 # which is also what the streaming translation does | 110 # which is also what the streaming translation does |
109 '-reduce-memory-footprint', | 111 '-reduce-memory-footprint', |
110 | 112 |
111 | 113 |
112 'LLC_FLAGS_ARM' : | 114 'LLC_FLAGS_ARM' : |
113 ('-arm-reserve-r9 -sfi-disable-cp ' + | 115 ('-arm-reserve-r9 -sfi-disable-cp ' + |
114 '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data ' + | 116 '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data ' + |
115 '-no-inline-jumptables -float-abi=hard -mattr=+neon'), | 117 '-no-inline-jumptables -float-abi=hard -mattr=+neon'), |
116 | 118 |
117 'LLC_FLAGS_X8632' : '', | 119 'LLC_FLAGS_X8632' : '', |
118 'LLC_FLAGS_X8664' : '', | 120 'LLC_FLAGS_X8664' : '', |
119 | 121 |
120 'LLC_FLAGS_MIPS32': '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data', | 122 'LLC_FLAGS_MIPS32': '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data', |
121 | 123 |
| 124 # When linking against Linux glibc, don't use %gs:0 to read the |
| 125 # thread pointer because that's not compatible with glibc's use of |
| 126 # %gs. |
| 127 'LLC_FLAGS_LINUX_X8632' : '-mtls-use-call', |
| 128 |
122 # LLC flags which set the target and output type. | 129 # LLC flags which set the target and output type. |
123 'LLC_FLAGS_TARGET' : '-mtriple=${TRIPLE} -filetype=${outfiletype}', | 130 'LLC_FLAGS_TARGET' : '-mtriple=${TRIPLE} -filetype=${outfiletype}', |
124 | 131 |
125 # Append additional non-default flags here. | 132 # Append additional non-default flags here. |
126 'LLC_FLAGS_EXTRA' : '${FAST_TRANSLATION ? ${LLC_FLAGS_FAST}} ' + | 133 'LLC_FLAGS_EXTRA' : '${FAST_TRANSLATION ? ${LLC_FLAGS_FAST}} ' + |
127 '${#OPT_LEVEL ? -O${OPT_LEVEL}} ' + | 134 '${#OPT_LEVEL ? -O${OPT_LEVEL}} ' + |
128 '${OPT_LEVEL == 0 ? -disable-fp-elim}', | 135 '${OPT_LEVEL == 0 ? -disable-fp-elim}', |
129 | 136 |
130 # Opt level from command line (if any) | 137 # Opt level from command line (if any) |
131 'OPT_LEVEL' : '', | 138 'OPT_LEVEL' : '', |
132 | 139 |
133 # faster translation == slower code | 140 # faster translation == slower code |
134 'LLC_FLAGS_FAST' : '${LLC_FLAGS_FAST_%ARCH%}', | 141 'LLC_FLAGS_FAST' : '${LLC_FLAGS_FAST_%ARCH%}' |
| 142 # This, surprisingly, makes a measurable difference |
| 143 ' -tail-merge-threshold=20', |
135 | 144 |
136 'LLC_FLAGS_FAST_X8632': '-O0 ' + | 145 'LLC_FLAGS_FAST_X8632': '-O0 ', |
137 # This, surprisingly, makes a measurable difference | 146 'LLC_FLAGS_FAST_X8664': '-O0 ', |
138 '-tail-merge-threshold=20', | 147 'LLC_FLAGS_FAST_ARM': '-O0 ', |
139 'LLC_FLAGS_FAST_X8664': '-O0 ' + | 148 'LLC_FLAGS_FAST_MIPS32': '-fast-isel', |
140 '-tail-merge-threshold=20', | 149 'LLC_FLAGS_FAST_LINUX_X8632': '-O0', |
141 'LLC_FLAGS_FAST_ARM': '-O0 ' + | |
142 '-tail-merge-threshold=20', | |
143 'LLC_FLAGS_FAST_MIPS32': '-fast-isel -tail-merge-threshold=20', | |
144 | 150 |
145 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_%ARCH%} ' + | 151 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_%ARCH%} ' + |
146 '${LLC_FLAGS_EXTRA}', | 152 '${LLC_FLAGS_EXTRA}', |
147 | 153 |
148 # CPU that is representative of baseline feature requirements for NaCl | 154 # CPU that is representative of baseline feature requirements for NaCl |
149 # and/or chrome. We may want to make this more like "-mtune" | 155 # and/or chrome. We may want to make this more like "-mtune" |
150 # by specifying both "-mcpu=X" and "-mattr=+feat1,-feat2,...". | 156 # by specifying both "-mcpu=X" and "-mattr=+feat1,-feat2,...". |
151 # Note: this may be different from the in-browser translator, which may | 157 # Note: this may be different from the in-browser translator, which may |
152 # do auto feature detection based on CPUID, but constrained by what is | 158 # do auto feature detection based on CPUID, but constrained by what is |
153 # accepted by NaCl validators. | 159 # accepted by NaCl validators. |
154 'LLC_MCPU' : '-mcpu=${LLC_MCPU_%ARCH%}', | 160 'LLC_MCPU' : '-mcpu=${LLC_MCPU_%ARCH%}', |
155 'LLC_MCPU_ARM' : 'cortex-a9', | 161 'LLC_MCPU_ARM' : 'cortex-a9', |
156 'LLC_MCPU_X8632' : 'pentium4', | 162 'LLC_MCPU_X8632' : 'pentium4', |
157 'LLC_MCPU_X8664' : 'core2', | 163 'LLC_MCPU_X8664' : 'core2', |
158 'LLC_MCPU_MIPS32' : 'mips32r2', | 164 'LLC_MCPU_MIPS32' : 'mips32r2', |
| 165 'LLC_MCPU_LINUX_X8632' : '${LLC_MCPU_X8632}', |
159 | 166 |
160 # Note: this is only used in the unsandboxed case | 167 # Note: this is only used in the unsandboxed case |
161 'RUN_LLC' : '${LLVM_PNACL_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' | 168 'RUN_LLC' : '${LLVM_PNACL_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' |
162 '${input} -o ${output} ', | 169 '${input} -o ${output} ', |
163 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC | 170 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC |
164 # for testing. Defaults to 1Gbps (effectively unlimited). | 171 # for testing. Defaults to 1Gbps (effectively unlimited). |
165 'BITCODE_STREAM_RATE' : '1000000000', | 172 'BITCODE_STREAM_RATE' : '1000000000', |
166 } | 173 } |
167 | 174 |
168 | 175 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 if env.getbool('STATIC'): | 306 if env.getbool('STATIC'): |
300 output_type = 'nexe' | 307 output_type = 'nexe' |
301 else: | 308 else: |
302 # Until we stabilize the ABI for shared libraries, | 309 # Until we stabilize the ABI for shared libraries, |
303 # assume that pnacl-translate only handles pexes -> nexes, | 310 # assume that pnacl-translate only handles pexes -> nexes, |
304 # to avoid a dependency on bitcode metadata. | 311 # to avoid a dependency on bitcode metadata. |
305 output_type = 'nexe' | 312 output_type = 'nexe' |
306 env.set('STATIC', '1') | 313 env.set('STATIC', '1') |
307 | 314 |
308 assert output_type in ('so','nexe') | 315 assert output_type in ('so','nexe') |
309 RunLD(ofile, output) | 316 if env.getone('ARCH') == 'LINUX_X8632': |
| 317 RunHostLD(ofile, output) |
| 318 else: |
| 319 RunLD(ofile, output) |
310 return 0 | 320 return 0 |
311 | 321 |
312 def RunAS(infile, outfile): | 322 def RunAS(infile, outfile): |
313 driver_tools.RunDriver('as', [infile, '-o', outfile]) | 323 driver_tools.RunDriver('as', [infile, '-o', outfile]) |
314 | 324 |
315 def ListReplace(items, old, new): | 325 def ListReplace(items, old, new): |
316 ret = [] | 326 ret = [] |
317 for k in items: | 327 for k in items: |
318 if k == old: | 328 if k == old: |
319 ret.append(new) | 329 ret.append(new) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 inputs.remove('__BITCODE__') | 391 inputs.remove('__BITCODE__') |
382 inputs = ['--llc-translated-file=' + infile] + inputs | 392 inputs = ['--llc-translated-file=' + infile] + inputs |
383 ToggleDefaultCommandlineLD(inputs, infile) | 393 ToggleDefaultCommandlineLD(inputs, infile) |
384 env.set('ld_inputs', *inputs) | 394 env.set('ld_inputs', *inputs) |
385 args = env.get('LD_ARGS') + ['-o', outfile] | 395 args = env.get('LD_ARGS') + ['-o', outfile] |
386 if not env.getbool('SHARED') and env.getbool('USE_STDLIB'): | 396 if not env.getbool('SHARED') and env.getbool('USE_STDLIB'): |
387 args += env.get('LD_ARGS_ENTRY') | 397 args += env.get('LD_ARGS_ENTRY') |
388 args += env.get('LD_FLAGS') | 398 args += env.get('LD_FLAGS') |
389 driver_tools.RunDriver('nativeld', args) | 399 driver_tools.RunDriver('nativeld', args) |
390 | 400 |
| 401 def RunHostLD(infile, outfile): |
| 402 driver_tools.Run(['objcopy', '--redefine-sym', '_start=_user_start', infile]) |
| 403 lib_dir = env.getone('BASE_LIB_NATIVE') + 'linux-x86-32' |
| 404 driver_tools.Run(['gcc', '-m32', infile, |
| 405 os.path.join(lib_dir, 'unsandboxed_irt.o'), |
| 406 '-o', outfile]) |
| 407 |
391 def RunLLC(infile, outfile, outfiletype): | 408 def RunLLC(infile, outfile, outfiletype): |
392 env.push() | 409 env.push() |
393 env.setmany(input=infile, output=outfile, outfiletype=outfiletype) | 410 env.setmany(input=infile, output=outfile, outfiletype=outfiletype) |
394 if env.getbool('SANDBOXED'): | 411 if env.getbool('SANDBOXED'): |
395 is_shared, soname, needed = RunLLCSandboxed() | 412 is_shared, soname, needed = RunLLCSandboxed() |
396 # Ignore is_shared, soname, and needed for now, since we aren't | 413 # Ignore is_shared, soname, and needed for now, since we aren't |
397 # dealing with bitcode shared libraries. | 414 # dealing with bitcode shared libraries. |
398 env.pop() | 415 env.pop() |
399 else: | 416 else: |
400 args = ["${RUN_LLC}"] | 417 args = ["${RUN_LLC}"] |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 499 |
483 ADVANCED OPTIONS: | 500 ADVANCED OPTIONS: |
484 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. | 501 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. |
485 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as | 502 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as |
486 turns cpu features on and off. | 503 turns cpu features on and off. |
487 -S Generate native assembly only. | 504 -S Generate native assembly only. |
488 -c Generate native object file only. | 505 -c Generate native object file only. |
489 --pnacl-sb Use the translator which runs inside the NaCl sandbox. | 506 --pnacl-sb Use the translator which runs inside the NaCl sandbox. |
490 -O[0-3] Change translation-time optimization level. | 507 -O[0-3] Change translation-time optimization level. |
491 """ | 508 """ |
OLD | NEW |