From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 79562 invoked by alias); 19 Aug 2019 13:57:10 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 79544 invoked by uid 89); 19 Aug 2019 13:57:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.1 spammy=H*Ad:U*markus, HTo:U*markus, accesses, increases X-HELO: resqmta-po-06v.sys.comcast.net Received: from resqmta-po-06v.sys.comcast.net (HELO resqmta-po-06v.sys.comcast.net) (96.114.154.165) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Aug 2019 13:57:08 +0000 Received: from resomta-po-15v.sys.comcast.net ([96.114.154.239]) by resqmta-po-06v.sys.comcast.net with ESMTP id zhiWhYeRGuvPDzi9ihIZqm; Mon, 19 Aug 2019 13:57:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1566223026; bh=mRXAEvmsprUrPu37gL919Z5nATRz7g7S/YLJw+W//6o=; h=Received:Received:Content-Type:Mime-Version:Subject:From:Date: Message-Id:To; b=4Ne8U3P6q88OM2/v+/LgcbH2dsjGBIyBCszFardoOjWlkMvEsBpjPK1q3jIytMHoH mwZy2n0t2Jch/4fndHVTRzaBYTiwvycJHb4UfxuLBt4EVvp8eabHuVt0NrKzSrs9cr fkJH8C/CTyzjGHlBzidaQ4fNiEcoYxQkXzy7dShPSfSbJwtlsx/9cnmG6QzqjPK0Vv 2+Yk4uPYVqdmChOnRkA/KDNHNxBLH0CqLaAZ+/A5sVPxNkTIjRJ7r0FT8YP5nR93s3 p/S6v+wARkNnKmR9XwHriImpApjienX3GlMRhf3O0m8Fk17+4AexJXkzDZSXpzb7Iv llndgWtId8IPA== Received: from pkoning.akdesign.com ([73.60.223.101]) by resomta-po-15v.sys.comcast.net with ESMTPA id zi9ghgGnZj1PQzi9hhlv0r; Mon, 19 Aug 2019 13:57:06 +0000 X-Xfinity-VAAS: gggruggvucftvghtrhhoucdtuddrgeduvddrudefledgjeduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuvehomhgtrghsthdqtfgvshhipdfqfgfvpdfpqffurfetoffkrfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurheptggguffhjgffgffkfhfvofesthhqmhdthhdtjeenucfhrhhomheprfgruhhlucfmohhnihhnghcuoehprghulhhkohhnihhnghestghomhgtrghsthdrnhgvtheqnecukfhppeejfedriedtrddvvdefrddutddunecurfgrrhgrmhephhgvlhhopehpkhhonhhinhhgrdgrkhguvghsihhgnhdrtghomhdpihhnvghtpeejfedriedtrddvvdefrddutddupdhmrghilhhfrhhomhepphgruhhlkhhonhhinhhgsegtohhmtggrshhtrdhnvghtpdhrtghpthhtohepmhgrrhhkuhhssehmuhgsfhdruggvpdhrtghpthhtohepghgttgesghgttgdrghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedt X-Xfinity-VMeta: sc=-100;st=legit Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: asking for __attribute__((aligned()) clarification From: Paul Koning In-Reply-To: Date: Mon, 19 Aug 2019 13:57:00 -0000 Cc: gcc@gcc.gnu.org Content-Transfer-Encoding: quoted-printable Message-Id: <1E465204-0887-49CB-8472-196EDE7AAE81@comcast.net> References: To: =?utf-8?Q?Markus_Fr=C3=B6schle?= X-SW-Source: 2019-08/txt/msg00136.txt.bz2 > On Aug 19, 2019, at 8:46 AM, Markus Fr=C3=B6schle wrote: >=20 > All, >=20 > this is my first post on these lists, so please bear with me. >=20 > My question is about gcc's __attribute__((aligned()). Please consider the= following code: >=20 > #include >=20 > typedef uint32_t uuint32_t __attribute__((aligned(1))); >=20 > uint32_t getuuint32(uint8_t p[]) { > return *(uuint32_t*)p; > } >=20 > This is meant to prevent gcc to produce hard faults/address errors on arc= hitectures that do not support unaligned access to shorts/ints (e.g some AR= Ms, some m68k). On these architectures, gcc is supposed to replace the 32 b= it access with a series of 8 or 16 bit accesses. >=20 > I originally came from gcc 4.6.4 (yes, pretty old) where this did not wor= k and gcc does not respect the aligned(1) attribute for its code generation= (i.e. it generates a 'normal' pointer dereference, consequently crashing w= hen the code executes). To be fair, it is my understanding that the gcc man= uals never promised this *would* work. That has never been my understanding. I've always read the manual to say t= hat "aligned" only INCREASES the alignment. The normal alignment is that s= pecified by the ABI for the given data type (often, but not always, the siz= e of the primitive type) -- or it is 1 for "packed". So I use __attribute__ ((packed)) to request byte alignment, and, say, __at= tribute__ ((packed, aligned(2))) to specify alignment to 2 byte multiples. paul