From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id CE2253870841 for ; Tue, 9 Jun 2020 09:39:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CE2253870841 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-285-zEo4lSfFOL2CyCdebaJ7Kg-1; Tue, 09 Jun 2020 05:39:02 -0400 X-MC-Unique: zEo4lSfFOL2CyCdebaJ7Kg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22C33107ACF2; Tue, 9 Jun 2020 09:39:01 +0000 (UTC) Received: from zarquon.pink (unknown [10.33.36.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CDCD6116D; Tue, 9 Jun 2020 09:38:59 +0000 (UTC) To: Lars Poeschel , Oleg Endo Cc: gcc-help@gcc.gnu.org References: <20200608133411.uwe4c4nt2h4zvnjq@lem-wkst-02.lemonage> <6a8fdf1e93248a8d0c3e651d5bf76ad08aaee15b.camel@t-online.de> <20200609080509.dbgs7zizqw7cajvq@lem-wkst-02.lemonage> From: Andrew Haley Autocrypt: addr=aph@redhat.com; prefer-encrypt=mutual; keydata= mQENBEoRZWsBCACUiFkb5YgfOfTHmzkESkfmTri14VX9UKdv4TUu9l9S6gFKf56ihWChiG8H pQ6CDTb5uqtZCWBNXoqcC2uCR0SCnWGk46tAW9dO0roEjoP+6AgbY4V5xUZt963XONYu1gnN EDQPB1QKN5L3PCMn0Dwnl1F6Of5BMPc+ErXr2BuMAG5Rb9QJPuWEjP4rMJdQIxeVkSk7oTnm rQJnDPF3WPimgwtaDGC17lZLwt4U9az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kbXlqhPbA7giKVQ4I6CfCbYEL9U454gr4gIQ3IMgKQlxYaxAD6EwQk JzMUSAu0kLTjX6e35FHdWmf2VHR6NbyuV5O/yzf/3iNallmocZIK5I0zY5ndbptd4vEWX4Kd R6d5D1AZrsnlLoFkIPR0WZfzfPtwiW6WVm6upSOQXEEA4YH3sNEFyywihqbp88Fx7BRKRtIS 27/FmbZjZ70N1rA99ld8cGmMha+ylFs4gBmDIpvKFLxlCiZFH7qEnyv4b73q Subject: Re: Unexpected unaligned access on arm Message-ID: <427c76eb-f080-601b-fbc9-66d9e8e47a67@redhat.com> Date: Tue, 9 Jun 2020 10:38:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200609080509.dbgs7zizqw7cajvq@lem-wkst-02.lemonage> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Jun 2020 09:39:07 -0000 On 09/06/2020 09:05, Lars Poeschel wrote: > On Mon, Jun 08, 2020 at 10:49:22PM +0900, Oleg Endo wrote: >> On Mon, 2020-06-08 at 15:34 +0200, Lars Poeschel wrote: >>> >>> What am I missing ? What am I doing wrong ? >>> >> >> You're casting an address of some byte array to a point to struct, >> which has an alignment > 1 byte. Try adding a #pragma pack (1) or >> respective attribute. > > Thank you! The pragma does indeed the right thing. gcc now produces > code, that accesses the fields in question individually. > But shouldn't the option > -mno-unaligned-access > I use for compiling also do the same ? No. '-munaligned-access' '-mno-unaligned-access' Enables (or disables) reading and writing of 16- and 32- bit values from addresses that are not 16- or 32- bit aligned. By default unaligned access is disabled for all pre-ARMv6, all ARMv6-M and for ARMv8-M Baseline architectures, and enabled for all other architectures. If unaligned access is not enabled then words in -mno-unaligned-access tells the compiler not to generate accesses to unaligned words. In this test case, the compiler didn't generate the unaligned access, *you* did. You did this by casting the address of an unaligned byte array to the address of a struct. If you take the address of a struct, cast it to a char*, then cast it back to a pointer to the struct type, that'll work. Likewise if you cast the result of malloc() to any struct pointer. If you lie to the compiler, it will get its revenge. - Henry Spencer -- Andrew Haley (he/him) Java Platform Lead Engineer Red Hat UK Ltd. https://keybase.io/andrewhaley EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671