Skip to content

Commit 923710b

Browse files
pbo-linarostsquad
authored andcommitted
plugins: enable linking with clang/lld
Windows uses a special mechanism to enable plugins to work (DLL delay loading). Option for lld is different than ld. MSYS2 clang based environment use lld by default, so restricting to this config on Windows is safe, and will avoid false bug reports. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Pierrick Bouvier <[email protected]> Tested-by: Stefan Weil <[email protected]> Tested-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent ecbf356 commit 923710b

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

contrib/plugins/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if get_option('plugins')
1212
t += shared_module(i, files(i + '.c') + 'win32_linker.c',
1313
include_directories: '../../include/qemu',
1414
link_depends: [win32_qemu_plugin_api_lib],
15-
link_args: ['-Lplugins', '-lqemu_plugin_api'],
15+
link_args: win32_qemu_plugin_api_link_flags,
1616
dependencies: glib)
1717
else
1818
t += shared_module(i, files(i + '.c'),

meson.build

+5
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ elif host_os == 'sunos'
377377
qemu_common_flags += '-D__EXTENSIONS__'
378378
elif host_os == 'haiku'
379379
qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC']
380+
elif host_os == 'windows'
381+
# plugins use delaylib, and clang needs to be used with lld to make it work.
382+
if compiler.get_id() == 'clang' and compiler.get_linker_id() != 'ld.lld'
383+
error('On windows, you need to use lld with clang - use msys2 clang64/clangarm64 env')
384+
endif
380385
endif
381386

382387
# Choose instruction set (currently x86-only)

plugins/meson.build

+20-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ if not enable_modules
1717
capture: true,
1818
command: ['sed', '-ne', 's/^[[:space:]]*\\(qemu_.*\\);/_\\1/p', '@INPUT@'])
1919
emulator_link_args += ['-Wl,-exported_symbols_list,plugins/qemu-plugins-ld64.symbols']
20+
elif host_os == 'windows' and meson.get_compiler('c').get_id() == 'clang'
21+
# LLVM/lld does not support exporting specific symbols. However, it works
22+
# out of the box with dllexport/dllimport attribute we set in the code.
2023
else
2124
emulator_link_args += ['-Xlinker', '--dynamic-list=' + qemu_plugin_symbols.full_path()]
2225
endif
2326
endif
2427

2528
if host_os == 'windows'
26-
dlltool = find_program('dlltool', required: true)
27-
2829
# Generate a .lib file for plugins to link against.
2930
# First, create a .def file listing all the symbols a plugin should expect to have
3031
# available in qemu
@@ -33,12 +34,27 @@ if host_os == 'windows'
3334
output: 'qemu_plugin_api.def',
3435
capture: true,
3536
command: ['sed', '-e', '0,/^/s//EXPORTS/; s/[{};]//g', '@INPUT@'])
37+
3638
# then use dlltool to assemble a delaylib.
39+
# The delaylib will have an "imaginary" name (qemu.exe), that is used by the
40+
# linker file we add with plugins (win32_linker.c) to identify that we want
41+
# to find missing symbols in current program.
42+
win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
43+
if meson.get_compiler('c').get_id() == 'clang'
44+
# With LLVM/lld, delaylib is specified at link time (-delayload)
45+
dlltool = find_program('llvm-dlltool', required: true)
46+
dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
47+
win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
48+
else
49+
# With gcc/ld, delay lib is built with a specific delay parameter.
50+
dlltool = find_program('dlltool', required: true)
51+
dlltool_cmd = [dlltool, '--input-def', '@INPUT@',
52+
'--output-delaylib', '@OUTPUT@', '--dllname', 'qemu.exe']
53+
endif
3754
win32_qemu_plugin_api_lib = configure_file(
3855
input: win32_plugin_def,
3956
output: 'libqemu_plugin_api.a',
40-
command: [dlltool, '--input-def', '@INPUT@',
41-
'--output-delaylib', '@OUTPUT@', '--dllname', 'qemu.exe']
57+
command: dlltool_cmd
4258
)
4359
endif
4460
specific_ss.add(files(

tests/tcg/plugins/meson.build

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ if get_option('plugins')
55
t += shared_module(i, files(i + '.c') + '../../../contrib/plugins/win32_linker.c',
66
include_directories: '../../../include/qemu',
77
link_depends: [win32_qemu_plugin_api_lib],
8-
link_args: ['-Lplugins', '-lqemu_plugin_api'],
8+
link_args: win32_qemu_plugin_api_link_flags,
99
dependencies: glib)
10-
1110
else
1211
t += shared_module(i, files(i + '.c'),
1312
include_directories: '../../../include/qemu',

0 commit comments

Comments
 (0)