common_symbols.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 # Find common dynamics public symbols between shared libraries.
3 
4 import argparse
5 import itertools
6 import pathlib
7 import subprocess
8 import typing
9 
10 
11 def generate_symbols(shared_library: pathlib.Path) -> typing.Set[str]:
12  # Show symbol
13  # -D: Dynamic
14  # -C: Demangled
15  # -U: Defined
16  # -W: Non weak
17  result = subprocess.run(
18  ["nm", "-DCUW", "--format=sysv", str(shared_library)],
19  capture_output=True,
20  text=True,
21  )
22  output = result.stdout
23  lines_split = (line.split("|") for line in output.splitlines() if "|" in line)
24  # Only keep lines with exported (upper case) symbols.
25  # `u` is also a global symbol, but if we always build with compatible libraries,
26  # there is no issue to find it in many places.
27  return set([line[0].strip() for line in lines_split if line[2].strip().isupper()])
28 
29 
30 if __name__ == "__main__":
31  parser = argparse.ArgumentParser(
32  prog="common_symbol",
33  description="Find common dynamics public symbols between shared libraries.",
34  )
35  parser.add_argument("shared_libraries", nargs="+", type=pathlib.Path)
36 
37  args = parser.parse_args()
38  symbols = [
39  (shared_library, generate_symbols(shared_library))
40  for shared_library in args.shared_libraries
41  ]
42 
43  for lib1, lib2 in itertools.combinations(symbols, 2):
44  print(f"Common symbols between {lib1[0]} and {lib2[0]}")
45  common_symbols = lib1[1].intersection(lib2[1])
46  for common in common_symbols:
47  print(f"\t{common}")
48  print()
common_symbols.generate_symbols
typing.Set[str] generate_symbols(pathlib.Path shared_library)
Definition: common_symbols.py:11
set
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:08