From: Heinrich Schuchardt Date: Tue, 17 Dec 2019 12:14:00 +0100 Subject: [PATCH 1/1] usb: avoid -Werror=address-of-packed-member In-Reply-To: <3c515d67-67f8-e4d0-7937-ef52b7913320@denx.de> References: <20191217092754.31710-1-xypron.glpk@gmx.de> <3c515d67-67f8-e4d0-7937-ef52b7913320@denx.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 12/17/19 11:00 AM, Marek Vasut wrote: > On 12/17/19 10:27 AM, Heinrich Schuchardt wrote: >> With GCC 9.2.1 errors of type -Werror=address-of-packed-member occur when >> passing a member of a packed structure to le16_to_cpus() on a big endian >> system (e.g. P2041RDB_defconfig). >> >> Replace le16_to_cpus() by get_unaligned_le16(). Check defined(__BIG_ENDIAN) >> to avoid the introduction of unnecessary instructions on little endian >> systems as seen on aarch64. > > I would expect the compiler would optimize such stuff out ? > Can we do without the ifdef ? When compiling qemu_arm64_defconfig without the #ifdef the GCC 9.2.1 adds assembler instructions: /* correct le values */ dev->descriptor.bcdUSB = 48: 79020660 strh w0, [x19, #258] 4c: 39442660 ldrb w0, [x19, #265] 50: 2a002020 orr w0, w1, w0, lsl #8 54: 39442a61 ldrb w1, [x19, #266] get_unaligned_le16(&dev->descriptor.bcdUSB); dev->descriptor.idVendor = 58: 79021260 strh w0, [x19, #264] 5c: 39442e60 ldrb w0, [x19, #267] 60: 2a002020 orr w0, w1, w0, lsl #8 64: 39443261 ldrb w1, [x19, #268] get_unaligned_le16(&dev->descriptor.idVendor); dev->descriptor.idProduct = 68: 79021660 strh w0, [x19, #266] 6c: 39443660 ldrb w0, [x19, #269] 70: 2a002020 orr w0, w1, w0, lsl #8 get_unaligned_le16(&dev->descriptor.idProduct); dev->descriptor.bcdDevice = 74: 79021a60 strh w0, [x19, #268] udelay(1000 * msec); 78: d2807d00 mov x0, #0x3e8 // #1000 7c: 94000000 bl 0 * one microframe duration here (1mS for USB 1.x , 125uS for USB 2.0). */ mdelay(1); Best regards Heinrich