There has been a bit of discussion regarding the possibility to move SPICE code to a module in order to reduce the attack surface and memory usage when SPICE is not used.
This WIP series proposes one way to do it that is relatively cheap in terms of code changes, relative to other ideas I tested, and seems to be working on simple test cases, unlike a couple of more "sophisiticated" ideas I tried where I ran into rather nasty SPICE initialization order issues. Furthermore, the approach presented here requires relatively few code changes in order to apply to other components as well. It relies on a couple of macros added to the module.h file, MODIFACE and MODIMPLE. MODIFACE declare the interface for a module function. A module function is transformed into a pointer when you build with modules, and that pointer is used instead of the original function. MODIMPL implements a MODIFACE, and patches the pointer at load time to call the function in the shared library. Thanks to some suggestions from Gerd, I also moved QXL to a module, although at the moment it does not load correctly. There are a few known hacks in the present state, including: - Adding various non-UI files into spice-app.so, which required a couple of ../pwd/foo.o references in the makefile. Not very nice, but I did not want to spend too much time fixing the makefiles. - qmp_query_spice had to be dealt with "manually" because its interface is generated. With these changes, the following shared libraries are no longer needed in the main binary: libspice-server.so.1 => /lib64/libspice-server.so.1 (HEX) libopus.so.0 => /lib64/libopus.so.0 (HEX) liblz4.so.1 => /lib64/liblz4.so.1 (HEX) libgstapp-1.0.so.0 => /lib64/libgstapp-1.0.so.0 (HEX) libgstvideo-1.0.so.0 => /lib64/libgstvideo-1.0.so.0 (HEX) libgstbase-1.0.so.0 => /lib64/libgstbase-1.0.so.0 (HEX) libgstreamer-1.0.so.0 => /lib64/libgstreamer-1.0.so.0 (HEX) libssl.so.1.1 => /lib64/libssl.so.1.1 (HEX) liborc-0.4.so.0 => /lib64/liborc-0.4.so.0 (HEX) I will keep pushing updates on branch "modular-spice" on https://github.com/c3d/qemu.git Christophe de Dinechin (10): modules: Provide macros making it easier to identify module exports minikconf: Pass variables for modules spice: Make spice a module configuration spice: Move all the spice-related code in spice-app.so build: Avoid build failure when building drivers as modules trivial: Remove extra trailing whitespace qxl - FIXME: Build as module build: Add SPICE_CFLAGS and SPICE_LIBS to relevant files spice: Put spice functions in a separate load module REMOVE: Instrumentation to show the module functions being replaced Makefile | 1 + Makefile.objs | 2 ++ Makefile.target | 7 +++++++ audio/Makefile.objs | 2 +- chardev/Makefile.objs | 2 +- configure | 6 +++--- hw/Makefile.objs | 1 + hw/display/Makefile.objs | 4 +++- hw/display/qxl.c | 2 +- hw/i386/Makefile.objs | 1 + include/qemu/module.h | 28 ++++++++++++++++++++++++++++ include/ui/qemu-spice.h | 24 +++++++++++++++--------- monitor/Makefile.objs | 3 +++ monitor/hmp-cmds.c | 6 ++++++ scripts/minikconf.py | 4 ++-- softmmu/Makefile.objs | 2 +- softmmu/vl.c | 1 + stubs/Makefile.objs | 2 +- ui/Makefile.objs | 12 ++++++------ ui/spice-core.c | 31 +++++++++++++++++++++---------- ui/spice-display.c | 2 +- util/module.c | 13 +++++++++++-- 22 files changed, 117 insertions(+), 39 deletions(-) -- 2.26.2