<div dir="ltr">> <span style="font-size:12.8px">If "UNALIGNED" is coming from</span><div>> <a href="https://github.com/dotnet/coreclr/blob/775003/src/pal/src/safecrt/cruntime.h" rel="noreferrer" target="_blank" style="font-size:12.8px">https://github.com/dotnet/coreclr/blob/775003/src/pal/src/safecrt/cruntime.h</a><br><br>I have thought that the "UNALIGNED"  is coming from <a href="https://github.com/dotnet/coreclr/blob/master/src/pal/inc/pal.h">https://github.com/dotnet/coreclr/blob/master/src/pal/inc/pal.h</a> (L194 ~ L206). <br>I will also check the difference between cruntime.h and pal.h. Thank you for your comment. <br><br>> <span style="font-size:12.8px">instead you need a typedef:</span><br style="font-size:12.8px"><span style="font-size:12.8px">>   typedef int __atribute__((aligned(1))) unaligned_int;</span><br style="font-size:12.8px"><span style="font-size:12.8px">>   *(unaligned_int *)ptr = 2; // Works</span><br><br>Really? Does the latest clang/llvm version also  ignore the below attribute that you commented?<br><span style="font-size:12.8px">*(int __attribute__((aligned(1))) *)ptr = 2; // Wrong, attribute ignored</span><br style="font-size:12.8px"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 11, 2016 at 10:54 PM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 11 July 2016 at 05:32, Geunsik Lim <<a href="mailto:leemgs@gmail.com">leemgs@gmail.com</a>> wrote:<br>
> However, I am not sure that this patch is appropriate solution to fix<br>
> this issue because I have used memcpy() call.<br>
<br>
</span>memcpy is the ideal portable solution to this kind of issue. But it<br>
looks like the issue is far more pervasive than that.<br>
<br>
If "UNALIGNED" is coming from<br>
<a href="https://github.com/dotnet/coreclr/blob/775003/src/pal/src/safecrt/cruntime.h" rel="noreferrer" target="_blank">https://github.com/dotnet/coreclr/blob/775003/src/pal/src/safecrt/cruntime.h</a><br>
then it looks like it's just completely ignored (to silently fail as<br>
you've seen) on anything that's not x86_64 (or Itanium, yay!).<br>
<br>
Clang doesn't have an attribute that's used like that though. For<br>
reasons I don't quite know (probably legacy GCC compatibility) this<br>
doesn't work:<br>
<br>
   *(int __attribute__((aligned(1))) *)ptr = 2; // Wrong, attribute ignored<br>
<br>
instead you need a typedef:<br>
<br>
   typedef int __atribute__((aligned(1))) unaligned_int;<br>
   *(unaligned_int *)ptr = 2; // Works<br>
<br>
So I think you'll need some more aggressive refactoring to remove uses<br>
of UNALIGNED like that in coreclr, otherwise the bug is likely to just<br>
come back later.<br>
<span class=""><br>
> And, why we can not resolve this issue with just -mno-unaligned-access"<br>
> compiler flag + -O3 using clang/llvm?<br>
<br>
</span>-mno-unaligned-access tells LLVM to split up accesses that it doesn't<br>
know are aligned. But the code here (with an ignored UNALIGNED)<br>
doesn't indicate that anything is wrong, so LLVM still thinks the<br>
usual rules for alignment apply; and that means that any pointer used<br>
as an __int64* must be 8-byte aligned (on ARM Linux).<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><a href="http://leemgs.fedorapeople.org" style="font-family:Tahoma" target="_blank">http://leemgs.fedorapeople.org</a><span style="font-family:Tahoma"> </span></div><div>Don't try to avoid pain if you fail.<br>If you decided to face the challenges in life, <br>you can gain a lot by giving your best.<br>Cheolsang Jeong's Book & life<br>--<br></div></div></div>
</div>