All of lore.kernel.org
 help / color / mirror / Atom feed
* Supporting clang on windows
@ 2024-11-24  0:21 Pierrick Bouvier
  2024-11-24 12:10 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Pierrick Bouvier @ 2024-11-24  0:21 UTC (permalink / raw)
  To: qemu-devel@nongnu.org, Paolo Bonzini, Daniel P. Berrangé,
	Thomas Huth
  Cc: Alex Bennée, Richard Henderson, Peter Maydell

Hi all,

very recently, I've been working on enabling clang builds on Windows 
[1]. As part of it, the major blocking point is that currently, clang 
does not support gcc_attribute on Windows.
The change proposed [2] was to use the compiler option [3] 
-mno-ms-bitfields, which enables the same behaviour. This option *only* 
has an effect on structs containing bitfields or structs that are 
packed, not on *all* structs.

The question that was left is: Is it was we want?

After thinking about it, a simple, exhaustive and reliable way to find 
this type information is the debug (dwarf) info.
By compiling qemu binaries with --enable-debug, and extracting info 
using llvm-dwarfdump plus a custom filter [4], we can obtain a text 
representation of all structures QEMU uses.

As expected, turning the option globally has an effect. The exact list 
of structures impacted (those having bitfields, and not being packed) 
can be seen for each binary here: [5].
As there is a lot of repetition between all qemu binaries, the reduced 
list of structs concerned is [6]:
+name:ArduinoMachineClass size:0x0198
+name:ARMCacheAttrs size:0x04
+name:ARMVAParameters size:0x04
+name:AspeedMachineClass size:0x01d0
+name:_GIOChannel size:0x70
+name:MachineClass size:0x0188
+name:MicrovmMachineClass size:0x01a0
+name:MPS2MachineClass size:0x01a8
+name:MPS2TZMachineClass size:0x01e8
+name:MPS3RMachineClass size:0x01a0
+name:MuscaMachineClass size:0x01a8
+name:NPCM7xxMachineClass size:0x0190
+name:PCMachineClass size:0x01c0
+name:PnvMachineClass size:0x01b0
+name:PPCE500MachineClass size:0x01e0
+name:RaspiBaseMachineClass size:0x0190
+name:RxGdbSimMachineClass size:0x0198
+name:S390CcwMachineClass size:0x0190
+name:SpaprMachineClass size:0x01d0
+name:Sun4mMachineClass size:0x0190
+name:TriBoardMachineClass size:0x01a0
+name:VexpressMachineClass size:0x0190
+name:VirtMachineClass size:0x01a0
+name:X86MachineClass size:0x0190

The interesting point I discovered is that, *after* this change, the new 
size start to match size when compiling for Linux.
After all, it makes totally sense: gcc by default mimics MSVC behaviour 
for bitfields, which is different from its behaviour on Linux.

As a conclusion, I think that applying gcc_struct selectively is a wrong 
default, and using globally the -mno-ms-bitfields allows to mimic what 
gcc is doing on Linux. We don't need any ABI compatibility with MSVC, so 
it's safe to enable this.

Before pushing the change again in a new series, I would like to get 
feedback from the concerned developers, and hope it can convince you 
this time it's a better approach than what we have.
As a side effect of all this, it will unlock supporting clang on 
windows, and with that, building it officially for windows-arm64, which 
was one of the goal of the original series.

Regards,
Pierrick

[1] 
https://lore.kernel.org/all/20241031040426.772604-1-pierrick.bouvier@linaro.org/
[2] 
https://lore.kernel.org/all/20241031040426.772604-8-pierrick.bouvier@linaro.org/
[3] https://gcc.gnu.org/onlinedocs/gcc/x86-Variable-Attributes.html
[4] 
https://github.com/pbo-linaro/qemu_packed_structs/blob/master/filter_dwarf_dump.sh
[5] 
https://github.com/pbo-linaro/qemu_packed_structs/commit/a47747b5220a933a94dbdc6e7bcd96589ae9abd0
[6] 
https://github.com/pbo-linaro/qemu_packed_structs/commit/9d41b7bd1fbd1d1553ae532e36c9305438549ae4


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

end of thread, other threads:[~2024-11-26 21:24 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-24  0:21 Supporting clang on windows Pierrick Bouvier
2024-11-24 12:10 ` Paolo Bonzini
2024-11-24 20:23   ` Pierrick Bouvier
2024-11-25  7:00     ` Paolo Bonzini
2024-11-25  9:34       ` Daniel P. Berrangé
2024-11-25  9:39         ` Paolo Bonzini
2024-11-25 10:42           ` Peter Maydell
2024-11-25 11:19           ` Thomas Huth
2024-11-25 16:48             ` Pierrick Bouvier
2024-11-25 17:05               ` Peter Maydell
2024-11-25 21:47                 ` Pierrick Bouvier
2024-11-26 21:24                   ` Pierrick Bouvier
2024-11-25 16:55       ` Pierrick Bouvier
2024-11-25  7:15     ` Thomas Huth
2024-11-24 12:28 ` Philippe Mathieu-Daudé
2024-11-24 20:24   ` Pierrick Bouvier
2024-11-25  6:31   ` Thomas Huth
2024-11-25 14:04 ` Richard Henderson
2024-11-25 16:19   ` Pierrick Bouvier

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.