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

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 06:54:18 PDT 2016


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.


More information about the llvm-commits mailing list