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 subprocess | 5 import subprocess |
6 import sys | 6 import sys |
7 import tempfile | 7 import tempfile |
8 | 8 |
9 import targets | 9 import targets |
10 from szbuild import LinkNonsfi | 10 from szbuild import LinkNonsfi |
11 from utils import FindBaseNaCl, GetObjcopyCmd, get_sfi_string, shellcmd | 11 from utils import FindBaseNaCl, GetObjcopyCmd, get_sfi_string, shellcmd |
12 | 12 |
13 def main(): | 13 def main(): |
14 """Builds a cross-test binary for comparing Subzero and llc translation. | 14 """Builds a cross-test binary for comparing Subzero and llc translation. |
15 | 15 |
16 Each --test argument is compiled once by llc and once by Subzero. C/C++ | 16 Each --test argument is compiled once by llc and once by Subzero. C/C++ |
17 tests are first compiled down to PNaCl bitcode using pnacl-clang and | 17 tests are first compiled down to PNaCl bitcode using pnacl-clang and |
18 pnacl-opt. The --prefix argument ensures that symbol names are different | 18 pnacl-opt. The --prefix argument ensures that symbol names are different |
19 between the two object files, to avoid linking errors. | 19 between the two object files, to avoid linking errors. |
20 | 20 |
21 There is also a --driver argument that specifies the C/C++ file that calls | 21 There is also a --driver argument that specifies the C/C++ file that calls |
22 the test functions with a variety of interesting inputs and compares their | 22 the test functions with a variety of interesting inputs and compares their |
23 results. | 23 results. |
24 | 24 |
25 """ | 25 """ |
26 # arch_map maps a Subzero target string to TargetInfo (e.g., triple). | 26 # arch_map maps a Subzero target string to TargetInfo (e.g., triple). |
27 arch_map = { 'x8632': targets.X8632Target, | 27 arch_map = { 'x8632': targets.X8632Target, |
28 'x8664': targets.X8664Target, | 28 'x8664': targets.X8664Target, |
29 'arm32': targets.ARM32Target } | 29 'arm32': targets.ARM32Target, |
| 30 'mips32': targets.MIPS32Target} |
30 arch_sz_flags = { 'x8632': [], | 31 arch_sz_flags = { 'x8632': [], |
31 'x8664': [], | 32 'x8664': [], |
32 # For ARM, test a large stack offset as well. +/- 4095 is | 33 # For ARM, test a large stack offset as well. +/- 4095 is |
33 # the limit, so test somewhere near that boundary. | 34 # the limit, so test somewhere near that boundary. |
34 'arm32': ['--test-stack-extra', '4084'] | 35 'arm32': ['--test-stack-extra', '4084'], |
| 36 'mips32': ['--test-stack-extra', '4084'] |
35 } | 37 } |
36 arch_llc_flags_extra = { | 38 arch_llc_flags_extra = { |
37 # Use sse2 instructions regardless of input -mattr | 39 # Use sse2 instructions regardless of input -mattr |
38 # argument to avoid differences in (undefined) behavior of | 40 # argument to avoid differences in (undefined) behavior of |
39 # converting NaN to int. | 41 # converting NaN to int. |
40 'x8632': ['-mattr=sse2'], | 42 'x8632': ['-mattr=sse2'], |
41 'x8664': ['-mattr=sse2'], | 43 'x8664': ['-mattr=sse2'], |
42 'arm32': [], | 44 'arm32': [], |
| 45 'mips32':[], |
43 } | 46 } |
44 desc = 'Build a cross-test that compares Subzero and llc translation.' | 47 desc = 'Build a cross-test that compares Subzero and llc translation.' |
45 argparser = argparse.ArgumentParser(description=desc) | 48 argparser = argparse.ArgumentParser(description=desc) |
46 argparser.add_argument('--test', required=True, action='append', | 49 argparser.add_argument('--test', required=True, action='append', |
47 metavar='TESTFILE_LIST', | 50 metavar='TESTFILE_LIST', |
48 help='List of C/C++/.ll files with test functions') | 51 help='List of C/C++/.ll files with test functions') |
49 argparser.add_argument('--driver', required=True, | 52 argparser.add_argument('--driver', required=True, |
50 metavar='DRIVER', | 53 metavar='DRIVER', |
51 help='Driver program') | 54 help='Driver program') |
52 argparser.add_argument('--target', required=False, default='x8632', | 55 argparser.add_argument('--target', required=False, default='x8632', |
53 choices=arch_map.keys(), | 56 choices=arch_map.keys(), |
54 metavar='TARGET', | 57 metavar='TARGET', |
55 help='Translation target architecture.' + | 58 help='Translation target architecture.' + |
56 ' Default %(default)s.') | 59 ' Default %(default)s.') |
57 argparser.add_argument('-O', required=False, default='2', dest='optlevel', | 60 argparser.add_argument('-O', required=False, default='2', dest='optlevel', |
58 choices=['m1', '-1', '0', '1', '2'], | 61 choices=['m1', '-1', '0', '1', '2'], |
59 metavar='OPTLEVEL', | 62 metavar='OPTLEVEL', |
60 help='Optimization level for llc and Subzero ' + | 63 help='Optimization level for llc and Subzero ' + |
61 '(m1 and -1 are equivalent).' + | 64 '(m1 and -1 are equivalent).' + |
62 ' Default %(default)s.') | 65 ' Default %(default)s.') |
63 argparser.add_argument('--clang-opt', required=False, default=True, | 66 argparser.add_argument('--clang-opt', required=False, default=True, |
64 dest='clang_opt') | 67 dest='clang_opt') |
65 argparser.add_argument('--mattr', required=False, default='sse2', | 68 argparser.add_argument('--mattr', required=False, default='sse2', |
66 dest='attr', choices=['sse2', 'sse4.1', | 69 dest='attr', choices=['sse2', 'sse4.1', |
67 'neon', 'hwdiv-arm'], | 70 'neon', 'hwdiv-arm', |
| 71 'base'], |
68 metavar='ATTRIBUTE', | 72 metavar='ATTRIBUTE', |
69 help='Target attribute. Default %(default)s.') | 73 help='Target attribute. Default %(default)s.') |
70 argparser.add_argument('--sandbox', required=False, default=0, type=int, | 74 argparser.add_argument('--sandbox', required=False, default=0, type=int, |
71 dest='sandbox', | 75 dest='sandbox', |
72 help='Use sandboxing. Default "%(default)s".') | 76 help='Use sandboxing. Default "%(default)s".') |
73 argparser.add_argument('--nonsfi', required=False, default=0, type=int, | 77 argparser.add_argument('--nonsfi', required=False, default=0, type=int, |
74 dest='nonsfi', | 78 dest='nonsfi', |
75 help='Use Non-SFI mode. Default "%(default)s".') | 79 help='Use Non-SFI mode. Default "%(default)s".') |
76 argparser.add_argument('--prefix', required=True, | 80 argparser.add_argument('--prefix', required=True, |
77 metavar='SZ_PREFIX', | 81 metavar='SZ_PREFIX', |
(...skipping 82 matching lines...) Loading... |
160 | 164 |
161 # Each separately translated Subzero object file contains its own | 165 # Each separately translated Subzero object file contains its own |
162 # definition of the __Sz_block_profile_info profiling symbol. Avoid | 166 # definition of the __Sz_block_profile_info profiling symbol. Avoid |
163 # linker errors (multiply defined symbol) by making all copies weak. | 167 # linker errors (multiply defined symbol) by making all copies weak. |
164 # (This could also be done by Subzero if it supported weak symbol | 168 # (This could also be done by Subzero if it supported weak symbol |
165 # definitions.) This approach should be OK because cross tests are | 169 # definitions.) This approach should be OK because cross tests are |
166 # currently the only situation where multiple translated files are | 170 # currently the only situation where multiple translated files are |
167 # linked into the executable, but when PNaCl supports shared nexe | 171 # linked into the executable, but when PNaCl supports shared nexe |
168 # libraries, this would need to change. (Note: the same issue applies | 172 # libraries, this would need to change. (Note: the same issue applies |
169 # to the __Sz_revision symbol.) | 173 # to the __Sz_revision symbol.) |
170 shellcmd(['{bin}/{objcopy}'.format(bin=bindir, objcopy=GetObjcopyCmd()), | 174 shellcmd(['{bin}/{objcopy}'.format(bin=bindir, |
| 175 objcopy=GetObjcopyCmd(args.target)), |
171 '--weaken-symbol=__Sz_block_profile_info', | 176 '--weaken-symbol=__Sz_block_profile_info', |
172 '--weaken-symbol=__Sz_revision', | 177 '--weaken-symbol=__Sz_revision', |
173 '--strip-symbol=nacl_tp_tdb_offset', | 178 '--strip-symbol=nacl_tp_tdb_offset', |
174 '--strip-symbol=nacl_tp_tls_offset', | 179 '--strip-symbol=nacl_tp_tls_offset', |
175 obj_sz]) | 180 obj_sz]) |
176 objs.append(obj_sz) | 181 objs.append(obj_sz) |
177 shellcmd(['{bin}/pnacl-llc'.format(bin=bindir), | 182 shellcmd(['{bin}/pnacl-llc'.format(bin=bindir), |
178 '-arm-enable-dwarf-eh=1', | |
179 '-mtriple=' + triple, | 183 '-mtriple=' + triple, |
180 '-externalize', | 184 '-externalize', |
181 '-filetype=obj', | 185 '-filetype=obj', |
182 '-bitcode-format=llvm', | 186 '-bitcode-format=llvm', |
183 '-o=' + obj_llc, | 187 '-o=' + obj_llc, |
184 bitcode] + llc_flags) | 188 bitcode] + llc_flags) |
185 shellcmd(['{bin}/{objcopy}'.format(bin=bindir, objcopy=GetObjcopyCmd()), | 189 strip_syms = [] if args.target == 'mips32' else ['nacl_tp_tdb_offset', |
186 '--strip-symbol=nacl_tp_tdb_offset', | 190 'nacl_tp_tls_offset'] |
187 '--strip-symbol=nacl_tp_tls_offset', | 191 shellcmd(['{bin}/{objcopy}'.format(bin=bindir, |
188 obj_llc]) | 192 objcopy=GetObjcopyCmd(args.target)), |
| 193 obj_llc] + |
| 194 [('--strip-symbol=' + sym) for sym in strip_syms]) |
189 objs.append(obj_llc) | 195 objs.append(obj_llc) |
190 | 196 |
191 # Add szrt_sb_${target}.o or szrt_native_${target}.o. | 197 # Add szrt_sb_${target}.o or szrt_native_${target}.o. |
192 if not args.nonsfi: | 198 if not args.nonsfi: |
193 objs.append(( | 199 objs.append(( |
194 '{root}/toolchain_build/src/subzero/build/runtime/' + | 200 '{root}/toolchain_build/src/subzero/build/runtime/' + |
195 'szrt_{sb}_' + args.target + '.o' | 201 'szrt_{sb}_' + args.target + '.o' |
196 ).format(root=nacl_root, | 202 ).format(root=nacl_root, |
197 sb=get_sfi_string(args, 'sb', 'nonsfi', 'native'))) | 203 sb=get_sfi_string(args, 'sb', 'nonsfi', 'native'))) |
198 | 204 |
(...skipping 38 matching lines...) Loading... |
237 shellcmd(['{bin}/pnacl-opt'.format(bin=bindir), | 243 shellcmd(['{bin}/pnacl-opt'.format(bin=bindir), |
238 '-pnacl-abi-simplify-preopt', | 244 '-pnacl-abi-simplify-preopt', |
239 '-pnacl-abi-simplify-postopt', | 245 '-pnacl-abi-simplify-postopt', |
240 '-pnaclabi-allow-debug-metadata', | 246 '-pnaclabi-allow-debug-metadata', |
241 '-strip-metadata', | 247 '-strip-metadata', |
242 '-strip-module-flags', | 248 '-strip-module-flags', |
243 '-strip-debug', | 249 '-strip-debug', |
244 '-disable-opt', | 250 '-disable-opt', |
245 bitcode_nonfinal, '-S', '-o', bitcode]) | 251 bitcode_nonfinal, '-S', '-o', bitcode]) |
246 shellcmd(['{bin}/pnacl-llc'.format(bin=bindir), | 252 shellcmd(['{bin}/pnacl-llc'.format(bin=bindir), |
247 '-arm-enable-dwarf-eh=1', | |
248 '-mtriple=' + triple, | 253 '-mtriple=' + triple, |
249 '-externalize', | 254 '-externalize', |
250 '-filetype=obj', | 255 '-filetype=obj', |
251 '-O2', | 256 '-O2', |
252 '-bitcode-format=llvm', | 257 '-bitcode-format=llvm', |
253 '-o', obj_llc, | 258 '-o', obj_llc, |
254 bitcode] + llc_flags) | 259 bitcode] + llc_flags) |
255 if not args.sandbox and not args.nonsfi: | 260 if not args.sandbox and not args.nonsfi: |
256 shellcmd(['{bin}/{objcopy}'.format(bin=bindir, objcopy=GetObjcopyCmd()), | 261 shellcmd(['{bin}/{objcopy}'.format(bin=bindir, |
| 262 objcopy=GetObjcopyCmd(args.target)), |
257 '--redefine-sym', '_start=_user_start', | 263 '--redefine-sym', '_start=_user_start', |
258 obj_llc | 264 obj_llc |
259 ]) | 265 ]) |
260 objs.append(obj_llc) | 266 objs.append(obj_llc) |
261 if args.nonsfi: | 267 if args.nonsfi: |
262 LinkNonsfi(objs, os.path.join(args.dir, args.output), args.target) | 268 LinkNonsfi(objs, os.path.join(args.dir, args.output), args.target) |
263 elif args.sandbox: | 269 elif args.sandbox: |
264 LinkSandbox(objs, os.path.join(args.dir, args.output), args.target) | 270 LinkSandbox(objs, os.path.join(args.dir, args.output), args.target) |
265 else: | 271 else: |
266 LinkNative(objs, os.path.join(args.dir, args.output), args.target) | 272 LinkNative(objs, os.path.join(args.dir, args.output), args.target) |
267 | 273 |
268 if __name__ == '__main__': | 274 if __name__ == '__main__': |
269 main() | 275 main() |
OLD | NEW |