qemu fails to compile on gcc 9 `error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]`

Bug #1824528 reported by Satheesh Rajendran
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Fix Released
Undecided
Unassigned

Bug Description

Qemu compilation fails with below error on ppc64le host with gcc 9(9.0.1 20190328)
repo: https://github.com/qemu/qemu.git
branch: master
commit e1be98540ee672ef93292b65a986055512237c35

  CC net/dump.o
hw/usb/dev-mtp.c: In function ‘usb_mtp_write_metadata’:
hw/usb/dev-mtp.c:1708:36: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
 1708 | dataset->filename);
      | ~~~~~~~^~~~~~~~~~
cc1: all warnings being treated as errors
  CC net/eth.o
make: *** [/home/kvmci/qemu-main/rules.mak:69: hw/usb/dev-mtp.o] Error 1
make: *** Waiting for unfinished jobs....
  CC net/announce.o

Revision history for this message
Satheesh Rajendran (sathnaga) wrote :

Tried to patch as below and it compiles fine, not sure if this is right fix though,

# git diff
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index ebf210f..7d512e5 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -231,7 +231,7 @@ typedef struct {
     char date_modified[0]; /*unused*/
     char keywords[0]; /*unused*/
     /* string and other data follows */
-} QEMU_PACKED ObjectInfo;
+} ObjectInfo;

 #define TYPE_USB_MTP "usb-mtp"
 #define USB_MTP(obj) OBJECT_CHECK(MTPState, (obj), TYPE_USB_MTP)

Revision history for this message
Daniel Berrange (berrange) wrote :

This struct represents the MTP protocol wire format so *must* be marked packed.

There unfortunately quite a few flaws in this MTP code area, so fixing the gcc warning is not straightforward.

https://lists.gnu.org/archive/html/qemu-devel/2019-03/msg07763.html

Revision history for this message
Peter Maydell (pmaydell) wrote :

As a workaround, the simplest thing is to configure with --disable-werror, which will reduce these from errors to warnings. (This is the default if you're building from one of our release tarballs, but for builds from git we default to making all warnings into errors so we catch and fix them quickly.)

Revision history for this message
Satheesh Rajendran (sathnaga) wrote :

Sure, Thanks, using the workaround to proceed.

Good if each commit goes through a automated build test across different platforms vs gcc versions.

Regards,
-Satheesh.

tags: added: compilation gcc9
Revision history for this message
Daniel Berrange (berrange) wrote :
Changed in qemu:
status: New → In Progress
Revision history for this message
Peter Maydell (pmaydell) wrote :

The fixes for this issue in dev-mtp.c are now in QEMU git master and will be in the 4.1 release.

Changed in qemu:
status: In Progress → Fix Committed
Thomas Huth (th-huth)
Changed in qemu:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.