Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755240AbXKXRfg (ORCPT ); Sat, 24 Nov 2007 12:35:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752892AbXKXRf3 (ORCPT ); Sat, 24 Nov 2007 12:35:29 -0500 Received: from gateway.drzeus.cx ([85.8.24.16]:47357 "EHLO smtp.drzeus.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752550AbXKXRf2 (ORCPT ); Sat, 24 Nov 2007 12:35:28 -0500 Date: Sat, 24 Nov 2007 18:35:25 +0100 From: Pierre Ossman To: Luciano Rocha Cc: Daniel Drake , linux-kernel@vger.kernel.org, davem@davemloft.net, kune@deine-taler.de, johannes@sipsolutions.net Subject: Re: [RFC] Documentation about unaligned memory access Message-ID: <20071124183525.13c41374@poseidon.drzeus.cx> In-Reply-To: <20071124172236.GA16944@bit.office.eurotux.com> References: <20071123001554.12F8B9D4A1F@zog.reactivated.net> <20071124143441.41657307@poseidon.drzeus.cx> <20071124155052.GA15440@bit.office.eurotux.com> <20071124171931.699aa1ff@poseidon.drzeus.cx> <20071124172236.GA16944@bit.office.eurotux.com> X-Mailer: Claws Mail 3.1.0 (GTK+ 2.12.1; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1638 Lines: 29 On Sat, 24 Nov 2007 17:22:36 +0000 Luciano Rocha wrote: > On Sat, Nov 24, 2007 at 05:19:31PM +0100, Pierre Ossman wrote: > > It most certainly does not. gcc will assume that an int* has int alignment. memcpy() is a builtin, which gcc can translate to pretty much anything. And C specifies that a pointer to foo, will point to a real object of type foo, so gcc can't be blamed for the unsafe typecasts. I have tested this the hard way, so this is not just speculation. > > Yes, on *int and other assumed aligned pointers, gcc uses its internal > version. > > However, my point is that those pointers, unless speaking of packed > structures, can safely be assumed aligned, while char*/void* can't. > I get the sensation we're violently in agreement here, just misunderstanding each other. :) _My_ point was that the documentation should mention that normal, unpacked C objects have alignments that influence the code generated by __builtin_memcpy(). As such, one should always make sure to have either src or dst be char*/void* when alignment cannot be guaranteed. The example in the documentation has this, but it isn't explicit that this is required. Rgds -- -- Pierre Ossman Linux kernel, MMC maintainer http://www.kernel.org PulseAudio, core developer http://pulseaudio.org rdesktop, core developer http://www.rdesktop.org - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/