Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nm output parsing robust against symbols containing : #18152

Merged
merged 1 commit into from Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -407,6 +407,7 @@ jobs:
asan.test_async_hello
asan.test_dlfcn_basic
asan.test_async_hello_stack_switching
asan.test_cubescript
lsan.test_stdio_locking
lsan.test_dlfcn_basic
lsan.test_pthread_create"
Expand Down
13 changes: 7 additions & 6 deletions tools/building.py
Expand Up @@ -300,24 +300,25 @@ def parse_llvm_nm_symbols(output):

for line in output.split('\n'):
# Line format: "[archive filename:]object filename: address status name"
entry_pos = line.rfind(':')
entry_pos = line.rfind(': ')
if entry_pos < 0:
continue

filename_pos = line.rfind(':', 0, entry_pos)
filename_end = line.rfind(':', 0, entry_pos)
# Disambiguate between
# C:\bar.o: T main
# and
# /foo.a:bar.o: T main
# (both of these have same number of ':'s, but in the first, the file name on disk is "C:\bar.o", in second, it is "/foo.a")
if filename_pos < 0 or line[filename_pos + 1] in '/\\':
filename_pos = entry_pos
if filename_end < 0 or line[filename_end + 1] in '/\\':
filename_end = entry_pos

filename = line[:filename_pos]
filename = line[:filename_end]
if entry_pos + 13 >= len(line):
exit_with_error('error parsing output of llvm-nm: `%s`\nIf the symbol name here contains a colon, and starts with __invoke_, then the object file was likely built with an old version of llvm (please rebuild it).' % line)

status = line[entry_pos + 11] # Skip address, which is always fixed-length 8 chars.
# Skip address, which is always fixed-length 8 chars (plus 2 leading chars `: ` and one trailing space)
status = line[entry_pos + 11]
symbol = line[entry_pos + 13:]

if filename not in symbols:
Expand Down