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.
14 def filter_lines_set(stdout
, from_staticlib
):
16 for line
in stdout
.splitlines():
17 tokens
= line
.split(b
' ')
19 if from_staticlib
and tokens
[1] == b
'U':
21 if not from_staticlib
and tokens
[1] != b
'U':
23 new_line
= b
'-Wl,-u,' + tokens
[0]
24 if not new_line
in linesSet
:
25 linesSet
.add(new_line
)
34 pc
= subprocess
.run([nm
, "-P", "-g", staticlib
], stdout
=subprocess
.PIPE
)
35 if pc
.returncode
!= 0:
37 staticlib_syms
= filter_lines_set(pc
.stdout
, True)
39 shared_modules
= args
[3:]
40 pc
= subprocess
.run([nm
, "-P", "-g"] + shared_modules
, stdout
=subprocess
.PIPE
)
41 if pc
.returncode
!= 0:
43 modules_undef_syms
= filter_lines_set(pc
.stdout
, False)
44 lines
= sorted(staticlib_syms
.intersection(modules_undef_syms
))
45 sys
.stdout
.buffer.write(b
'\n'.join(lines
))
47 if __name__
== "__main__":