qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] build-sys: do no support modules on Windows


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH] build-sys: do no support modules on Windows
Date: Thu, 18 Jul 2019 15:13:48 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2

On 18/07/19 14:49, Daniel P. Berrangé wrote:
> On Thu, Jul 18, 2019 at 04:04:13PM +0400, Marc-André Lureau wrote:
>> Our module system does not support Windows, because it relies on
>> resolving symbols from the main executable.
>>
>> If there is enough interest in supporting modules on Windows, we could
>> generate an import library for the executable and link with it:
>> https://stackoverflow.com/questions/15454968/dll-plugin-that-uses-functions-defined-in-the-main-executable
>>
>> However, there is a small chicken egg problem, since the executable
>> link and exports extra symbols needed by the library...
> 
> The "solution" to that would presumably be to put everything into a
> library, and the executable merely becomes trivial main() that calls
> a "runme" function in the library. It is kind of ugly though as we
> would need a separate library for each system emulator executable.
> 
> Just ignoring modules on Windows looks like the prudent solution.

See https://github.com/mesonbuild/meson/pull/3683#issuecomment-467815241

The trick is to build the modules in two phases, first as a static
library and then as a shared module (with Meson you'd use link_whole).
Then the list of symbols can be gleaned from the static libraries, but
the executable can still be linked before the shared module:

modules_objs = {}
modules_objs += { 'b': static_library('b.mo', 'src.c', pic: true) }
# ...

undef = []
undefdeps = []
foreach name, lib : modules_objs
    shared_module(name, link_whole: lib, link_with: e)
    undefdeps += [custom_target('undefsym', output: [name+'.undef'],
                            input: lib,
                            command: [files('undefsym.sh'),
                                      '@OUTPUT0@', '@INPUT@'])]
    undef += [ '@' + name + '.undef' ]
endforeach

libutil = static_library('util', 'util.c', pic: true)
e = executable('a', 'main.c', link_with: [libutil],
               link_args: undef, link_depends: undefdeps,
               implib: true)

This in fact is exactly what we're doing now, just with a .o file and
"ld -r" instead of a .a file that is wholly-linked into the shared module.

Paolo



reply via email to

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