[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bea4697e847e4b5aa548e62e284d56ca@AcuMS.aculab.com>
Date: Tue, 23 Feb 2021 11:46:28 +0000
From: David Laight <David.Laight@...LAB.COM>
To: "'Michael J. Baars'" <mjbaars1977.gcc@...erfiber.eu>,
Andrew Pinski <pinskia@...il.com>
CC: GCC Mailing List <gcc@....gnu.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: RE: problems with memory allocation and the alignment check
> > > I just wrote this little program to demonstrate a possible flaw in both malloc and calloc.
> > >
> > > If I allocate a the simplest memory region from main(), one out of three optimization flags fail.
> > > If I allocate the same region from a function, three out of three optimization flags fail.
> > >
> > > Does someone know if this really is a flaw, and if so, is it a gcc or a kernel flaw?
> >
> > There is no flaw. GCC (kernel, glibc) all assume unaligned accesses
> > on x86 will not cause an exception.
>
> Is this just an assumption or more like a fact? I agree with you that byte aligned is more or less the
> same as unaligned.
They require that such accesses don't cause an exception.
While the misaligned accesses are slightly slower (apart from locked accesses
that cross page boundaries) the cost of avoiding them is typically higher.
This is particularly true for functions like strlen() which are often
called for short strings.
Care does have to be taken to stop strlen() reading across a page boundary.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists