On 2/3/26 5:36 PM, Richard Henderson wrote:
On 2/4/26 05:41, Pierrick Bouvier wrote:
target_arch() function will reparse target_name() every time if it was
not set to a proper SYS_EMU_TARGET_* value (when using
target-info-stub.c), which is not efficient.
Since we want to preserve the constness of TargetInfo but C doesn't give
us flexible compile time expressions, we simply set target_arch using a
static constructor once instead.
A static constructor isn't static initialization.
That said, we can do better with some extra help from meson; see attached.
I'm mildly annoyed with openrisc vs or1k. We really ought to fix that, but I
haven't
looked into what API breakage we get from selecting one or the other.
This was my first approach, and I noticed the or1k issue + missing
hexagon in SYS_EMU_TARGET enum. Having a hack for target name in
meson.build is *really* ugly IMHO.
At the moment, hexagon is only linux-user, so I thought it didn't make
sense to add it to SYS_EMU_TARGET, and I didn't want to go down the
rabbit hole to rename or extend this qapi definition, as the initial
goal is just to define a field before main, which I consider to be
static initialization, even though you might prefer to call it differently.
So with all that, having a function with constructor attribute seemed
like being the best compromise between maintainability and efficiency.
I'll let you upstream whatever changes you prefer, and I drop this patch.
Regards,
Pierrick