hw/usb: Use __attribute__((packed)) vs __packed
PATCH 1/1 hw/usb: Use __attribute__((packed)) vs __packed
__packed is non standard and is not present in clang-cl. __attribute__((packed)) has the same semantics.
--- include/hw/usb/dwc2-regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/usb/dwc2-regs.h +1 -1
@@ -838,7 +838,7 @@struct dwc2_dma_desc {uint32_t status;uint32_t buf; -} __packed; +}QEMU_PACKED ;/* Host Mode DMA descriptor status quadlet */
Signature · 1 line
2.47.0.163.g1226f6d8fa-goog
Quoted 14 lines · Roque Arcudia Hernandez
__packedis non standard and is not present in clang-cl. __attribute__((packed)) has the same semantics.Signed-off-by Erwin Jansen <[email protected]>Signed-off-by Roque Arcudia Hernandez <[email protected]>--- include/hw/usb/dwc2-regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/usb/dwc2-regs.h +0
-0
include/hw/usb/dwc2-regs.h line 844
Quoted 8 lines
include/hw/usb/dwc2-regs.h +1
-1@@ -838,7 +838,7 @@struct dwc2_dma_desc {uint32_t status;uint32_t buf; -} __packed; +}QEMU_PACKED ;/* Host Mode DMA descriptor status quadlet */
Quoted 14 lines · Roque Arcudia Hernandez
__packedis non standard and is not present in clang-cl. __attribute__((packed)) has the same semantics.Signed-off-by Erwin Jansen <[email protected]>Signed-off-by Roque Arcudia Hernandez <[email protected]>--- include/hw/usb/dwc2-regs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/usb/dwc2-regs.h +0
-0
include/hw/usb/dwc2-regs.h line 841
Quoted 5 lines
include/hw/usb/dwc2-regs.h +1
-1@@ -838,7 +838,7 @@struct dwc2_dma_desc {uint32_t status;uint32_t buf; -} __packed; +}QEMU_PACKED ;
Actually, the struct only consists of two 32-bit values, so I doubt that the "packed" is needed here at all. Maybe we could even simply remove it?
Thomas
Quoted 23 lines · Thomas Huth
Quoted 14 lines · Roque Arcudia Hernandez
__packedis non standard and is not present in clang-cl. __attribute__((packed)) has the same semantics.Signed-off-by Erwin Jansen <[email protected]>Signed-off-by Roque Arcudia Hernandez <[email protected]>---
include/hw/usb/dwc2-regs.h| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)include/hw/usb/dwc2-regs.h +0
-0include/hw/usb/dwc2-regs.h line 841
Quoted 5 lines
include/hw/usb/dwc2-regs.h +1
-1@@ -838,7 +838,7 @@ struct dwc2_dma_desc { uint32_t status; uint32_t buf; -} __packed; +}QEMU_PACKED ;Reviewed-by Thomas Huth <[email protected]>
Quoted 1 line
Actually, the struct only consists of two 32-bit values, so I doubt that the "packed" is needed here at all. Maybe we could even simply remove it?
To me it is important to mark structures as packed if it is important for them to have strict layout like in this case, even if de-facto it does not change the actual layout. It's just like an annotation saying this structure can be used on wire or somesuch.
/mjt
Quoted 24 lines · Michael Tokarev
Quoted 23 lines · Thomas Huth
Quoted 14 lines · Roque Arcudia Hernandez
__packedis non standard and is not present in clang-cl. __attribute__((packed)) has the same semantics.Signed-off-by Erwin Jansen <[email protected]>Signed-off-by Roque Arcudia Hernandez <[email protected]>---
include/hw/usb/dwc2-regs.h| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)include/hw/usb/dwc2-regs.h +0
-0include/hw/usb/dwc2-regs.h line 841
Quoted 5 lines
include/hw/usb/dwc2-regs.h +1
-1@@ -838,7 +838,7 @@ struct dwc2_dma_desc { uint32_t status; uint32_t buf; -} __packed; +}QEMU_PACKED ;Reviewed-by Thomas Huth <[email protected]>
Quoted 6 lines
Quoted 1 line
Actually, the struct only consists of two 32-bit values, so I doubt that the "packed" is needed here at all. Maybe we could even simply remove it?
To me it is important to mark structures as packed if it is important for them to have strict layout like in this case, even if de-facto it does not change the actual layout. It's just like an annotation saying this structure can be used on wire or somesuch.
Well, it can have an impact on your binary, too. On architectures that don't support unaligned memory accesses, the compiler has to generate code that reads the values of packed structures in a more cumbersome way. So if you used "packed" though it's not really necessary (i.e. everything is naturally aligned, and you can be sure that the starting address is also properly aligned), the compiler generates worse code than necessary in that case.
Thomas
Quoted 25 lines · Thomas Huth
Quoted 24 lines · Michael Tokarev
Quoted 23 lines · Thomas Huth
Quoted 14 lines · Roque Arcudia Hernandez
__packedis non standard and is not present in clang-cl. __attribute__((packed)) has the same semantics.Signed-off-by Erwin Jansen <[email protected]>Signed-off-by Roque Arcudia Hernandez <[email protected]>---
include/hw/usb/dwc2-regs.h| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)include/hw/usb/dwc2-regs.h +0
-0include/hw/usb/dwc2-regs.h line 841
Quoted 5 lines
include/hw/usb/dwc2-regs.h +1
-1@@ -838,7 +838,7 @@ struct dwc2_dma_desc { uint32_t status; uint32_t buf; -} __packed; +}QEMU_PACKED ;Reviewed-by Thomas Huth <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Actually, the struct only consists of two 32-bit values, so I doubt that the "packed" is needed here at all. Maybe we could even simply remove it?
To me it is important to mark structures as packed if it is important for them to have strict layout like in this case, even if de-facto it does not change the actual layout. It's just like an annotation saying this structure can be used on wire or somesuch.
Well, it can have an impact on your binary, too. On architectures that don't support unaligned memory accesses, the compiler has to generate code that reads the values of packed structures in a more cumbersome way. So if you used "packed" though it's not really necessary (i.e. everything is naturally aligned, and you can be sure that the starting address is also properly aligned), the compiler generates worse code than necessary in that case.
Well, in this case the struct is downright unused. :) But we can't know if it is naturally aligned or not in guest memory, so it is advisable to keep the QEMU_PACKED.
Paolo