lkml.org 
[lkml]   [2012]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Memory corruption due to word sharing
On Fri, Feb 03, 2012 at 09:37:22AM +0000, Richard Guenther wrote:
> On Fri, 3 Feb 2012, DJ Delorie wrote:
>
> >
> > Jan Kara <jack@suse.cz> writes:
> > > we've spotted the following mismatch between what kernel folks expect
> > > from a compiler and what GCC really does, resulting in memory corruption on
> > > some architectures. Consider the following structure:
> > > struct x {
> > > long a;
> > > unsigned int b1;
> > > unsigned int b2:1;
> > > };
> >
> > If this structure were volatile, you could try
> > -fstrict-volatile-bitfields, which forces GCC to use the C type to
> > define the access width, instead of doing whatever it thinks is optimal.
> >
> > Note: that flag is enabled by default for some targets already, most
> > notably ARM.
>
> Note that -fstrict-volatile-bitfields does not work for
>
> volatile struct S {
> int i : 1;
> char c;
> } s;
> int main()
> {
> s.i = 1;
> s.c = 2;
> }
>
> where it accesses s.i using SImode. -fstrict-volatile-bitfields
> falls foul of all the games bitfield layout plays and the
> irrelevantness of the declared bitfield type (but maybe the
> ARM ABI exactly specifies it that way).

Indeed the ARM ABI does - see Section 7.1.7.5 of the PCS available at:

http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042-/

In fact the example above is pretty much the same as that given in the ABI
docs, and it says that accessing s.i will also cause an access
to s.c, but not vice-versa.

Thanks,

Matt

--
Matthew Gretton-Dann
Principal Engineer, PD Software, ARM Ltd.



\
 
 \ /
  Last update: 2012-02-03 11:05    [W:0.094 / U:0.832 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site