Skip to content

Commit

Permalink
tests: handle uncommon architecture format for nm
Browse files Browse the repository at this point in the history
The zlib symbols may not be of type 'T' but rather e.g. 'D' -- instead,
tell nm to emit the POSIX format and also to only emit defined symbols,
not undefined ones. Then we just check if the symbol is listed at all,
regardless of type.

We already depend on -U elsewhere (e.g symbolextractor). There's no real
replacement for it, sadly. It's also buggy in some versions of nm, so we
check both its long and short options.

Bug: https://bugs.gentoo.org/938259
  • Loading branch information
eli-schwartz committed Sep 6, 2024
1 parent 6d92547 commit 83f8de5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test cases/linuxlike/14 static dynamic linkage/verify_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@

def handle_common(path):
"""Handle the common case."""
output = subprocess.check_output(['nm', path]).decode('utf-8')
if 'T zlibVersion' in output:
try:
output = subprocess.check_output(['nm', '--defined-only', '-P', '-A', path]).decode('utf-8')
except subprocess.CalledProcessError:
# some NMs only support -U. Older binutils only supports --defined-only.
output = subprocess.check_output(['nm', '-UPA', path]).decode('utf-8')
# POSIX format. Prints all *defined* symbols, looks like this:
# builddir/main_static: zlibVersion T 1190 39
# or
# builddir/main_static: zlibVersion D 1fde0 30
if ': zlibVersion ' in output:
return 0
return 1

Expand Down

0 comments on commit 83f8de5

Please sign in to comment.