Linux/ARM: Bus error with -O3 flag of clang/llvm-3.6 while running unit-test of .NET Core

Geunsik Lim via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 17:21:26 PDT 2016


> If "UNALIGNED" is coming from
>
https://github.com/dotnet/coreclr/blob/775003/src/pal/src/safecrt/cruntime.h

I have thought that the "UNALIGNED"  is coming from
https://github.com/dotnet/coreclr/blob/master/src/pal/inc/pal.h (L194 ~
L206).
I will also check the difference between cruntime.h and pal.h. Thank you
for your comment.

> instead you need a typedef:
>   typedef int __atribute__((aligned(1))) unaligned_int;
>   *(unaligned_int *)ptr = 2; // Works

Really? Does the latest clang/llvm version also  ignore the below attribute
that you commented?
*(int __attribute__((aligned(1))) *)ptr = 2; // Wrong, attribute ignored


On Mon, Jul 11, 2016 at 10:54 PM, Tim Northover <t.p.northover at gmail.com>
wrote:

> On 11 July 2016 at 05:32, Geunsik Lim <leemgs at gmail.com> wrote:
> > However, I am not sure that this patch is appropriate solution to fix
> > this issue because I have used memcpy() call.
>
> memcpy is the ideal portable solution to this kind of issue. But it
> looks like the issue is far more pervasive than that.
>
> If "UNALIGNED" is coming from
>
> https://github.com/dotnet/coreclr/blob/775003/src/pal/src/safecrt/cruntime.h
> then it looks like it's just completely ignored (to silently fail as
> you've seen) on anything that's not x86_64 (or Itanium, yay!).
>
> Clang doesn't have an attribute that's used like that though. For
> reasons I don't quite know (probably legacy GCC compatibility) this
> doesn't work:
>
>    *(int __attribute__((aligned(1))) *)ptr = 2; // Wrong, attribute ignored
>
> instead you need a typedef:
>
>    typedef int __atribute__((aligned(1))) unaligned_int;
>    *(unaligned_int *)ptr = 2; // Works
>
> So I think you'll need some more aggressive refactoring to remove uses
> of UNALIGNED like that in coreclr, otherwise the bug is likely to just
> come back later.
>
> > And, why we can not resolve this issue with just -mno-unaligned-access"
> > compiler flag + -O3 using clang/llvm?
>
> -mno-unaligned-access tells LLVM to split up accesses that it doesn't
> know are aligned. But the code here (with an ignored UNALIGNED)
> doesn't indicate that anything is wrong, so LLVM still thinks the
> usual rules for alignment apply; and that means that any pointer used
> as an __int64* must be 8-byte aligned (on ARM Linux).
>
> Tim.
>



-- 
http://leemgs.fedorapeople.org
Don't try to avoid pain if you fail.
If you decided to face the challenges in life,
you can gain a lot by giving your best.
Cheolsang Jeong's Book & life
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160712/08607611/attachment.html>


More information about the llvm-commits mailing list