@samitouri / QOSamiQemu / commits / 0f5cf64e64

meson.build: define stubs library per target base architecture

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 <pierrick.bouvier@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20260424230103.1579600-2-pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Pierrick Bouvier committed Apr 9, 2026 at 14:37 UTC 0f5cf64e649b7abf49ccc741a89b283de2f9c22c
1 file changed +19 -3
meson.build
+19 -3
@@ -3738,6 +3738,7 @@ target_user_arch = {}
3738 hw_common_arch = {}
3739 target_common_arch = {}
3740 target_common_system_arch = {}
3741 +target_stubs_arch = {}
3742
3743 # NOTE: the trace/ subdirectory needs the qapi_trace_events variable
3744 # that is filled in by qapi/.
@@ -4143,6 +4144,7 @@ common_all = static_library('common',
4144 # construct common libraries per base architecture
4145 target_common_arch_libs = {}
4146 target_common_system_arch_libs = {}
4147 +target_stubs_arch_libs = {}
4148 foreach target_base_arch, config_base_arch : config_base_arch_mak
4149 target_inc = [include_directories('target' / target_base_arch)]
4150 inc = [common_user_inc + target_inc]
@@ -4202,6 +4204,15 @@ foreach target_base_arch, config_base_arch : config_base_arch_mak
4204 dependencies: src.all_dependencies() + common_deps + system_deps)
4205 target_common_system_arch_libs += {target_base_arch: lib}
4206 endif
4207 +
4208 + if target_base_arch in target_stubs_arch
4209 + src = target_stubs_arch[target_base_arch]
4210 + lib = static_library('stubs_' + target_base_arch,
4211 + sources: src.all_sources() + genh,
4212 + include_directories: inc,
4213 + c_args: target_system_c_args)
4214 + target_stubs_arch_libs += {target_base_arch: lib}
4215 + endif
4216 endforeach
4217
4218 if have_rust
@@ -4363,6 +4374,11 @@ foreach target : target_dirs
4374 objects += lib.extract_objects(src.sources())
4375 arch_deps += src.dependencies()
4376 endif
4377 + lib_target_stubs = []
4378 + if target_base_arch in target_stubs_arch_libs
4379 + lib_target_stubs = [target_stubs_arch_libs[target_base_arch]]
4380 + endif
4381 + target_stubs = declare_dependency(link_with: lib_target_stubs)
4382
4383 target_specific = specific_ss.apply(config_target, strict: false)
4384 arch_srcs += target_specific.sources()
@@ -4408,14 +4424,14 @@ foreach target : target_dirs
4424 'name': 'qemu-system-' + target_name,
4425 'win_subsystem': 'console',
4426 'sources': [main_rs, files('system/main.c')],
4411 - 'dependencies': [sdl]
4427 + 'dependencies': [sdl, target_stubs],
4428 }]
4429 if host_os == 'windows' and (sdl.found() or gtk.found())
4430 execs += [{
4431 'name': 'qemu-system-' + target_name + 'w',
4432 'win_subsystem': 'windows',
4433 'sources': [main_rs, files('system/main.c')],
4418 - 'dependencies': [sdl]
4434 + 'dependencies': [sdl, target_stubs],
4435 }]
4436 endif
4437 if get_option('fuzzing')
@@ -4432,7 +4448,7 @@ foreach target : target_dirs
4448 'name': 'qemu-' + target_name,
4449 'win_subsystem': 'console',
4450 'sources': [],
4435 - 'dependencies': []
4451 + 'dependencies': [target_stubs]
4452 }]
4453 endif
4454 foreach exe: execs