From 0f5cf64e649b7abf49ccc741a89b283de2f9c22c Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier Date: Thu, 9 Apr 2026 14:37:02 -0700 Subject: [PATCH] meson.build: define stubs library per target base architecture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20260424230103.1579600-2-pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Philippe Mathieu-Daudé --- meson.build | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 987f33bace..5fbdc75a0f 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