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
' ')
20 if from_staticlib
and tokens
[1] == b
'U':
22 if not from_staticlib
and tokens
[1] != b
'U':
24 new_line
= b
'-Wl,-u,' + tokens
[0]
25 if not new_line
in linesSet
:
26 linesSet
.add(new_line
)
35 pc
= subprocess
.run([nm
, "-P", "-g", staticlib
], stdout
=subprocess
.PIPE
)
36 if pc
.returncode
!= 0:
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:
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__":