This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Memory corruption due to word sharing
- From: DJ Delorie <dj at redhat dot com>
- To: LKML <linux-kernel at vger dot kernel dot org>
- Cc: linux-ia64 at vger dot kernel dot org, Linus Torvalds <torvalds at linux-foundation dot org>, dsterba at suse dot cz, ptesarik at suse dot cz, rguenther at suse dot de, gcc at gcc dot gnu dot org
- Date: Fri, 03 Feb 2012 01:45:42 -0500
- Subject: Re: Memory corruption due to word sharing
- References: <20120201151918.GC16714@quack.suse.cz>
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.