Bug 1634204 - Allow newer versions of symbols if they are weakly linked. r=froydnj

We currently check that the binaries we ship are not using symbol
versions of system libraries that would not be available on some older
systems. In some cases, however, we may get dependencies on newer symbol
versions in the form of weak symbols, that are checked for at runtime.
This happens with __cxa_thread_atexit_impl when building against a glibc
newer than 2.18, and the supporting code in Rust libstd actually checks
at runtime whether the weak symbol is resolved before using it.

Differential Revision: https://phabricator.services.mozilla.com/D73782
This commit is contained in:
Mike Hommey 2020-05-06 02:00:13 +00:00
Родитель 3d64f74464
Коммит 5cef88b2f1
1 изменённых файлов: 21 добавлений и 4 удалений

Просмотреть файл

@ -96,8 +96,11 @@ def iter_symbols(binary):
continue
addr = int(m.group(0), 16)
# The second "column" is 7 one-character items that can be
# whitespaces. We don't have use for their value, so just skip
# those.
# whitespaces.
flags = line[m.end():][:7]
# We're only interested whether the symbol might be weak.
weak = 'w' in flags
rest = line[m.end() + 9:].split()
# The number of remaining colums will vary between ELF and MACHO.
# On ELF, we have:
@ -116,6 +119,7 @@ def iter_symbols(binary):
'size': int(rest[1], 16) if ty == ELF else 0,
'name': name,
'version': ver or None,
'weak': weak,
}
else:
export_table = False
@ -143,6 +147,7 @@ def iter_symbols(binary):
'size': 0,
'name': name,
'version': None,
'weak': None,
}
@ -160,8 +165,20 @@ def check_dep_versions(target, binary, lib, prefix, max_version):
prefix = prefix + '_'
try:
for sym in at_least_one(iter_symbols(binary)):
if sym['addr'] == 0 and sym['version'] and \
sym['version'].startswith(prefix):
# Only check versions on undefined symbols
if sym['addr'] != 0:
continue
# Versions for weak symbols don't matter, since the code must
# handle the case where they're not defined.
if sym['weak']:
continue
# No version to check
if not sym['version']:
continue
if sym['version'].startswith(prefix):
version = Version(sym['version'][len(prefix):])
if version > max_version:
unwanted.append(sym)