mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michael J. Baars" <mjbaars1977.gcc@cyberfiber.eu>
To: Andrew Pinski <pinskia@gmail.com>
Cc: GCC Mailing List <gcc@gcc.gnu.org>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: problems with memory allocation and the alignment check
Date: Mon, 22 Feb 2021 11:04:40 +0100	[thread overview]
Message-ID: <64755104869ec3af730db147b5eccb5da4b78b74.camel@cyberfiber.eu> (raw)
In-Reply-To: <CA+=Sn1kR6jV2j2cOLhC-GBDS_NSxsw0m=K+VghBmqBSB4c2gqw@mail.gmail.com>

On Mon, 2021-02-22 at 01:41 -0800, Andrew Pinski wrote:
> 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?

I'm writing an algorithm to compress and encrypt data for use in cluster computing. While trying to verify my own code, I stumbled upon this. Just like that...

And yes, as always performance certainly is an issue :) Correctness of the code even more.

> 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?

So it's more like a joke than a flaw? I noticed it earlier with printf too, and traced it back to the strlen kernel assembly code where a lot of sse code is
used that expects memory to be aligned at the 16 byte boundary. Most character strings that come with printf as an argument, apparently aren't.

I'll have a look at perf.

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




  reply	other threads:[~2021-02-22 10:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22  9:08 Michael J. Baars
2021-02-22  9:29 ` Andrew Pinski
2021-02-22  9:37   ` Michael J. Baars
2021-02-22  9:41     ` Andrew Pinski
2021-02-22 10:04       ` Michael J. Baars [this message]
2021-02-24  7:05       ` Michael J. Baars
2021-02-23 11:46     ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64755104869ec3af730db147b5eccb5da4b78b74.camel@cyberfiber.eu \
    --to=mjbaars1977.gcc@cyberfiber.eu \
    --cc=gcc@gcc.gnu.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pinskia@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®