From: Pierrick Bouvier <[email protected]> QEMU stubs (from stubs folder) have a unique feature: they emulate weak symbols. Weak symbols are not supported on Windows with gcc. This is achieved by defining a static library, so the linker can pick a file only when one of its symbol is needed.
The problem is that common stubs are embedded in qemuutil, which is defined and created before any target code. Thus, to benefit from the same feature for target code, we need to create stub static libraries for each target architecture. To keep things simple, we declare one library per target base architecture. This implies that stubs are compiled only once, and we choose them to be system common files. This is not a big issue, since stubs definition have no specific behaviour, out of returning a default value, or stopping execution, which makes this safe to link them in user binaries also. Signed-off-by: Pierrick Bouvier <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> --- meson.build | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 987f33bacee..5fbdc75a0fc 100644 --- a/meson.build +++ b/meson.build @@ -3738,6 +3738,7 @@ target_user_arch = {} hw_common_arch = {} target_common_arch = {} target_common_system_arch = {} +target_stubs_arch = {} # NOTE: the trace/ subdirectory needs the qapi_trace_events variable # that is filled in by qapi/. @@ -4143,6 +4144,7 @@ common_all = static_library('common', # construct common libraries per base architecture target_common_arch_libs = {} target_common_system_arch_libs = {} +target_stubs_arch_libs = {} foreach target_base_arch, config_base_arch : config_base_arch_mak target_inc = [include_directories('target' / target_base_arch)] inc = [common_user_inc + target_inc] @@ -4202,6 +4204,15 @@ foreach target_base_arch, config_base_arch : config_base_arch_mak dependencies: src.all_dependencies() + common_deps + system_deps) target_common_system_arch_libs += {target_base_arch: lib} endif + + if target_base_arch in target_stubs_arch + src = target_stubs_arch[target_base_arch] + lib = static_library('stubs_' + target_base_arch, + sources: src.all_sources() + genh, + include_directories: inc, + c_args: target_system_c_args) + target_stubs_arch_libs += {target_base_arch: lib} + endif endforeach if have_rust @@ -4363,6 +4374,11 @@ foreach target : target_dirs objects += lib.extract_objects(src.sources()) arch_deps += src.dependencies() endif + lib_target_stubs = [] + if target_base_arch in target_stubs_arch_libs + lib_target_stubs = [target_stubs_arch_libs[target_base_arch]] + endif + target_stubs = declare_dependency(link_with: lib_target_stubs) target_specific = specific_ss.apply(config_target, strict: false) arch_srcs += target_specific.sources() @@ -4408,14 +4424,14 @@ foreach target : target_dirs 'name': 'qemu-system-' + target_name, 'win_subsystem': 'console', 'sources': [main_rs, files('system/main.c')], - 'dependencies': [sdl] + 'dependencies': [sdl, target_stubs], }] if host_os == 'windows' and (sdl.found() or gtk.found()) execs += [{ 'name': 'qemu-system-' + target_name + 'w', 'win_subsystem': 'windows', 'sources': [main_rs, files('system/main.c')], - 'dependencies': [sdl] + 'dependencies': [sdl, target_stubs], }] endif if get_option('fuzzing') @@ -4432,7 +4448,7 @@ foreach target : target_dirs 'name': 'qemu-' + target_name, 'win_subsystem': 'console', 'sources': [], - 'dependencies': [] + 'dependencies': [target_stubs] }] endif foreach exe: execs -- 2.53.0
