Skip to contentSkip to conversation

Fix packing for MinGW with -mms-bitfields

PATCH In review Stefan Weil 10 participants 32 messages Aug 28, 2011 – Sep 3, 2011 Block layer

lore
Share & tools
lore
#0 lore raw

cover Fix packing for MinGW with -mms-bitfields

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

The patches are split for different maintainers.
Feel free to combine them on commit.

I suggest replacing the remaining code with __attribute__((packed)) or __attribute__((__packed__)) in separate patches.

Cheers,
Stefan

[PATCH 1/7] Add new macro QEMU_PACKED for packed C structures [PATCH 2/7] block/vvfat: Fix packing for w32
[PATCH 3/7] acpi: Fix packing for w32
[PATCH 4/7] hpet: Fix packing for w32
[PATCH 5/7] usb: Fix packing for w32
[PATCH 6/7] virtio: Fix packing for w32
[PATCH 7/7] slirp: Fix packing for w32

#1 lore raw

PATCH 1/7 Add new macro QEMU_PACKED for packed C structures

A packed struct needs different gcc attributes for compilations with MinGW compilers because glib-2.0 adds compiler flag -mms-bitfields which modifies the packing algorithm.

Attribute gcc_struct reverses the negative effects of -mms-bitfields. QEMU_PACKED sets this attribute and must be used for any packed struct which is affected by -mms-bitfields.

---
 compiler.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
compiler.h +6 -0
index 9af5dc6..a2d5959 100644
@@ -12,6 +12,12 @@
 #define QEMU_WARN_UNUSED_RESULT
 #endif
 
+#if defined(_WIN32)
+# define QEMU_PACKED __attribute__((gcc_struct, packed))
+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif
+
 #define QEMU_BUILD_BUG_ON(x) \
     typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
 
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH 2/7 block/vvfat: Fix packing for w32

In reply to Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

---
 block/vvfat.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
block/vvfat.c +7 -7
index d6a07ef..ae1c03d 100644
@@ -200,7 +200,7 @@ static int array_index(array_t* array, void* pointer)
 }
 
 /* These structures are used to fake a disk and the VFAT filesystem.
- * For this reason we need to use __attribute__((packed)). */
+ * For this reason we need to use QEMU_PACKED. */
 
 typedef struct bootsector_t {
     uint8_t jump[3];
@@ -224,7 +224,7 @@ typedef struct bootsector_t {
 	    uint8_t signature;
 	    uint32_t id;
 	    uint8_t volume_label[11];
-	} __attribute__((packed)) fat16;
+        } QEMU_PACKED fat16;
 	struct {
 	    uint32_t sectors_per_fat;
 	    uint16_t flags;
@@ -233,12 +233,12 @@ typedef struct bootsector_t {
 	    uint16_t info_sector;
 	    uint16_t backup_boot_sector;
 	    uint16_t ignored;
-	} __attribute__((packed)) fat32;
+        } QEMU_PACKED fat32;
     } u;
     uint8_t fat_type[8];
     uint8_t ignored[0x1c0];
     uint8_t magic[2];
-} __attribute__((packed)) bootsector_t;
+} QEMU_PACKED bootsector_t;
 
 typedef struct {
     uint8_t head;
@@ -253,7 +253,7 @@ typedef struct partition_t {
     mbr_chs_t end_CHS;
     uint32_t start_sector_long;
     uint32_t length_sector_long;
-} __attribute__((packed)) partition_t;
+} QEMU_PACKED partition_t;
 
 typedef struct mbr_t {
     uint8_t ignored[0x1b8];
@@ -261,7 +261,7 @@ typedef struct mbr_t {
     uint8_t ignored2[2];
     partition_t partition[4];
     uint8_t magic[2];
-} __attribute__((packed)) mbr_t;
+} QEMU_PACKED mbr_t;
 
 typedef struct direntry_t {
     uint8_t name[8];
@@ -276,7 +276,7 @@ typedef struct direntry_t {
     uint16_t mdate;
     uint16_t begin;
     uint32_t size;
-} __attribute__((packed)) direntry_t;
+} QEMU_PACKED direntry_t;
 
 /* this structure are used to transparently access the files */
 
Signature · 1 line
1.7.0.4
#9 lore raw

PATCH 3/7 acpi: Fix packing for w32

In reply to Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

Cc Isaku Yamahata <[email protected]>
---
 hw/acpi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/acpi.c +1 -1
index d04b965..1cf35e1 100644
@@ -32,7 +32,7 @@ struct acpi_table_header {
     uint32_t oem_revision;    /* OEM revision number */
     char asl_compiler_id[4];  /* ASL compiler vendor ID */
     uint32_t asl_compiler_revision; /* ASL compiler revision number */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define ACPI_TABLE_HDR_SIZE sizeof(struct acpi_table_header)
 #define ACPI_TABLE_PFX_SIZE sizeof(uint16_t)  /* size of the extra prefix */
Signature · 1 line
1.7.0.4
#10 lore raw

PATCH 4/7 hpet: Fix packing for w32

In reply to Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

Cc Alexander Graf <[email protected]>
---
 hw/hpet_emul.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/hpet_emul.h +2 -2
index 8bf312a..6128702 100644
@@ -59,13 +59,13 @@ struct hpet_fw_entry
     uint64_t address;
     uint16_t min_tick;
     uint8_t page_prot;
-} __attribute__ ((packed));
+} QEMU_PACKED;
 
 struct hpet_fw_config
 {
     uint8_t count;
     struct hpet_fw_entry hpet[8];
-} __attribute__ ((packed));
+} QEMU_PACKED;
 
 extern struct hpet_fw_config hpet_cfg;
 #endif
Signature · 1 line
1.7.0.4
#12 lore raw

PATCH 6/7 virtio: Fix packing for w32

In reply to Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

Cc Anthony Liguori <[email protected]>
---
 hw/virtio-balloon.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/virtio-balloon.h +1 -1
index e20cf6b..73300dd 100644
@@ -50,6 +50,6 @@ struct virtio_balloon_config
 typedef struct VirtIOBalloonStat {
     uint16_t tag;
     uint64_t val;
-} __attribute__((packed)) VirtIOBalloonStat;
+} QEMU_PACKED VirtIOBalloonStat;
 
 #endif
Signature · 1 line
1.7.0.4
#11 lore raw

PATCH 5/7 usb: Fix packing for w32

In reply to Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

---
 hw/usb-ccid.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
hw/usb-ccid.c +9 -9
index 66aeb21..c2f9241 100644
@@ -176,56 +176,56 @@ enum {
      */
 };
 
-typedef struct __attribute__ ((__packed__)) CCID_Header {
+typedef struct QEMU_PACKED CCID_Header {
     uint8_t     bMessageType;
     uint32_t    dwLength;
     uint8_t     bSlot;
     uint8_t     bSeq;
 } CCID_Header;
 
-typedef struct __attribute__ ((__packed__)) CCID_BULK_IN {
+typedef struct QEMU_PACKED CCID_BULK_IN {
     CCID_Header hdr;
     uint8_t     bStatus;        /* Only used in BULK_IN */
     uint8_t     bError;         /* Only used in BULK_IN */
 } CCID_BULK_IN;
 
-typedef struct __attribute__ ((__packed__)) CCID_SlotStatus {
+typedef struct QEMU_PACKED CCID_SlotStatus {
     CCID_BULK_IN b;
     uint8_t     bClockStatus;
 } CCID_SlotStatus;
 
-typedef struct __attribute__ ((__packed__)) CCID_Parameter {
+typedef struct QEMU_PACKED CCID_Parameter {
     CCID_BULK_IN b;
     uint8_t     bProtocolNum;
     uint8_t     abProtocolDataStructure[0];
 } CCID_Parameter;
 
-typedef struct __attribute__ ((__packed__)) CCID_DataBlock {
+typedef struct QEMU_PACKED CCID_DataBlock {
     CCID_BULK_IN b;
     uint8_t      bChainParameter;
     uint8_t      abData[0];
 } CCID_DataBlock;
 
 /* 6.1.4 PC_to_RDR_XfrBlock */
-typedef struct __attribute__ ((__packed__)) CCID_XferBlock {
+typedef struct QEMU_PACKED CCID_XferBlock {
     CCID_Header  hdr;
     uint8_t      bBWI; /* Block Waiting Timeout */
     uint16_t     wLevelParameter; /* XXX currently unused */
     uint8_t      abData[0];
 } CCID_XferBlock;
 
-typedef struct __attribute__ ((__packed__)) CCID_IccPowerOn {
+typedef struct QEMU_PACKED CCID_IccPowerOn {
     CCID_Header hdr;
     uint8_t     bPowerSelect;
     uint16_t    abRFU;
 } CCID_IccPowerOn;
 
-typedef struct __attribute__ ((__packed__)) CCID_IccPowerOff {
+typedef struct QEMU_PACKED CCID_IccPowerOff {
     CCID_Header hdr;
     uint16_t    abRFU;
 } CCID_IccPowerOff;
 
-typedef struct __attribute__ ((__packed__)) CCID_SetParameters {
+typedef struct QEMU_PACKED CCID_SetParameters {
     CCID_Header hdr;
     uint8_t     bProtocolNum;
     uint16_t   abRFU;
Signature · 1 line
1.7.0.4
#13 lore raw

PATCH 7/7 slirp: Fix packing for w32

In reply to Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

---
 slirp/slirp.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
slirp/slirp.h +1 -1
index dcf99d5..28a5c03 100644
@@ -199,7 +199,7 @@ struct arphdr {
     uint32_t      ar_sip;           /* sender IP address       */
     unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
     uint32_t      ar_tip;           /* target IP address       */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define ARP_TABLE_SIZE 16
 
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] Add new macro QEMU_PACKED for packed C structures

In reply to Stefan Weil

Am 28.08.2011 um 22:43 schrieb Stefan Weil:

Quoted 3 lines

A packed struct needs different gcc attributes for compilations with MinGW compilers because glib-2.0 adds compiler flag -mms-bitfields which modifies the packing algorithm.

Is that algorithm actually needed anywhere? If not, is there no GCC option to fix this centrally in configure for win32 only?

Andreas

Quoted 30 lines

Attribute gcc_struct reverses the negative effects of -mms-bitfields. QEMU_PACKED sets this attribute and must be used for any packed struct which is affected by -mms-bitfields.

---
compiler.h | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
compiler.h +6 -0
index 9af5dc6..a2d5959 100644
@@ -12,6 +12,12 @@
 #define QEMU_WARN_UNUSED_RESULT
 #endif
 
+#if defined(_WIN32)
+# define QEMU_PACKED __attribute__((gcc_struct, packed))
+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif
+
 #define QEMU_BUILD_BUG_ON(x) \
    typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
 
Signature · 1 line
1.7.0.4
#17 lore raw
In reply to Stefan Weil
Quoted 5 lines · Stefan Weil

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

Quoted 19 lines

The patches are split for different maintainers.
Feel free to combine them on commit.

I suggest replacing the remaining code with __attribute__((packed)) or __attribute__((__packed__)) in separate patches.

Cheers,
Stefan

[PATCH 1/7] Add new macro QEMU_PACKED for packed C structures [PATCH 2/7] block/vvfat: Fix packing for w32
[PATCH 3/7] acpi: Fix packing for w32
[PATCH 4/7] hpet: Fix packing for w32
[PATCH 5/7] usb: Fix packing for w32
[PATCH 6/7] virtio: Fix packing for w32
[PATCH 7/7] slirp: Fix packing for w32

#18 lore raw

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 7 lines · Stefan Weil
Quoted 5 lines

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?) [PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

#3 lore raw

Re: [Qemu-devel] [PATCH 1/7] Add new macro QEMU_PACKED for packed C structures

In reply to Andreas Färber

Am 28.08.2011 22:47, schrieb Andreas Färber:

Quoted 9 lines

Am 28.08.2011 um 22:43 schrieb Stefan Weil:

Quoted 3 lines

A packed struct needs different gcc attributes for compilations with MinGW compilers because glib-2.0 adds compiler flag -mms-bitfields which modifies the packing algorithm.

Is that algorithm actually needed anywhere? If not, is there no GCC option to fix this centrally in configure for win32 only?

Andreas

I think it is needed: glib-2.0 requires -mms-bitfields for MinGW which breaks networking (and more) for w32 hosts because of changes in struct alignment. A central solution would require removal of -mms-bitfields or its effects. This is possible, but very risky, because it will raise problems with glib-2.0 and w32 libraries. Therefore a central solution was rejected.

See this thread:
http://lists.gnu.org/archive/html/qemu-devel/2011-08/msg01877.html

Stefan

#19 lore raw
In reply to Stefan Weil

Hi,

Quoted 4 lines
Quoted 2 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter.

[PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface)

Patch looks good (and is needed as the structs are part of the guest interface).

cheers,
Gerd

#20 lore raw
In reply to Stefan Weil
Quoted 27 lines · Stefan Weil

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 9 lines · Stefan Weil
Quoted 6 lines

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?) [PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

#21 lore raw

Am 29.08.2011 um 10:34 schrieb TeLeMan <[email protected]>:

Quoted 28 lines · Stefan Weil
Quoted 27 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 9 lines · Stefan Weil
Quoted 6 lines

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?) [PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Yes, please go through the complete source code and either replace the packed attribute by your macro or remove the unused ones. This patch set feels very x86-guest focused :)

I would however wait for another day and check if anyone is offended by the macro approach in general.

Thanks a lot for doing this!

Alex

#14 lore raw

Re: [Qemu-devel] [PATCH 7/7] slirp: Fix packing for w32

In reply to Stefan Weil
Quoted 14 lines · Stefan Weil

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

---
 slirp/slirp.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
slirp/slirp.h +0 -0
index dcf99d5..28a5c03 100644

slirp/slirp.h struct arphdr { · line 205

Quoted 8 lines
slirp/slirp.h +1 -1
@@ -199,7 +199,7 @@ struct arphdr {
     uint32_t      ar_sip;           /* sender IP address       */
     unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
     uint32_t      ar_tip;           /* target IP address       */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define ARP_TABLE_SIZE 16
 

There are further cases in slirp. Please address them as well.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#15 lore raw

Re: [Qemu-devel] [PATCH 7/7] slirp: Fix packing for w32

Am 29.08.2011 12:12, schrieb Jan Kiszka:

Quoted 21 lines · Stefan Weil
Quoted 20 lines

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

---
  slirp/slirp.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
slirp/slirp.h +1 -1
index dcf99d5..28a5c03 100644
@@ -199,7 +199,7 @@ struct arphdr {
      uint32_t      ar_sip;           /* sender IP address       */
      unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
      uint32_t      ar_tip;           /* target IP address       */
-} __attribute__((packed));
+} QEMU_PACKED;
 
Quoted 6 lines

slirp/slirp.h struct arphdr { · line 205

Quoted 2 lines
slirp/slirp.h +0 -0
  #define ARP_TABLE_SIZE 16
 

There are further cases in slirp. Please address them as well.

Jan

I only addressed those cases which are affected by -mms-bitfields, see
http://lists.gnu.org/archive/html/qemu-devel/2011-08/msg03428.html.

Other files with __attribute__((packed)) will be handled in separate patches.

I don't think that I missed a case which breaks slirp, but if I did, just tell me the struct name so I can fix it, too.

Stefan

#22 lore raw
In reply to TeLeMan

Am 29.08.2011 10:34, schrieb TeLeMan:

Quoted 28 lines · Stefan Weil
Quoted 27 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 9 lines · Stefan Weil
Quoted 6 lines

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?) [PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Oops, you are right. Obviously I missed all anonymous structs:
codiff simply ignores them, and pahole must be called with flags -a -A to show them. Who invented packing of structs?

Comparing the output of pahole -a -A is less elegant than using codiff, but shows the structs which you mentioned.

I suggest to apply my patch series first because it fixes the most important bugs in networking. The remaining bugs are in code which is used less often. They will be fixed by a second patch series which replaces all remaining packed attributes.

#16 lore raw

Re: [Qemu-devel] [PATCH 7/7] slirp: Fix packing for w32

In reply to Stefan Weil
Quoted 27 lines · Stefan Weil

Am 29.08.2011 12:12, schrieb Jan Kiszka:

Quoted 26 lines · Stefan Weil
Quoted 14 lines

Use QEMU_PACKED to eliminate the effects of compiler option -mms-bitfields.

---
  slirp/slirp.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
slirp/slirp.h +0 -0
index dcf99d5..28a5c03 100644

slirp/slirp.h struct arphdr { · line 205

Quoted 8 lines
slirp/slirp.h +1 -1
@@ -199,7 +199,7 @@ struct arphdr {
      uint32_t      ar_sip;           /* sender IP address       */
      unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
      uint32_t      ar_tip;           /* target IP address       */
-} __attribute__((packed));
+} QEMU_PACKED;
 
  #define ARP_TABLE_SIZE 16
 

There are further cases in slirp. Please address them as well.

Quoted 7 lines
Quoted 1 line

Jan

I only addressed those cases which are affected by -mms-bitfields, see
http://lists.gnu.org/archive/html/qemu-devel/2011-08/msg03428.html.

Other files with __attribute__((packed)) will be handled in separate patches.

OK, but this was not clear from the patch description.

Quoted 3 lines

I don't think that I missed a case which breaks slirp, but if I did, just tell me the struct name so I can fix it, too.

From just looking at the slirp struct, you are likely safe as none should have odd layouts.

Jan

#23 lore raw
In reply to Stefan Weil

Am 29.08.2011 21:55, schrieb Stefan Weil:

Quoted 41 lines

Am 29.08.2011 10:34, schrieb TeLeMan:

Quoted 31 lines · Stefan Weil
Quoted 30 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 11 lines
Quoted 7 lines · Stefan Weil

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?)
[PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Oops, you are right. Obviously I missed all anonymous structs:
codiff simply ignores them, and pahole must be called with flags -a -A to show them. Who invented packing of structs?

Quoted 8 lines

Comparing the output of pahole -a -A is less elegant than using codiff, but shows the structs which you mentioned.

I suggest to apply my patch series first because it fixes the most important bugs in networking. The remaining bugs are in code which is used less often. They will be fixed by a second patch series which replaces all remaining packed attributes.

Shouldn't we have a look at every packed structure instead of just fixing what we notice as broken in the x86 emulator binary with one given configuration? I think if there is a QEMU_PACKED, we should use it consistently, or is there a reason not to do so?

Kevin

#24 lore raw

Am 30.08.2011 09:44, schrieb Kevin Wolf:

Quoted 51 lines

Am 29.08.2011 21:55, schrieb Stefan Weil:

Quoted 41 lines

Am 29.08.2011 10:34, schrieb TeLeMan:

Quoted 31 lines · Stefan Weil
Quoted 30 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 11 lines
Quoted 7 lines · Stefan Weil

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?)
[PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Oops, you are right. Obviously I missed all anonymous structs:
codiff simply ignores them, and pahole must be called with flags -a -A to show them. Who invented packing of structs?

Quoted 8 lines

Comparing the output of pahole -a -A is less elegant than using codiff, but shows the structs which you mentioned.

I suggest to apply my patch series first because it fixes the most important bugs in networking. The remaining bugs are in code which is used less often. They will be fixed by a second patch series which replaces all remaining packed attributes.

Quoted 6 lines

Shouldn't we have a look at every packed structure instead of just fixing what we notice as broken in the x86 emulator binary with one given configuration? I think if there is a QEMU_PACKED, we should use it consistently, or is there a reason not to do so?

Kevin

Hi Kevin,

yes, we should use QEMU_PACKED instead of any __attribute__((packed)).

The first 7 patches simply introduce QEMU_PACKED and fix the most important bugs for those users who run QEMU on Windows. There was only a bug report for broken networking (fixed by Jan's committed patch and the above slirp patch). These fixes work for all targets, so chances are good that Windows users will have working binaries for the commonly used scenarios with any target - although I only examined qemu.exe.

For this reason, these patches should be applied to git master as soon as possible.

I did not intend to have a look at every packed structure as was suggested by Alex, Blue and others.
I simply wanted to run a global replace (perl -pi -e ...) which replaced the remaining __attributes__.

Reviewing every __attribute__ takes much more time of course:
there are more than 250 of them.
I don't think that a review is really necessary, because usually "packed" is not added just for fun, and most QEMU code was already reviewed. A small rate of unnecessary QEMU_PACKED would do no harm, because only performance suffers a little.

If more people agreed that QEMU_PACKED can be introduced mechanically by a script without a new review, I could send a patch very soon.

Cheers,
Stefan

#4 lore raw

Re: [Qemu-devel] [PATCH 1/7] Add new macro QEMU_PACKED for packed C structures

In reply to Stefan Weil
Quoted 18 lines · Stefan Weil

A packed struct needs different gcc attributes for compilations with MinGW compilers because glib-2.0 adds compiler flag -mms-bitfields which modifies the packing algorithm.

Attribute gcc_struct reverses the negative effects of -mms-bitfields. QEMU_PACKED sets this attribute and must be used for any packed struct which is affected by -mms-bitfields.

---
 compiler.h |    6 ++++++

 1 files changed, 6 insertions(+), 0 deletions(-)
compiler.h +0 -0
index 9af5dc6..a2d5959 100644

compiler.h line 16

Quoted 5 lines
compiler.h +2 -0
@@ -12,6 +12,12 @@
  #define QEMU_WARN_UNUSED_RESULT
  #endif
 
+#if defined(_WIN32)
+# define QEMU_PACKED __attribute__((gcc_struct, packed))

Maybe we could also use gcc_struct also for non-win32?

Quoted 12 lines
compiler.h +4 -1
+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif
+
  #define QEMU_BUILD_BUG_ON(x) \
     typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
 
--

1.7.0.4

#5 lore raw

Re: [Qemu-devel] [PATCH 1/7] Add new macro QEMU_PACKED for packed C structures

Quoted 8 lines · Blue Swirl
Quoted 3 lines
Quoted 3 lines

+#if defined(_WIN32)
+# define QEMU_PACKED __attribute__((gcc_struct, packed))

Maybe we could also use gcc_struct also for non-win32?

Quoted 3 lines
Quoted 3 lines

+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif

Indeed.

Paolo

#25 lore raw
In reply to Stefan Weil
Quoted 87 lines · Stefan Weil

Am 30.08.2011 09:44, schrieb Kevin Wolf:

Quoted 51 lines

Am 29.08.2011 21:55, schrieb Stefan Weil:

Quoted 41 lines

Am 29.08.2011 10:34, schrieb TeLeMan:

Quoted 31 lines · Stefan Weil
Quoted 30 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 11 lines
Quoted 7 lines · Stefan Weil

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?)
[PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Oops, you are right. Obviously I missed all anonymous structs:
codiff simply ignores them, and pahole must be called with flags -a -A to show them. Who invented packing of structs?

Quoted 8 lines

Comparing the output of pahole -a -A is less elegant than using codiff, but shows the structs which you mentioned.

I suggest to apply my patch series first because it fixes the most important bugs in networking. The remaining bugs are in code which is used less often. They will be fixed by a second patch series which replaces all remaining packed attributes.

Quoted 6 lines

Shouldn't we have a look at every packed structure instead of just fixing what we notice as broken in the x86 emulator binary with one given configuration? I think if there is a QEMU_PACKED, we should use it consistently, or is there a reason not to do so?

Kevin

Hi Kevin,

yes, we should use QEMU_PACKED instead of any __attribute__((packed)).

The first 7 patches simply introduce QEMU_PACKED and fix the most important bugs for those users who run QEMU on Windows. There was only a bug report for broken networking (fixed by Jan's committed patch and the above slirp patch). These fixes work for all targets, so chances are good that Windows users will have working binaries for the commonly used scenarios with any target - although I only examined qemu.exe.

For this reason, these patches should be applied to git master as soon as possible.

I did not intend to have a look at every packed structure as was suggested by Alex, Blue and others.
I simply wanted to run a global replace (perl -pi -e ...) which replaced the remaining __attributes__.

Reviewing every __attribute__ takes much more time of course:
there are more than 250 of them.
I don't think that a review is really necessary, because usually "packed" is not added just for fun, and most QEMU code was already reviewed. A small rate of unnecessary QEMU_PACKED would do no harm, because only performance suffers a little.

Quoted 3 lines

If more people agreed that QEMU_PACKED can be introduced mechanically by a script without a new review, I could send a patch very soon.

I think that's the better approach to the partial commit. Just introduce QEMU_PACKED, provide the script/sed cmdline you ran over the tree and replace it in every file. That makes more sense to commit than the partial conversion.

But please wait for a second opinion here :)

Alex

#26 lore raw
Quoted 90 lines · Alexander Graf
Quoted 87 lines · Stefan Weil

Am 30.08.2011 09:44, schrieb Kevin Wolf:

Quoted 51 lines

Am 29.08.2011 21:55, schrieb Stefan Weil:

Quoted 41 lines

Am 29.08.2011 10:34, schrieb TeLeMan:

Quoted 31 lines · Stefan Weil
Quoted 30 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 11 lines
Quoted 7 lines · Stefan Weil

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?)
[PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Oops, you are right. Obviously I missed all anonymous structs:
codiff simply ignores them, and pahole must be called with flags -a -A to show them. Who invented packing of structs?

Quoted 8 lines

Comparing the output of pahole -a -A is less elegant than using codiff, but shows the structs which you mentioned.

I suggest to apply my patch series first because it fixes the most important bugs in networking. The remaining bugs are in code which is used less often. They will be fixed by a second patch series which replaces all remaining packed attributes.

Quoted 6 lines

Shouldn't we have a look at every packed structure instead of just fixing what we notice as broken in the x86 emulator binary with one given configuration? I think if there is a QEMU_PACKED, we should use it consistently, or is there a reason not to do so?

Kevin

Hi Kevin,

yes, we should use QEMU_PACKED instead of any __attribute__((packed)).

The first 7 patches simply introduce QEMU_PACKED and fix the most important bugs for those users who run QEMU on Windows. There was only a bug report for broken networking (fixed by Jan's committed patch and the above slirp patch). These fixes work for all targets, so chances are good that Windows users will have working binaries for the commonly used scenarios with any target - although I only examined qemu.exe.

For this reason, these patches should be applied to git master as soon as possible.

I did not intend to have a look at every packed structure as was suggested by Alex, Blue and others.
I simply wanted to run a global replace (perl -pi -e ...) which replaced the remaining __attributes__.

Reviewing every __attribute__ takes much more time of course:
there are more than 250 of them.
I don't think that a review is really necessary, because usually "packed" is not added just for fun, and most QEMU code was already reviewed. A small rate of unnecessary QEMU_PACKED would do no harm, because only performance suffers a little.

Quoted 7 lines
Quoted 3 lines

If more people agreed that QEMU_PACKED can be introduced mechanically by a script without a new review, I could send a patch very soon.

I think that's the better approach to the partial commit. Just introduce QEMU_PACKED, provide the script/sed cmdline you ran over the tree and replace it in every file. That makes more sense to commit than the partial conversion.

But please wait for a second opinion here :)

I'm leaning slightly towards mechanical approach for consistency.

#6 lore raw

Re: [Qemu-devel] [PATCH 1/7] Add new macro QEMU_PACKED for packed C structures

In reply to Paolo Bonzini

Am 30.08.2011 20:29, schrieb Paolo Bonzini:

Quoted 6 lines · Blue Swirl
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

+#if defined(_WIN32)
+# define QEMU_PACKED __attribute__((gcc_struct, packed))

Maybe we could also use gcc_struct also for non-win32?

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif

Indeed.

Paolo

No. Extract from gcc documentation:

"Two attributes are currently defined for i386 configurations: |ms_struct| and |gcc_struct"

For non i386 configuration, these configurations are undefined:

mipsel-linux-gnu-gcc -c -Wall test.c
test.c:3: warning: ‘gcc_struct’ attribute directive ignored

Therefore, we cannot use gcc_struct for most supported hosts. Linux i386 or x86_64 would support it, but they don't need it...

We need one #if ... #else ... #endif to avoid 250 of them :-)

Stefan

|

#27 lore raw
In reply to Alexander Graf

Am 30.08.2011 20:29, schrieb Alexander Graf:

Quoted 90 lines · Stefan Weil
Quoted 88 lines

Am 30.08.2011 09:44, schrieb Kevin Wolf:

Quoted 51 lines

Am 29.08.2011 21:55, schrieb Stefan Weil:

Quoted 41 lines

Am 29.08.2011 10:34, schrieb TeLeMan:

Quoted 31 lines · Stefan Weil
Quoted 30 lines

Am 28.08.2011 23:43, schrieb Blue Swirl:

Quoted 11 lines
Quoted 7 lines · Stefan Weil

These patches fix the packing of structures which were affected by the new compiler attribute -mms-bitfields (which is needed for glib-2.0).

I compiled qemu.exe with and without -mms-bitfields and compared the resulting struct alignment using pahole and codiff.

Quoted 6 lines

If a structure is only used internally by QEMU (not used in network, disk or guest interfaces), changes in padding don't matter. In fact, in those cases it may be better to remove the packing, because then the fields may be naturally aligned and that gives better performance on most architectures. Could you please check if this is the case for any of the structs?

I did this already, but also forward your question to the maintainers. Here is my result:

[PATCH 2/7] block/vvfat: Fix packing for w32: needs packing (disk) [PATCH 3/7] acpi: Fix packing for w32: needs packing (bios interface) [PATCH 4/7] hpet: Fix packing for w32: needs packing (bios interface) [PATCH 5/7] usb: Fix packing for w32: needs packing (usb interface) [PATCH 6/7] virtio: Fix packing for w32: needs packing? (guest interface?)
[PATCH 7/7] slirp: Fix packing for w32: needs packing (network interface)

Quoted 4 lines
Quoted 2 lines

All those struct statements need the pack attribute (otherwise the code would have to be rewritten which is of course always possible).

gesn_cdb in atapi.c, VMDK4Header in vmdk.c and many structures in bt.h need be fixed too.

Oops, you are right. Obviously I missed all anonymous structs:
codiff simply ignores them, and pahole must be called with flags -a -A to show them. Who invented packing of structs?

Quoted 8 lines

Comparing the output of pahole -a -A is less elegant than using codiff, but shows the structs which you mentioned.

I suggest to apply my patch series first because it fixes the most important bugs in networking. The remaining bugs are in code which is used less often. They will be fixed by a second patch series which replaces all remaining packed attributes.

Quoted 6 lines

Shouldn't we have a look at every packed structure instead of just fixing what we notice as broken in the x86 emulator binary with one given configuration? I think if there is a QEMU_PACKED, we should use it consistently, or is there a reason not to do so?

Kevin

Hi Kevin,

yes, we should use QEMU_PACKED instead of any __attribute__((packed)).

The first 7 patches simply introduce QEMU_PACKED and fix the most important bugs for those users who run QEMU on Windows. There was only a bug report for broken networking (fixed by Jan's committed patch and the above slirp patch). These fixes work for all targets, so chances are good that Windows users will have working binaries for the commonly used scenarios with any target - although I only examined qemu.exe.

For this reason, these patches should be applied to git master as soon as possible.

I did not intend to have a look at every packed structure as was suggested by Alex, Blue and others.
I simply wanted to run a global replace (perl -pi -e ...) which replaced the remaining __attributes__.

Reviewing every __attribute__ takes much more time of course:
there are more than 250 of them.
I don't think that a review is really necessary, because usually "packed" is not added just for fun, and most QEMU code was already reviewed. A small rate of unnecessary QEMU_PACKED would do no harm, because only performance suffers a little.

Quoted 7 lines
Quoted 3 lines

If more people agreed that QEMU_PACKED can be introduced mechanically by a script without a new review, I could send a patch very soon.

I think that's the better approach to the partial commit. Just introduce QEMU_PACKED, provide the script/sed cmdline you ran over the tree and replace it in every file. That makes more sense to commit than the partial conversion.

But please wait for a second opinion here :)

I agree.

Kevin

#28 lore raw

cover Fix packing for MinGW with new macro QEMU_PACKED

The new series adds macro QEMU_PACKED and converts most code locations mechanically (script) to use this macro.

See log message of patch 2/2 for the few exceptions.

[PATCH 1/2] Add new macro QEMU_PACKED for packed C structures [PATCH 2/2] Use new macro QEMU_PACKED for packed structures

Cheers,
Stefan

#30 lore raw

PATCH 1/2 Add new macro QEMU_PACKED for packed C structures

In reply to Kevin Wolf

A packed struct needs different gcc attributes for compilations with MinGW compilers because glib-2.0 adds compiler flag -mms-bitfields which modifies the packing algorithm.

Attribute gcc_struct reverses the negative effects of -mms-bitfields. QEMU_PACKED sets this attribute and must be used for any packed struct which is affected by -mms-bitfields.

---
 compiler.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
compiler.h +6 -0
index 9af5dc6..a2d5959 100644
@@ -12,6 +12,12 @@
 #define QEMU_WARN_UNUSED_RESULT
 #endif
 
+#if defined(_WIN32)
+# define QEMU_PACKED __attribute__((gcc_struct, packed))
+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif
+
 #define QEMU_BUILD_BUG_ON(x) \
     typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
 
Signature · 1 line
1.7.2.5
#31 lore raw

PATCH 2/2 Use new macro QEMU_PACKED for packed structures

In reply to Kevin Wolf

Most changes were made using these commands:

git grep -la '__attribute__((packed))'|xargs perl -pi -e 's/__attribute__\(\(packed\)\)/QEMU_PACKED/' git grep -la '__attribute__ ((packed))'|xargs perl -pi -e 's/__attribute__ \(\(packed\)\)/QEMU_PACKED/' git grep -la '__attribute__((__packed__))'|xargs perl -pi -e 's/__attribute__\(\(__packed__\)\)/QEMU_PACKED/' git grep -la '__attribute__ ((__packed__))'|xargs perl -pi -e 's/__attribute__ \(\(__packed__\)\)/QEMU_PACKED/' git grep -la '__attribute((packed))'|xargs perl -pi -e 's/__attribute\(\(packed\)\)/QEMU_PACKED/'

Whitespace in linux-user/syscall_defs.h was fixed manually to avoid warnings from scripts/checkpatch.pl.

Manual changes were also applied to hw/pc.c.

I did not fix indentation with tabs in block/vvfat.c. The patch will show 4 errors with scripts/checkpatch.pl.

---
 a.out.h                   |    2 +-
 block.c                   |    2 +-
 block/parallels.c         |    2 +-
 block/qcow2-snapshot.c    |    2 +-
 block/vmdk.c              |    2 +-
 block/vvfat.c             |   14 +-
 hw/9pfs/virtio-9p.h       |    2 +-
 hw/acpi.c                 |    2 +-
 hw/bt.h                   |  332 ++++++++++++++++++++++----------------------
 hw/hpet_emul.h            |    4 +-
 hw/ide/ahci.h             |    6 +-
 hw/ide/atapi.c            |    4 +-
 hw/milkymist-tmu2.c       |    2 +-
 hw/pc.c                   |    4 +-
 hw/pxa2xx_lcd.c           |    2 +-
 hw/r2d.c                  |    2 +-
 hw/rc4030.c               |    2 +-
 hw/smbios.c               |    6 +-
 hw/smbios.h               |   22 ++--
 hw/srp.h                  |   10 +-
 hw/usb-ccid.c             |   18 ++--
 hw/virtio-balloon.h       |    2 +-
 hw/virtio-blk.h           |    2 +-
 hw/virtio-net.h           |    2 +-
 hw/virtio-serial.h        |    2 +-
 hw/vmware_vga.c           |    2 +-
 hw/zaurus.c               |    2 +-
 linux-user/syscall_defs.h |   16 +-
 m68k-semi.c               |    4 +-
 nbd.h                     |    4 +-
 slirp/ip.h                |   16 +-
 slirp/slirp.h             |    2 +-
 target-i386/kvm.c         |    2 +-
 target-i386/svm.h         |    8 +-
 target-s390x/cpu.h        |    2 +-
 tests/test-i386.c         |   10 +-
 36 files changed, 259 insertions(+), 259 deletions(-)
a.out.h +1 -1
index dfc104e..33ca7f7 100644
@@ -151,7 +151,7 @@ struct external_lineno {
 #define E_FILNMLEN	14	/* # characters in a file name		*/
 #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
 
-struct __attribute__((packed)) external_syment
+struct QEMU_PACKED external_syment
 {
   union {
     char e_name[E_SYMNMLEN];
block.c +1 -1
index 03a21d8..43742b7 100644
@@ -1327,7 +1327,7 @@ struct partition {
         uint8_t end_cyl;            /* end cylinder */
         uint32_t start_sect;        /* starting sector counting from 0 */
         uint32_t nr_sects;          /* nr of sectors in partition */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 /* try to guess the disk logical geometry from the MSDOS partition table. Return 0 if OK, -1 if could not guess */
 static int guess_disk_lchs(BlockDriverState *bs,
block/parallels.c +1 -1
index 37d151d..c64103d 100644
@@ -43,7 +43,7 @@ struct parallels_header {
     uint32_t catalog_entries;
     uint32_t nb_sectors;
     char padding[24];
-} __attribute__((packed));
+} QEMU_PACKED;
 
 typedef struct BDRVParallelsState {
 
block/qcow2-snapshot.c +1 -1
index 3e6bf8b..bdc33ba 100644
@@ -26,7 +26,7 @@
 #include "block_int.h"
 #include "block/qcow2.h"
 
-typedef struct __attribute__((packed)) QCowSnapshotHeader {
+typedef struct QEMU_PACKED QCowSnapshotHeader {
     /* header is 8 byte aligned */
     uint64_t l1_table_offset;
 
block/vmdk.c +1 -1
index 8da87ac..5f673e9 100644
@@ -56,7 +56,7 @@ typedef struct {
     int64_t grain_offset;
     char filler[1];
     char check_bytes[4];
-} __attribute__((packed)) VMDK4Header;
+} QEMU_PACKED VMDK4Header;
 
 #define L2_CACHE_SIZE 16
 
block/vvfat.c +7 -7
index d6a07ef..187ac96 100644
@@ -200,7 +200,7 @@ static int array_index(array_t* array, void* pointer)
 }
 
 /* These structures are used to fake a disk and the VFAT filesystem.
- * For this reason we need to use __attribute__((packed)). */
+ * For this reason we need to use QEMU_PACKED. */
 
 typedef struct bootsector_t {
     uint8_t jump[3];
@@ -224,7 +224,7 @@ typedef struct bootsector_t {
 	    uint8_t signature;
 	    uint32_t id;
 	    uint8_t volume_label[11];
-	} __attribute__((packed)) fat16;
+	} QEMU_PACKED fat16;
 	struct {
 	    uint32_t sectors_per_fat;
 	    uint16_t flags;
@@ -233,12 +233,12 @@ typedef struct bootsector_t {
 	    uint16_t info_sector;
 	    uint16_t backup_boot_sector;
 	    uint16_t ignored;
-	} __attribute__((packed)) fat32;
+	} QEMU_PACKED fat32;
     } u;
     uint8_t fat_type[8];
     uint8_t ignored[0x1c0];
     uint8_t magic[2];
-} __attribute__((packed)) bootsector_t;
+} QEMU_PACKED bootsector_t;
 
 typedef struct {
     uint8_t head;
@@ -253,7 +253,7 @@ typedef struct partition_t {
     mbr_chs_t end_CHS;
     uint32_t start_sector_long;
     uint32_t length_sector_long;
-} __attribute__((packed)) partition_t;
+} QEMU_PACKED partition_t;
 
 typedef struct mbr_t {
     uint8_t ignored[0x1b8];
@@ -261,7 +261,7 @@ typedef struct mbr_t {
     uint8_t ignored2[2];
     partition_t partition[4];
     uint8_t magic[2];
-} __attribute__((packed)) mbr_t;
+} QEMU_PACKED mbr_t;
 
 typedef struct direntry_t {
     uint8_t name[8];
@@ -276,7 +276,7 @@ typedef struct direntry_t {
     uint16_t mdate;
     uint16_t begin;
     uint32_t size;
-} __attribute__((packed)) direntry_t;
+} QEMU_PACKED direntry_t;
 
 /* this structure are used to transparently access the files */
 
hw/9pfs/virtio-9p.h +1 -1
index 1d8c1b1..d00a502 100644
@@ -314,7 +314,7 @@ struct virtio_9p_config
     uint16_t tag_len;
     /* Variable size tag name */
     uint8_t tag[0];
-} __attribute__((packed));
+} QEMU_PACKED;
 
 typedef struct V9fsMkState {
     V9fsPDU *pdu;
hw/acpi.c +1 -1
index d04b965..1cf35e1 100644
@@ -32,7 +32,7 @@ struct acpi_table_header {
     uint32_t oem_revision;    /* OEM revision number */
     char asl_compiler_id[4];  /* ASL compiler vendor ID */
     uint32_t asl_compiler_revision; /* ASL compiler revision number */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define ACPI_TABLE_HDR_SIZE sizeof(struct acpi_table_header)
 #define ACPI_TABLE_PFX_SIZE sizeof(uint16_t)  /* size of the extra prefix */
hw/bt.h +166 -166

1,255 lines not on this page · raw message

hw/hpet_emul.h +2 -2
index 8bf312a..6128702 100644
@@ -59,13 +59,13 @@ struct hpet_fw_entry
     uint64_t address;
     uint16_t min_tick;
     uint8_t page_prot;
-} __attribute__ ((packed));
+} QEMU_PACKED;
 
 struct hpet_fw_config
 {
     uint8_t count;
     struct hpet_fw_entry hpet[8];
-} __attribute__ ((packed));
+} QEMU_PACKED;
 
 extern struct hpet_fw_config hpet_cfg;
 #endif
hw/ide/ahci.h +3 -3
index 832539c..3c29d93 100644
@@ -244,13 +244,13 @@ typedef struct AHCICmdHdr {
     uint32_t    status;
     uint64_t    tbl_addr;
     uint32_t    reserved[4];
-} __attribute__ ((packed)) AHCICmdHdr;
+} QEMU_PACKED AHCICmdHdr;
 
 typedef struct AHCI_SG {
     uint64_t    addr;
     uint32_t    reserved;
     uint32_t    flags_size;
-} __attribute__ ((packed)) AHCI_SG;
+} QEMU_PACKED AHCI_SG;
 
 typedef struct AHCIDevice AHCIDevice;
 
@@ -321,7 +321,7 @@ typedef struct NCQFrame {
     uint8_t reserved8;
     uint8_t reserved9;
     uint8_t reserved10;
-} __attribute__ ((packed)) NCQFrame;
+} QEMU_PACKED NCQFrame;
 
 void ahci_init(AHCIState *s, DeviceState *qdev, int ports);
 void ahci_uninit(AHCIState *s);
hw/ide/atapi.c +2 -2
index c552320..f38d289 100644
@@ -557,13 +557,13 @@ static void cmd_get_event_status_notification(IDEState *s,
         uint8_t reserved3[2];
         uint16_t len;
         uint8_t control;
-    } __attribute__((packed)) *gesn_cdb;
+    } QEMU_PACKED *gesn_cdb;
 
     struct {
         uint16_t len;
         uint8_t notification_class;
         uint8_t supported_events;
-    } __attribute((packed)) *gesn_event_header;
+    } QEMU_PACKED *gesn_event_header;
 
     enum notification_class_request_type {
         NCR_RESERVED1 = 1 << 0,
hw/milkymist-tmu2.c +1 -1
index 790cdcb..953d42f 100644
@@ -73,7 +73,7 @@ enum {
 struct vertex {
     int x;
     int y;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 struct MilkymistTMU2State {
     SysBusDevice busdev;
hw/pc.c +2 -2
index 263fb1a..5bc845a 100644
@@ -78,12 +78,12 @@ struct e820_entry {
     uint64_t address;
     uint64_t length;
     uint32_t type;
-} __attribute((__packed__, __aligned__(4)));
+} QEMU_PACKED __attribute((__aligned__(4)));
 
 struct e820_table {
     uint32_t count;
     struct e820_entry entry[E820_NR_ENTRIES];
-} __attribute((__packed__, __aligned__(4)));
+} QEMU_PACKED __attribute((__aligned__(4)));
 
 static struct e820_table e820_table;
 struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
hw/pxa2xx_lcd.c +1 -1
index 97f9015..b73290c 100644
@@ -70,7 +70,7 @@ struct PXA2xxLCDState {
     int orientation;
 };
 
-typedef struct __attribute__ ((__packed__)) {
+typedef struct QEMU_PACKED {
     uint32_t fdaddr;
     uint32_t fsaddr;
     uint32_t fidr;
hw/r2d.c +1 -1
index 96a7ff8..771f3d0 100644
@@ -209,7 +209,7 @@ static void main_cpu_reset(void *opaque)
     env->pc = s->vector;
 }
 
-static struct __attribute__((__packed__))
+static struct QEMU_PACKED
 {
     int mount_root_rdonly;
     int ramdisk_flags;
hw/rc4030.c +1 -1
index a2a2099..33e1070 100644
@@ -50,7 +50,7 @@ do { fprintf(stderr, "rc4030 ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } whi
 typedef struct dma_pagetable_entry {
     int32_t frame;
     int32_t owner;
-} __attribute__((packed)) dma_pagetable_entry;
+} QEMU_PACKED dma_pagetable_entry;
 
 #define DMA_PAGESIZE    4096
 #define DMA_REG_ENABLE  1
hw/smbios.c +3 -3
index 8f2e965..c9ba43e 100644
@@ -21,19 +21,19 @@
 struct smbios_header {
     uint16_t length;
     uint8_t type;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 struct smbios_field {
     struct smbios_header header;
     uint8_t type;
     uint16_t offset;
     uint8_t data[];
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 struct smbios_table {
     struct smbios_header header;
     uint8_t data[];
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 #define SMBIOS_FIELD_ENTRY 0
 #define SMBIOS_TABLE_ENTRY 1
hw/smbios.h +11 -11
index 3a5169d..94e3641 100644
@@ -26,7 +26,7 @@ struct smbios_structure_header {
     uint8_t type;
     uint8_t length;
     uint16_t handle;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 0 - BIOS Information */
 struct smbios_type_0 {
@@ -42,7 +42,7 @@ struct smbios_type_0 {
     uint8_t system_bios_minor_release;
     uint8_t embedded_controller_major_release;
     uint8_t embedded_controller_minor_release;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 1 - System Information */
 struct smbios_type_1 {
@@ -55,7 +55,7 @@ struct smbios_type_1 {
     uint8_t wake_up_type;
     uint8_t sku_number_str;
     uint8_t family_str;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 3 - System Enclosure (v2.3) */
 struct smbios_type_3 {
@@ -74,7 +74,7 @@ struct smbios_type_3 {
     uint8_t number_of_power_cords;
     uint8_t contained_element_count;
     // contained elements follow
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 4 - Processor Information (v2.0) */
 struct smbios_type_4 {
@@ -94,7 +94,7 @@ struct smbios_type_4 {
     uint16_t l1_cache_handle;
     uint16_t l2_cache_handle;
     uint16_t l3_cache_handle;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 16 - Physical Memory Array
  *   Associated with one type 17 (Memory Device).
@@ -107,7 +107,7 @@ struct smbios_type_16 {
     uint32_t maximum_capacity;
     uint16_t memory_error_information_handle;
     uint16_t number_of_memory_devices;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 /* SMBIOS type 17 - Memory Device
  *   Associated with one type 19
  */
@@ -124,7 +124,7 @@ struct smbios_type_17 {
     uint8_t bank_locator_str;
     uint8_t memory_type;
     uint16_t type_detail;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 19 - Memory Array Mapped Address */
 struct smbios_type_19 {
@@ -133,7 +133,7 @@ struct smbios_type_19 {
     uint32_t ending_address;
     uint16_t memory_array_handle;
     uint8_t partition_width;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 20 - Memory Device Mapped Address */
 struct smbios_type_20 {
@@ -145,18 +145,18 @@ struct smbios_type_20 {
     uint8_t partition_row_position;
     uint8_t interleave_position;
     uint8_t interleaved_data_depth;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 32 - System Boot Information */
 struct smbios_type_32 {
     struct smbios_structure_header header;
     uint8_t reserved[6];
     uint8_t boot_status;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 /* SMBIOS type 127 -- End-of-table */
 struct smbios_type_127 {
     struct smbios_structure_header header;
-} __attribute__((__packed__));
+} QEMU_PACKED;
 
 #endif /*QEMU_SMBIOS_H */
hw/srp.h +5 -5
index afcd135..3009bd5 100644
@@ -106,7 +106,7 @@ struct srp_indirect_buf {
     struct srp_direct_buf    table_desc;
     uint32_t                 len;
     struct srp_direct_buf    desc_list[0];
-} __attribute__((packed));
+} QEMU_PACKED;
 
 enum {
     SRP_MULTICHAN_SINGLE = 0,
@@ -141,7 +141,7 @@ struct srp_login_rsp {
     uint16_t   buf_fmt;
     uint8_t    rsp_flags;
     uint8_t    reserved2[25];
-} __attribute__((packed));
+} QEMU_PACKED;
 
 struct srp_login_rej {
     uint8_t    opcode;
@@ -177,7 +177,7 @@ struct srp_tsk_mgmt {
     uint8_t    reserved1[6];
     uint64_t   tag;
     uint8_t    reserved2[4];
-    uint64_t   lun __attribute__((packed));
+    uint64_t   lun QEMU_PACKED;
     uint8_t    reserved3[2];
     uint8_t    tsk_mgmt_func;
     uint8_t    reserved4;
@@ -198,7 +198,7 @@ struct srp_cmd {
     uint8_t    data_in_desc_cnt;
     uint64_t   tag;
     uint8_t    reserved2[4];
-    uint64_t   lun __attribute__((packed));
+    uint64_t   lun QEMU_PACKED;
     uint8_t    reserved3;
     uint8_t    task_attr;
     uint8_t    reserved4;
@@ -235,6 +235,6 @@ struct srp_rsp {
     uint32_t   sense_data_len;
     uint32_t   resp_data_len;
     uint8_t    data[0];
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #endif /* SCSI_SRP_H */
hw/usb-ccid.c +9 -9
index 66aeb21..c2f9241 100644
@@ -176,56 +176,56 @@ enum {
      */
 };
 
-typedef struct __attribute__ ((__packed__)) CCID_Header {
+typedef struct QEMU_PACKED CCID_Header {
     uint8_t     bMessageType;
     uint32_t    dwLength;
     uint8_t     bSlot;
     uint8_t     bSeq;
 } CCID_Header;
 
-typedef struct __attribute__ ((__packed__)) CCID_BULK_IN {
+typedef struct QEMU_PACKED CCID_BULK_IN {
     CCID_Header hdr;
     uint8_t     bStatus;        /* Only used in BULK_IN */
     uint8_t     bError;         /* Only used in BULK_IN */
 } CCID_BULK_IN;
 
-typedef struct __attribute__ ((__packed__)) CCID_SlotStatus {
+typedef struct QEMU_PACKED CCID_SlotStatus {
     CCID_BULK_IN b;
     uint8_t     bClockStatus;
 } CCID_SlotStatus;
 
-typedef struct __attribute__ ((__packed__)) CCID_Parameter {
+typedef struct QEMU_PACKED CCID_Parameter {
     CCID_BULK_IN b;
     uint8_t     bProtocolNum;
     uint8_t     abProtocolDataStructure[0];
 } CCID_Parameter;
 
-typedef struct __attribute__ ((__packed__)) CCID_DataBlock {
+typedef struct QEMU_PACKED CCID_DataBlock {
     CCID_BULK_IN b;
     uint8_t      bChainParameter;
     uint8_t      abData[0];
 } CCID_DataBlock;
 
 /* 6.1.4 PC_to_RDR_XfrBlock */
-typedef struct __attribute__ ((__packed__)) CCID_XferBlock {
+typedef struct QEMU_PACKED CCID_XferBlock {
     CCID_Header  hdr;
     uint8_t      bBWI; /* Block Waiting Timeout */
     uint16_t     wLevelParameter; /* XXX currently unused */
     uint8_t      abData[0];
 } CCID_XferBlock;
 
-typedef struct __attribute__ ((__packed__)) CCID_IccPowerOn {
+typedef struct QEMU_PACKED CCID_IccPowerOn {
     CCID_Header hdr;
     uint8_t     bPowerSelect;
     uint16_t    abRFU;
 } CCID_IccPowerOn;
 
-typedef struct __attribute__ ((__packed__)) CCID_IccPowerOff {
+typedef struct QEMU_PACKED CCID_IccPowerOff {
     CCID_Header hdr;
     uint16_t    abRFU;
 } CCID_IccPowerOff;
 
-typedef struct __attribute__ ((__packed__)) CCID_SetParameters {
+typedef struct QEMU_PACKED CCID_SetParameters {
     CCID_Header hdr;
     uint8_t     bProtocolNum;
     uint16_t   abRFU;
hw/virtio-balloon.h +1 -1
index e20cf6b..73300dd 100644
@@ -50,6 +50,6 @@ struct virtio_balloon_config
 typedef struct VirtIOBalloonStat {
     uint16_t tag;
     uint64_t val;
-} __attribute__((packed)) VirtIOBalloonStat;
+} QEMU_PACKED VirtIOBalloonStat;
 
 #endif
hw/virtio-blk.h +1 -1
index 5645d2b..244dce4 100644
@@ -49,7 +49,7 @@ struct virtio_blk_config
     uint8_t alignment_offset;
     uint16_t min_io_size;
     uint32_t opt_io_size;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 /* These two define direction. */
 #define VIRTIO_BLK_T_IN         0
hw/virtio-net.h +1 -1
index 8af9a1c..4468741 100644
@@ -72,7 +72,7 @@ struct virtio_net_config
     uint8_t mac[ETH_ALEN];
     /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
     uint16_t status;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 /* This is the first element of the scatter-gather list.  If you don't
  * specify GSO or CSUM features, you can simply ignore the header. */
hw/virtio-serial.h +1 -1
index 36e9d22..ab13803 100644
@@ -37,7 +37,7 @@ struct virtio_console_config {
     uint16_t rows;
 
     uint32_t max_nr_ports;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 struct virtio_console_control {
     uint32_t id;		/* Port number */
hw/vmware_vga.c +1 -1
index 52d2d26..aa68237 100644
@@ -70,7 +70,7 @@ struct vmsvga_state_s {
 
     union {
         uint32_t *fifo;
-        struct __attribute__((__packed__)) {
+        struct QEMU_PACKED {
             uint32_t min;
             uint32_t max;
             uint32_t next_cmd;
hw/zaurus.c +1 -1
index c24aeb5..0eeacf7 100644
@@ -246,7 +246,7 @@ device_init(scoop_register);
 
 #define MAGIC_CHG(a, b, c, d)	((d << 24) | (c << 16) | (b << 8) | a)
 
-static struct __attribute__ ((__packed__)) sl_param_info {
+static struct QEMU_PACKED sl_param_info {
     uint32_t comadj_keyword;
     int32_t comadj;
 
linux-user/syscall_defs.h +8 -8
index a117407..15c44d4 100644
@@ -1120,7 +1120,7 @@ struct target_stat64 {
 	abi_ulong	__pad7;		/* will be high 32 bits of ctime someday */
 
 	unsigned long long	st_ino;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #ifdef TARGET_ARM
 struct target_eabi_stat64 {
@@ -1151,7 +1151,7 @@ struct target_eabi_stat64 {
         abi_ulong    target_st_ctime_nsec;
 
         unsigned long long st_ino;
-} __attribute__ ((packed));
+} QEMU_PACKED;
 #endif
 
 #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
@@ -1294,7 +1294,7 @@ struct target_stat {
 #endif
 };
 
-struct __attribute__((__packed__)) target_stat64 {
+struct QEMU_PACKED target_stat64 {
 	unsigned long long st_dev;
         unsigned long long st_ino;
 	unsigned int st_mode;
@@ -1341,7 +1341,7 @@ struct target_stat {
 };
 
 /* FIXME: Microblaze no-mmu user-space has a difference stat64 layout...  */
-struct __attribute__((__packed__)) target_stat64 {
+struct QEMU_PACKED target_stat64 {
 	uint64_t st_dev;
 #define TARGET_STAT64_HAS_BROKEN_ST_INO 1
 	uint32_t pad0;
@@ -1428,7 +1428,7 @@ struct target_stat64 {
 	abi_ulong	target_st_ctime_nsec;
 
 	unsigned long long	st_ino;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #elif defined(TARGET_ABI_MIPSN64)
 
@@ -1680,7 +1680,7 @@ struct target_stat {
 /* This matches struct stat64 in glibc2.1, hence the absolutely
  * insane amounts of padding around dev_t's.
  */
-struct __attribute__((__packed__)) target_stat64 {
+struct QEMU_PACKED target_stat64 {
 	unsigned long long	st_dev;
 	unsigned char	__pad0[4];
 
@@ -2095,7 +2095,7 @@ struct target_flock64 {
 	unsigned long long l_start;
 	unsigned long long l_len;
 	int  l_pid;
-}__attribute__((packed));
+} QEMU_PACKED;
 
 #ifdef TARGET_ARM
 struct target_eabi_flock64 {
@@ -2105,7 +2105,7 @@ struct target_eabi_flock64 {
 	unsigned long long l_start;
 	unsigned long long l_len;
 	int  l_pid;
-}__attribute__((packed));
+} QEMU_PACKED;
 #endif
 
 /* soundcard defines */
m68k-semi.c +2 -2
index 7fde10e..bab01ee 100644
@@ -70,12 +70,12 @@ struct m68k_gdb_stat {
   gdb_time_t  gdb_st_atime;   /* time of last access */
   gdb_time_t  gdb_st_mtime;   /* time of last modification */
   gdb_time_t  gdb_st_ctime;   /* time of last change */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 struct gdb_timeval {
   gdb_time_t tv_sec;  /* second */
   uint64_t tv_usec;   /* microsecond */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define GDB_O_RDONLY   0x0
 #define GDB_O_WRONLY   0x1
nbd.h +2 -2
index b38d0d0..96f77fe 100644
@@ -31,13 +31,13 @@ struct nbd_request {
     uint64_t handle;
     uint64_t from;
     uint32_t len;
-} __attribute__ ((__packed__));
+} QEMU_PACKED;
 
 struct nbd_reply {
     uint32_t magic;
     uint32_t error;
     uint64_t handle;
-} __attribute__ ((__packed__));
+} QEMU_PACKED;
 
 enum {
     NBD_CMD_READ = 0,
slirp/ip.h +8 -8
index 72dbe9a..88c903f 100644
@@ -91,7 +91,7 @@ struct ip {
 	uint8_t ip_p;			/* protocol */
 	uint16_t	ip_sum;			/* checksum */
 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define	IP_MAXPACKET	65535		/* maximum packet size */
 
@@ -153,7 +153,7 @@ struct	ip_timestamp {
 			n_long ipt_time;
 		} ipt_ta[1];
 	} ipt_timestamp;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 /* flag bits for ipt_flg */
 #define	IPOPT_TS_TSONLY		0		/* timestamps only */
@@ -183,11 +183,11 @@ struct	ip_timestamp {
 struct mbuf_ptr {
 	struct mbuf *mptr;
 	uint32_t dummy;
-} __attribute__((packed));
+} QEMU_PACKED;
 #else
 struct mbuf_ptr {
 	struct mbuf *mptr;
-} __attribute__((packed));
+} QEMU_PACKED;
 #endif
 struct qlink {
 	void *next, *prev;
@@ -203,7 +203,7 @@ struct ipovly {
 	uint16_t	ih_len;			/* protocol length */
 	struct	in_addr ih_src;		/* source internet address */
 	struct	in_addr ih_dst;		/* destination internet address */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 /*
  * Ip reassembly queue structure.  Each fragment
@@ -219,7 +219,7 @@ struct ipq {
 	uint8_t	ipq_p;			/* protocol of this fragment */
 	uint16_t	ipq_id;			/* sequence id for reassembly */
 	struct	in_addr ipq_src,ipq_dst;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 /*
  * Ip header, when holding a fragment.
@@ -229,7 +229,7 @@ struct ipq {
 struct	ipasfrag {
 	struct qlink ipf_link;
 	struct ip ipf_ip;
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define ipf_off      ipf_ip.ip_off
 #define ipf_tos      ipf_ip.ip_tos
@@ -248,6 +248,6 @@ struct	ipasfrag {
 struct ipoption {
 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
 	int8_t	ipopt_list[MAX_IPOPTLEN];	/* options proper */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #endif
slirp/slirp.h +1 -1
index dcf99d5..28a5c03 100644
@@ -199,7 +199,7 @@ struct arphdr {
     uint32_t      ar_sip;           /* sender IP address       */
     unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
     uint32_t      ar_tip;           /* target IP address       */
-} __attribute__((packed));
+} QEMU_PACKED;
 
 #define ARP_TABLE_SIZE 16
 
target-i386/kvm.c +1 -1
index 1d9b20c..70ef74b 100644
@@ -348,7 +348,7 @@ int kvm_arch_init_vcpu(CPUState *env)
     struct {
         struct kvm_cpuid2 cpuid;
         struct kvm_cpuid_entry2 entries[100];
-    } __attribute__((packed)) cpuid_data;
+    } QEMU_PACKED cpuid_data;
     KVMState *s = env->kvm_state;
     uint32_t limit, i, j, cpuid_i;
     uint32_t unused;
target-i386/svm.h +4 -4
index a224aea..04193ed 100644
@@ -130,7 +130,7 @@
 
 #define SVM_CR0_SELECTIVE_MASK (1 << 3 | 1) /* TS and MP */
 
-struct __attribute__ ((__packed__)) vmcb_control_area {
+struct QEMU_PACKED vmcb_control_area {
 	uint16_t intercept_cr_read;
 	uint16_t intercept_cr_write;
 	uint16_t intercept_dr_read;
@@ -162,14 +162,14 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
 	uint8_t reserved_5[832];
 };
 
-struct __attribute__ ((__packed__)) vmcb_seg {
+struct QEMU_PACKED vmcb_seg {
 	uint16_t selector;
 	uint16_t attrib;
 	uint32_t limit;
 	uint64_t base;
 };
 
-struct __attribute__ ((__packed__)) vmcb_save_area {
+struct QEMU_PACKED vmcb_save_area {
 	struct vmcb_seg es;
 	struct vmcb_seg cs;
 	struct vmcb_seg ss;
@@ -214,7 +214,7 @@ struct __attribute__ ((__packed__)) vmcb_save_area {
 	uint64_t last_excp_to;
 };
 
-struct __attribute__ ((__packed__)) vmcb {
+struct QEMU_PACKED vmcb {
 	struct vmcb_control_area control;
 	struct vmcb_save_area save;
 };
target-s390x/cpu.h +1 -1
index f8f0c82..e192b50 100644
@@ -698,7 +698,7 @@ typedef struct LowCore
     /* align to the top of the prefix area */
 
     uint8_t         pad18[0x2000-0x1400];      /* 0x1400 */
-} __attribute__((packed)) LowCore;
+} QEMU_PACKED LowCore;
 
 /* STSI */
 #define STSI_LEVEL_MASK         0x00000000f0000000ULL
tests/test-i386.c +5 -5
index 56ff110..9cb5b51 100644
@@ -773,7 +773,7 @@ void test_fops(double a, double b)
 
 void fpu_clear_exceptions(void)
 {
-    struct __attribute__((packed)) {
+    struct QEMU_PACKED {
         uint16_t fpuc;
         uint16_t dummy1;
         uint16_t fpus;
@@ -924,7 +924,7 @@ void test_fbcd(double a)
 
 void test_fenv(void)
 {
-    struct __attribute__((packed)) {
+    struct QEMU_PACKED {
         uint16_t fpuc;
         uint16_t dummy1;
         uint16_t fpus;
@@ -934,7 +934,7 @@ void test_fenv(void)
         uint32_t ignored[4];
         long double fpregs[8];
     } float_env32;
-    struct __attribute__((packed)) {
+    struct QEMU_PACKED {
         uint16_t fpuc;
         uint16_t fpus;
         uint16_t fptag;
@@ -1279,7 +1279,7 @@ void test_segs(void)
     struct {
         uint32_t offset;
         uint16_t seg;
-    } __attribute__((packed)) segoff;
+    } QEMU_PACKED segoff;
 
     ldt.entry_number = 1;
     ldt.base_addr = (unsigned long)&seg_data1;
@@ -1441,7 +1441,7 @@ void test_misc(void)
         /* XXX: see if Intel Core2 and AMD64 behavior really
            differ. Here we implemented the Intel way which is not
            compatible yet with QEMU. */
-        static struct __attribute__((packed)) {
+        static struct QEMU_PACKED {
             uint64_t offset;
             uint16_t seg;
         } desc;
Signature · 1 line
1.7.2.5
Applied
#29 lore raw

Re: [Qemu-devel] [PATCH 0/2] Fix packing for MinGW with new macro QEMU_PACKED

In reply to Stefan Weil
Quoted 7 lines · Stefan Weil

The new series adds macro QEMU_PACKED and converts most code locations mechanically (script) to use this macro.

See log message of patch 2/2 for the few exceptions.

[PATCH 1/2] Add new macro QEMU_PACKED for packed C structures [PATCH 2/2] Use new macro QEMU_PACKED for packed structures

Thanks, applied both.