util/hexdump: introduce qemu_hexdump_line()
[qemu/ar7.git] / scripts / undefsym.py
blob69a895cd26c19d37dd58c3e4ac18a96069dc46d2
1 #!/usr/bin/env python3
3 # Before a shared module's DSO is produced, a static library is built for it
4 # and passed to this script. The script generates -Wl,-u options to force
5 # the inclusion of symbol from libqemuutil.a if the shared modules need them,
6 # This is necessary because the modules may use functions not needed by the
7 # executable itself, which would cause the function to not be linked in.
8 # Then the DSO loading would fail because of the missing symbol.
11 import sys
12 import subprocess
14 def filter_lines_set(stdout, from_staticlib):
15 linesSet = set()
16 for line in stdout.splitlines():
17 tokens = line.split(b' ')
18 if len(tokens) >= 1:
19 if len(tokens) > 1:
20 if from_staticlib and tokens[1] == b'U':
21 continue
22 if not from_staticlib and tokens[1] != b'U':
23 continue
24 new_line = b'-Wl,-u,' + tokens[0]
25 if not new_line in linesSet:
26 linesSet.add(new_line)
27 return linesSet
29 def main(args):
30 if len(args) <= 3:
31 sys.exit(0)
33 nm = args[1]
34 staticlib = args[2]
35 pc = subprocess.run([nm, "-P", "-g", staticlib], stdout=subprocess.PIPE)
36 if pc.returncode != 0:
37 sys.exit(1)
38 staticlib_syms = filter_lines_set(pc.stdout, True)
40 shared_modules = args[3:]
41 pc = subprocess.run([nm, "-P", "-g"] + shared_modules, stdout=subprocess.PIPE)
42 if pc.returncode != 0:
43 sys.exit(1)
44 modules_undef_syms = filter_lines_set(pc.stdout, False)
45 lines = sorted(staticlib_syms.intersection(modules_undef_syms))
46 sys.stdout.buffer.write(b'\n'.join(lines))
48 if __name__ == "__main__":
49 main(sys.argv)