glibc_check.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. """
  3. Check if all given binaries work with the given glibc version.
  4. glibc_check.py 2.11 bin [bin ...]
  5. rc = 0 means "yes", rc = 1 means "no".
  6. """
  7. import re
  8. import subprocess
  9. import sys
  10. verbose = True
  11. objdump = "objdump -T %s"
  12. glibc_re = re.compile(r'GLIBC_([0-9]\.[0-9]+)')
  13. def parse_version(v):
  14. major, minor = v.split('.')
  15. return int(major), int(minor)
  16. def format_version(version):
  17. return "%d.%d" % version
  18. def main():
  19. given = parse_version(sys.argv[1])
  20. filenames = sys.argv[2:]
  21. overall_versions = set()
  22. for filename in filenames:
  23. try:
  24. output = subprocess.check_output(objdump % filename, shell=True,
  25. stderr=subprocess.STDOUT)
  26. output = output.decode('utf-8')
  27. versions = set(parse_version(match.group(1))
  28. for match in glibc_re.finditer(output))
  29. requires_glibc = max(versions)
  30. overall_versions.add(requires_glibc)
  31. if verbose:
  32. print("%s %s" % (filename, format_version(requires_glibc)))
  33. except subprocess.CalledProcessError as e:
  34. if verbose:
  35. print("%s errored." % filename)
  36. wanted = max(overall_versions)
  37. ok = given >= wanted
  38. if verbose:
  39. if ok:
  40. print("The binaries work with the given glibc %s." %
  41. format_version(given))
  42. else:
  43. print("The binaries do not work with the given glibc %s. "
  44. "Minimum is: %s" % (format_version(given), format_version(wanted)))
  45. return ok
  46. if __name__ == '__main__':
  47. ok = main()
  48. sys.exit(0 if ok else 1)