@samitouri / QOSamiQemu / commits / e3d9c2a0ce

include: define constant for early constructor priority

Functions marked with __attribute__((__constructor__)) will be invoked in linker order. In theory this is well defined, but in practice, it is hard to determine what this order will be with the layers of indirection through meson, ninja and the static libraries QEMU builds. Notably, the order currently appears different between Linux and Windows (as tested with Wine on Linux). This can cause problems when certain QEMU constructors have a dependancy on other QEMU constructors. To address this define a QEMU_CONSTRUCTOR_EARLY constant which provides a priority value that will run before other default constructors. This is to be used for QEMU constructors that are themselves self-contained, but may be relied upon by other constructors. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Daniel P. Berrangé committed Aug 6, 2025 at 15:23 UTC e3d9c2a0ce10818a522db81111f0e3bd863cae54
1 file changed +8
include/qemu/compiler.h
+8
@@ -194,6 +194,14 @@
194 # define QEMU_USED
195 #endif
196
197 +/*
198 + * A priority for __attribute__((constructor(...))) that
199 + * will run earlier than the default constructors. Must
200 + * only be used for functions that have no dependency
201 + * on global initialization of other QEMU subsystems.
202 + */
203 +#define QEMU_CONSTRUCTOR_EARLY 101
204 +
205 /*
206 * Disable -ftrivial-auto-var-init on a local variable.
207 *