|
18 | 18 | sys.exit(2)
|
19 | 19 |
|
20 | 20 | outfile = open(sys.argv[1], 'w')
|
21 |
| -try: |
22 |
| - pipe = subprocess.Popen([ 'objdump', '-z', '-D', sys.argv[2] ], |
23 |
| - bufsize=-1, stdout=subprocess.PIPE).stdout |
24 |
| -except OSError as e: |
25 |
| - if e.errno == errno.ENOENT: |
26 |
| - print(''' |
27 |
| - Node.js compile error: could not find objdump |
28 |
| -
|
29 |
| - Check that GNU binutils are installed and included in PATH |
30 |
| - ''') |
31 |
| - else: |
32 |
| - print('problem running objdump: ', e.strerror) |
33 |
| - |
34 |
| - sys.exit() |
| 21 | + |
| 22 | +def objdump(filename, opts): |
| 23 | + try: |
| 24 | + pipe = subprocess.Popen([ 'objdump' ] + opts + [ filename ], |
| 25 | + bufsize=-1, stdout=subprocess.PIPE).stdout |
| 26 | + except OSError as e: |
| 27 | + if e.errno == errno.ENOENT: |
| 28 | + print(''' |
| 29 | + Node.js compile error: could not find objdump |
| 30 | +
|
| 31 | + Check that GNU binutils are installed and included in PATH |
| 32 | + ''') |
| 33 | + else: |
| 34 | + print('problem running objdump: ', e.strerror) |
| 35 | + |
| 36 | + sys.exit() |
| 37 | + |
| 38 | + return pipe |
| 39 | + |
| 40 | +# Since GNU binutils 2.41, gobjdump does not include .bss sections in |
| 41 | +# disassembly output, even with -z. |
| 42 | +# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=0a3137ce4c4b38ee8 |
| 43 | +# To work around this while still supporting older versions of binutils, we |
| 44 | +# need to extract a list of sections and pass them all to objdump via -j. |
| 45 | + |
| 46 | +sections = set() |
| 47 | +pattern = re.compile(r'^\s+\d+\s+(\.\S+)') |
| 48 | +pipe = objdump(sys.argv[2], [ '-h' ]) |
| 49 | +for line in pipe: |
| 50 | + line = line.decode('utf-8') |
| 51 | + match = pattern.match(line) |
| 52 | + if match is None: |
| 53 | + continue |
| 54 | + sections.add(str(match.group(1))) |
| 55 | + |
| 56 | +opts = [ '-z', '-D' ] |
| 57 | +for section in sections: |
| 58 | + opts.extend([ '-j', section ]) |
| 59 | + |
| 60 | +pipe = objdump(sys.argv[2], opts) |
35 | 61 |
|
36 | 62 | pattern = re.compile('([0-9a-fA-F]{8}|[0-9a-fA-F]{16}) <(.*)>:')
|
37 | 63 | v8dbg = re.compile('^v8dbg.*$')
|
|
0 commit comments