All of lore.kernel.org
 help / color / mirror / Atom feed
* Artificially target-dependend compiles
@ 2021-11-05 13:45 Markus Armbruster
  2021-11-05 16:15 ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Armbruster @ 2021-11-05 13:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini

Some .c need to be compiled per target.  build-system.rst calls these
target-dependent.

Consider hw/acpi/vmgenid.c.  hw/acpi/meson.build has

    acpi_ss.add(when: 'CONFIG_ACPI_VMGENID', if_true: files('vmgenid.c'))

and

    softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss)

softmmu_ss is target-independent, and so is hw/acpi/vmgenid.c.

The C macro CONFIG_ACPI_VMGENID is actually target-dependent;
config-poison.h has

    #pragma GCC poison CONFIG_ACPI_VMGENID

This feels odd until you think about it some.  Meson's
CONFIG_ACPI_VMGENID means "we need to compile hw/acpi/vmgenid.c (because
at least one target we're building needs it)".  We have no use for a C
macro with this meaning.  We sometimes want "*this* target needs it".
That's C macro CONFIG_ACPI_VMGENID.  It's unused, as far as I can tell.
Similar C macros exist that are used.


QMP command query-vm-generation-id exists regardless of either
CONFIG_ACPI_VMGENID.  For targets with CONFIG_ACPI_VMGENID, we link the
real handler from hw/acpi/vmgenid.c.  For other targets, we link the
stub from stubs/vmgenid.c, which always fails.

This works, but it's not introspectable.  To make it introspectable,
we'd have to make the command conditional.  Naive attempt:

    diff --git a/qapi/machine.json b/qapi/machine.json
    index 17794ef681..e554cac53d 100644
    --- a/qapi/machine.json
    +++ b/qapi/machine.json
    @@ -264,7 +264,8 @@
     #
     # Since: 2.9
     ##
    -{ 'struct': 'GuidInfo', 'data': {'guid': 'str'} }
    +{ 'struct': 'GuidInfo', 'data': {'guid': 'str'},
    +  'if': 'CONFIG_ACPI_VMGENID' }

     ##
     # @query-vm-generation-id:
    @@ -273,7 +274,8 @@
     #
     # Since: 2.9
     ##
    -{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
    +{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo',
    +  'if': 'CONFIG_ACPI_VMGENID' }

     ##
     # @system_reset:

No go, because CONFIG_ACPI_VMGENID can only be used in target-dependent
code.

Moving these definitions to machine-target.json moves the generated C
from qapi/qapi-*-machine.[ch] to qapi/qapi-*-machine-target.[ch], where
CONFIG_ACPI_VMGENID is okay.  It also makes qmp_query_vm_generation_id()
target-dependent: it needs qapi/qapi-commands-machine-target.h.

The target-dependence is completely artificial: compiling
hw/acpi/vmgenid.c just once is as fine as it ever was.

You might challenge the utility of making this one introspectable.  I'm
not going to debate; it's just a random example.  The problem exists
unless you can demonstrate that introspection is useless for *all*
commands with similar target-dependent stubbery.


Have you seen similar artificial target-dependence elsewhere?

Any smart ideas on avoiding it?



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-08 16:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 13:45 Artificially target-dependend compiles Markus Armbruster
2021-11-05 16:15 ` Paolo Bonzini
2021-11-06  7:40   ` Markus Armbruster
2021-11-08  8:09     ` Markus Armbruster
2021-11-08 10:27       ` Paolo Bonzini
2021-11-08 15:38       ` Thomas Huth
2021-11-08 16:23         ` Paolo Bonzini
2021-11-08 16:30           ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.