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


pinocchio
Author(s):
autogenerated on Wed Apr 16 2025 02:41:45