<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW " title="NEW --- - Runtime GP fault when throwing aligned type" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23868&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=89_JV5FtsGfKFz-3otRo6vcbANihxyD53HxR6H-4fPU&s=ck2oaQSfVVaMyI8v6ztu9qAlWX7EV1mhW94TSGEQi1s&e=">23868</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Runtime GP fault when throwing aligned type
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.6
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>greg@hewgill.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I have a type that is declared with __attribute__((aligned(16))). When building
with clang on OS X on x86_64, the following code causes a GP fault when
attempting to throw a value containing this type. The fault happens because the
compiler generates a 128-bit move instruction which must be aligned on a
16-byte boundary, but the address is not correctly aligned.
Here is a program that reproduces the problem:
#include <stdint.h>
#include <stdio.h>
struct __attribute__((aligned(16))) int128 {
uint64_t w[2];
};
int main()
{
try {
int128 x;
throw x;
} catch (int128 &e) {
printf("%p %lu\n", &e, sizeof(e));
}
}
And the disassembly with the fault location marked with `->`:
a.out`main:
0x100000db0 <+0>: pushq %rbp
0x100000db1 <+1>: movq %rsp, %rbp
0x100000db4 <+4>: subq $0x40, %rsp
0x100000db8 <+8>: movl $0x10, %eax
0x100000dbd <+13>: movl %eax, %edi
0x100000dbf <+15>: callq 0x100000e8c ; symbol stub for:
__cxa_allocate_exception
0x100000dc4 <+20>: movaps -0x10(%rbp), %xmm0
-> 0x100000dc8 <+24>: movaps %xmm0, (%rax)
0x100000dcb <+27>: movq 0x23e(%rip), %rsi ; (void
*)0x0000000100001058
0x100000dd2 <+34>: xorl %ecx, %ecx
0x100000dd4 <+36>: movl %ecx, %edx
0x100000dd6 <+38>: movq %rax, %rdi
0x100000dd9 <+41>: callq 0x100000e9e ; symbol stub for:
__cxa_throw
Current register:
(lldb) register read rax
rax = 0x0000000100905b08
It looks like what is happening is the __cxa_allocate_exception function has no
knowledge of the alignment requirements of the type for which it is allocating
storage. On my system it happens to allocate an address that ends in 8, and is
therefore not 16-byte aligned. When the `movaps` instruction attempts to move
data into that memory location, the CPU faults due to unaligned access.
Compiler info (`clang` from Xcode 6.3.2):
$ clang --version
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>