<div dir="ltr">Hi Alexey,<div><br></div><div>That sounds good to me. RuntimeDyldMachO already has writeBytesUnaligned for this reason, though it's use is somewhat patchy. We should also make better use of the facilities provided in llvm/Support/Endian.h - it has alignment and endianness aware definitions for common primitive types.</div>
<div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 19, 2014 at 4:40 PM, Alexey Samsonov <span dir="ltr"><<a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I've noticed that certain parts of LLVM (RuntimeDyld, JIT) use unaligned memory accesses to load/store pointers or just 32- or 64-bit integers. Technically, this is undefined behavior, and UBSan reports errors when this happens. Even if we believe we're running some x86-specific code (e.g. RuntimeDyldELF::resolveX86_64Relocation) what matters for unaligned acceses in source code is the host architecture, not the target one.</div>
<div><br></div><div>What do you think of adding</div><div><br></div><div> T unaligned_load(const void *addr)</div><div> void unaligned_store(void *addr, T value);</div><div><br></div><div>to support headers? We can then provide the default memcpy implementations of these methods and, optionally, straightforward implementations for x86 hosts (and disable UBSan alignment checks for the latter).</div>
<span class="HOEnZb"><font color="#888888">
<div><br></div>-- <br><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div>
</font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>