Bug 1854308 - Handle old llvm-readelf output for --dyn-syms properly. r=firefox-build-system-reviewers,andi

While we're here, adjust the error messages, because we're not using
llvm-objdump anymore.

Differential Revision: https://phabricator.services.mozilla.com/D188794
This commit is contained in:
Mike Hommey 2023-09-21 20:51:35 +00:00
parent 194571f479
commit 163fd5a55a

View File

@ -65,11 +65,19 @@ def iter_elf_symbols(binary, all=False):
if ty == UNKNOWN and open(binary, "rb").read(8) == b"!<arch>\n":
ty = ELF
assert ty == ELF
def looks_like_readelf_data(data):
return len(data) >= 8 and data[0].endswith(":") and data[0][:-1].isdigit()
for line in get_output(
READELF, "--wide", "--syms" if all else "--dyn-syms", binary
):
data = line.split()
if not (len(data) >= 8 and data[0].endswith(":") and data[0][:-1].isdigit()):
if not looks_like_readelf_data(data):
# Older versions of llvm-readelf would use .hash for --dyn-syms,
# which would add an extra column at the beginning.
data = data[1:]
if not looks_like_readelf_data(data):
continue
n, addr, size, type, bind, vis, index, name = data[:8]
@ -123,7 +131,7 @@ def check_binary_compat(binary):
if version > max_version:
unwanted.setdefault(prefix, []).append(sym)
except Empty:
raise RuntimeError("Could not parse llvm-objdump output?")
raise RuntimeError("Could not parse readelf output?")
if unwanted:
error = []
for lib, prefix, _ in checks:
@ -240,7 +248,7 @@ def check_networking(binary):
if sym["addr"] == 0 and sym["name"] in networking_functions:
bad_occurences_names.add(sym["name"])
except Empty:
raise RuntimeError("Could not parse llvm-objdump output?")
raise RuntimeError("Could not parse readelf output?")
basename = os.path.basename(binary)
if bad_occurences_names: