Skip to content

Commit 4ecd40f

Browse files
committed
tools: pass explicit section list to objdump
Objdump in recent versions of GNU binutils ignores bss sections unless they are specifically selected with the '-j' option. Symbols from these sections are needed for dtrace support. To fix this while retaining compatibility with previous versions of binutils, change to a two pass approach. The first pass extracts the list of unique sections, and the second pass invokes objdump with '-j' options for each of them. Fixes: nodejs#49991
1 parent aadfea4 commit 4ecd40f

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

tools/genv8constants.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,46 @@
1818
sys.exit(2)
1919

2020
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)
3561

3662
pattern = re.compile('([0-9a-fA-F]{8}|[0-9a-fA-F]{16}) <(.*)>:')
3763
v8dbg = re.compile('^v8dbg.*$')

0 commit comments

Comments
 (0)