Friday, November 29, 2019

Re: SIGBUS on octeon for my program

Be warned that __packed doesn't do quite what you think it does.

void func(int *p) {
*p = 0;
}

If you pass an unaligned pointer into this function on a strict-alignment
platform, your program will likely crash. I am unaware of any attribute
that can inform the compiler that 'p' may be misaligned.

--david

On Fri, Nov 29, 2019 at 2:54 AM Peter J. Philipp <pjp@centroid.eu> wrote:

> On Thu, Nov 28, 2019 at 11:44:07PM -0700, Theo de Raadt wrote:
> > Half the cpu platforms fault on unaligned access.
> >
> > There are strategies for handling this. Your code must use them.
> >
> > It is kind of boring, actually.
>
> I took a look at how libasr does it, and I have similar code ie. pack8(),
> pack16(), pack32(), I will just change all my functions, as unalignment
> flags passed per -m aren't standard on every arch. I did use __packed on
> structs already but the way libasr does is a great example I think.
>
> It's a bit of work but the fact that this could work on architectures like
> octeon make it worth it for me.
>
> Thanks a lot!
> -peter
>
>

No comments:

Post a Comment