qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/1] plugins: Move the windows linking function to qemu


From: Paolo Bonzini
Subject: Re: [PATCH v2 1/1] plugins: Move the windows linking function to qemu
Date: Fri, 10 Nov 2023 22:47:26 +0100

On Fri, Nov 10, 2023 at 6:36 PM Greg Manning <gmanning@rapitasystems.com> wrote:
> Then hopefully when a plugin links to this, it gets the __pfnDliFailureHook2
> symbol defined and set up and everything would work. Except gcc strips
> out any unreferenced symbols from static libs when linking. So the plugin
> would have to be linked thusly:
>
> gcc -shared -o my_plugin.dll -Wl,-u,__pfnDliFailureHook2 my_plugin.o 
> qemu_plugin_api.lib
>
> But no other qemu-fiddling-with-things or extra code in plugins required.
>
> Hmm. Feels like half a solution. I wonder if there's a way to mark symbols as
> "always required despite what dead code analysis says".

To be clear, I don't dislike at all the simpler solution where you
just add a macro like this:

#ifdef _WIN32
#define QEMU_PLUGIN_HOOK \
   /* contents of win32_linker.c */
#else
#define QEMU_PLUGIN_HOOK
#endif

and add QEMU_PLUGIN_HOOK to a source file of every plugin. But if you
would like to use a library, you can pass a linker script on the
command line as if it was a library, and the paths within the linker
script are resolved relative to the linker script itself. So you can
place in tests/plugins/meson.build something like:

# uses dlltool like it does now... can also use custom_target
delaylib = configure_file(output: 'qemu_plugin_api.lib',
   ...)
delayhook = static_library('qemu_delay_hook', sources: 'qemu_delay_hook.c')
plugin_api = configure_file(output : 'libqemu_plugin_api.a', input:
'libqemu_plugin_api.ld', copy: true, install_dir:
get_option('libdir'))

where the last configure_file creates a file with contents such as

INPUT(qemu_plugin_api.lib) # from dlltool
INPUT(libqemu_delay_hook.a) # compiled from qemu_delay_hook.c
EXTERN(__pfnDliNotifyHook2)  # equivalent to -Wl,-u

And then it should work to add link_depends: [delayhook, delaylib,
plugin_api], link_args: plugin_api as in your previous version.

Finally, since the hook will be built by ninja, you also need

diff --git a/Makefile b/Makefile
index 676a4a54f48..7b42d85f1dc 100644
--- a/Makefile
+++ b/Makefile
@@ -184,6 +184,7 @@ $(SUBDIR_RULES):
 ifneq ($(filter contrib/plugins, $(SUBDIRS)),)
 .PHONY: plugins
 plugins: contrib/plugins/all
+contrib/plugins/all: | run-ninja
 endif

 .PHONY: recurse-all recurse-clean

to ensure that the plugins are built after libqemu_delay_hook.a (of
course feel free to change the file names!).

The main disadvantage is that the Microsoft linker does not know
linker scripts, so that's a point in favor of the macro solution.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]