| OLD | NEW |
| 1 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 1 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # A simple program to run objdump on a file and assert that the ABI TLS | 5 # A simple program to run objdump on a file and assert that the ABI TLS |
| 6 # register appears nowhere in it. This ensures that the direct register access | 6 # register appears nowhere in it. This ensures that the direct register access |
| 7 # style of TLS is not being used in the IRT blob. | 7 # style of TLS is not being used in the IRT blob. |
| 8 | 8 |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| 11 import re | 11 import re |
| 12 | 12 |
| 13 def Main(args): | 13 def Main(args): |
| 14 nargs = len(args) | 14 nargs = len(args) |
| 15 outfile = None | 15 outfile = None |
| 16 if nargs == 4: | 16 if nargs == 4: |
| 17 outfile = args[3] | 17 outfile = args[3] |
| 18 else: | 18 else: |
| 19 assert(nargs == 3) | 19 assert(nargs == 3) |
| 20 arch = args[0] | 20 arch = args[0] |
| 21 objdump = args[1] | 21 objdump = args[1] |
| 22 obj_file = args[2] | 22 obj_file = args[2] |
| 23 | 23 |
| 24 whitelist_regex = None | 24 whitelist_regex = None |
| 25 objdump_args = [objdump, '-d', obj_file] |
| 25 if arch == 'x86-32': | 26 if arch == 'x86-32': |
| 26 objdump_args = [objdump, '-d', obj_file] | |
| 27 # "%gs:4" is allowed but all other uses of %gs are suspect. | 27 # "%gs:4" is allowed but all other uses of %gs are suspect. |
| 28 register = '%gs' | 28 register = '%gs' |
| 29 regex = re.compile(register + r'(?!:0x4\b)') | 29 regex = re.compile(register + r'(?!:0x4\b)') |
| 30 elif arch == 'x86-64': | 30 elif arch == 'x86-64': |
| 31 # Nothing to check. | 31 # Nothing to check. |
| 32 regex = None | 32 regex = None |
| 33 elif arch.startswith('arm'): | 33 elif arch.startswith('arm'): |
| 34 if arch == 'arm-gcc': | |
| 35 objdump_flags = ['-d'] | |
| 36 elif arch == 'arm-pnacl': | |
| 37 # TODO(mcgrathr): Just use -d when PNaCl compiler is fixed so it works. | |
| 38 # See http://code.google.com/p/nativeclient/issues/detail?id=2818 | |
| 39 objdump_flags = ['-D', '--section=.text'] | |
| 40 objdump_args = [objdump] + objdump_flags + [obj_file] | |
| 41 # A real reference to r9 should probably be preceded by some character | 34 # A real reference to r9 should probably be preceded by some character |
| 42 # that is not legal for an identifier (e.g., spaces, commas, brackets). | 35 # that is not legal for an identifier (e.g., spaces, commas, brackets). |
| 43 register = 'r9' | 36 register = 'r9' |
| 44 regex = re.compile('[^_\w]' + register) | 37 regex = re.compile('[^_\w]' + register) |
| 45 whitelist_regex = re.compile(r'ldr\s+r0,\s*\[r9,\s*#4\]\s*$') | 38 whitelist_regex = re.compile(r'ldr\s+r0,\s*\[r9,\s*#4\]\s*$') |
| 46 else: | 39 else: |
| 47 print 'Unknown architecture: %s' % arch | 40 print 'Unknown architecture: %s' % arch |
| 48 sys.exit(1) | 41 sys.exit(1) |
| 49 | 42 |
| 50 if regex is not None: | 43 if regex is not None: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 65 sys.exit(1) | 58 sys.exit(1) |
| 66 | 59 |
| 67 if outfile is not None: | 60 if outfile is not None: |
| 68 outf = open(outfile, 'w') | 61 outf = open(outfile, 'w') |
| 69 outf.write('TLS in %s OK\n' % obj_file) | 62 outf.write('TLS in %s OK\n' % obj_file) |
| 70 outf.close() | 63 outf.close() |
| 71 | 64 |
| 72 | 65 |
| 73 if __name__ == '__main__': | 66 if __name__ == '__main__': |
| 74 Main(sys.argv[1:]) | 67 Main(sys.argv[1:]) |
| OLD | NEW |