lkml.org 
[lkml]   [2021]   [Feb]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: problems with memory allocation and the alignment check
On Mon, Feb 22, 2021 at 1:37 AM Michael J. Baars
<mjbaars1977.gcc@cyberfiber.eu> wrote:
>
> On Mon, 2021-02-22 at 01:29 -0800, Andrew Pinski wrote:
> > On Mon, Feb 22, 2021 at 1:17 AM Michael J. Baars
> > <mjbaars1977.gcc@cyberfiber.eu> wrote:
> > > Hi,
> > >
> > > 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.

It is an assumption that is even made inside GCC. You can modify GCC
not to assume that but you need to recompile all libraries and even
check the assembly code that is included with most programs.
Why are you enabling the alignment access check anyways? What are you
trying to do?
If you are looking into a performance issue with unaligned accesses,
may I suggest you look into perf to see if you can see unaligned
accesses?

Thanks,
Andrew

>
> >
> > Thanks,
> > Andrew
> >
> > > Regards,
> > > Mischa.
>

\
 
 \ /
  Last update: 2021-02-22 10:45    [W:0.070 / U:0.456 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site