2016-07-05 20:43:38 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Check if all given binaries work with the given glibc version.
|
|
|
|
|
2016-07-31 12:20:06 +00:00
|
|
|
glibc_check.py 2.11 bin [bin ...]
|
|
|
|
|
|
|
|
rc = 0 means "yes", rc = 1 means "no".
|
2016-07-05 20:43:38 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
verbose = True
|
2022-07-06 13:37:27 +00:00
|
|
|
glibc_re = re.compile(r"GLIBC_([0-9]\.[0-9]+)")
|
2016-07-05 20:43:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def parse_version(v):
|
2022-07-06 13:37:27 +00:00
|
|
|
major, minor = v.split(".")
|
2016-07-05 20:43:38 +00:00
|
|
|
return int(major), int(minor)
|
|
|
|
|
|
|
|
|
|
|
|
def format_version(version):
|
|
|
|
return "%d.%d" % version
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
given = parse_version(sys.argv[1])
|
|
|
|
filenames = sys.argv[2:]
|
|
|
|
|
|
|
|
overall_versions = set()
|
|
|
|
for filename in filenames:
|
|
|
|
try:
|
2023-10-06 12:47:20 +00:00
|
|
|
output = subprocess.check_output(["objdump", "-T", filename], stderr=subprocess.STDOUT)
|
2019-02-22 16:05:57 +00:00
|
|
|
output = output.decode()
|
2022-07-06 13:37:27 +00:00
|
|
|
versions = {parse_version(match.group(1)) for match in glibc_re.finditer(output)}
|
2016-07-05 20:43:38 +00:00
|
|
|
requires_glibc = max(versions)
|
|
|
|
overall_versions.add(requires_glibc)
|
|
|
|
if verbose:
|
2022-02-27 18:31:33 +00:00
|
|
|
print(f"{filename} {format_version(requires_glibc)}")
|
2018-10-29 10:54:24 +00:00
|
|
|
except subprocess.CalledProcessError:
|
2016-07-05 20:43:38 +00:00
|
|
|
if verbose:
|
|
|
|
print("%s errored." % filename)
|
|
|
|
|
|
|
|
wanted = max(overall_versions)
|
|
|
|
ok = given >= wanted
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
if ok:
|
2022-07-06 13:37:27 +00:00
|
|
|
print("The binaries work with the given glibc %s." % format_version(given))
|
2016-07-05 20:43:38 +00:00
|
|
|
else:
|
2022-07-06 13:37:27 +00:00
|
|
|
print(
|
|
|
|
"The binaries do not work with the given glibc %s. "
|
|
|
|
"Minimum is: %s" % (format_version(given), format_version(wanted))
|
|
|
|
)
|
2016-07-05 20:43:38 +00:00
|
|
|
return ok
|
|
|
|
|
|
|
|
|
2022-07-06 13:37:27 +00:00
|
|
|
if __name__ == "__main__":
|
2016-07-05 20:43:38 +00:00
|
|
|
ok = main()
|
|
|
|
sys.exit(0 if ok else 1)
|