<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61682>61682</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
OpenMP segfault on macOS arm64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
adamjstewart
</td>
</tr>
</table>
<pre>
I'm trying to build PyTorch with OpenMP support using LLVM's OpenMP subproject. Although the build completes successfully, the resulting installation crashes with a segfault whenever it tries to use OpenMP:
```console
$ lldb python
(lldb) target create "python"
Current executable set to 'python' (arm64).
(lldb) r test.py
Process 35943 launched: '/Users/ajstewart/.spack/.spack-env/view/bin/python' (arm64)
Process 35943 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
frame #0: 0x0000000102c807b0 libomp.dylib`__kmp_get_global_thread_id + 356
libomp.dylib`:
-> 0x102c807b0 <+356>: ldr w8, [x9, #0x10]
0x102c807b4 <+360>: cbz w8, 0x102c80834 ; <+488>
0x102c807b8 <+364>: mov w8, w19
0x102c807bc <+368>: ldr x10, [x9]
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
* frame #0: 0x0000000102c807b0 libomp.dylib`__kmp_get_global_thread_id + 356
frame #1: 0x0000000102cb2e9c libomp.dylib`__kmp_release_64 + 48
frame #2: 0x0000000102c8df64 libomp.dylib`__kmp_reap_thread(kmp_info*, int) + 168
frame #3: 0x0000000102c8b7a0 libomp.dylib`__kmp_internal_end() + 288
frame #4: 0x0000000102c8b5b8 libomp.dylib`__kmp_internal_end_library + 592
frame #5: 0x00000001b5857dd0 libsystem_c.dylib`__cxa_finalize_ranges + 464
frame #6: 0x00000001b5857b74 libsystem_c.dylib`exit + 44
frame #7: 0x00000001b5978ec4 libdyld.dylib`dyld4::LibSystemHelpers::exit(int) const + 20
frame #8: 0x00000001000110d8 dyld`start + 596
```
I've managed to reproduce this on macOS 12.4 and 13.2.1 on both M1 and M2 CPUs. The issue does not occur for me on x86_64, only arm64. I've also managed to reproduce the issue with LLVM OpenMP 12.0.1, 14.0.6, and 16.0.0. Steps to reproduce can be found at https://github.com/pytorch/pytorch/issues/80805. Also opened a discussion about this here: https://discourse.llvm.org/t/69449.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMls9u4zYQxp-GvgwiUNQfUwcfHDtGC2ywAbJb9CaQ0tjiLkWqJJXE-_QFZcvZJN72VKCCAUvU8DcfPxKaEd6rg0FckeKWFNuFGENn3Uq0ov_mAz4LFxbStsfV74QtewjuqMwBggU5Kt3Cw_GLdU0Hzyp08HlAc_8AfhwG6wKMPoZ--vTHPWFL__pWDs5-wyYksNahs-Ohg9DhGdjYftAY0IMfmwa9349aHwnbTDEO_ahDxCrjg9BaBGUNNE74Dv1JhQCPh70YdYDnDg0-oQMVIDiFPgofPZ61kGxN6JbQNSnp6ddY463G8yjLQetWwnAMnTXzII9jhFUQhDtggMahCAiEsXMcY6fQzegcmgD4gs0YhNQIHkOUQNhyjl0CYVy4vswJq5IPORwE9CEZjqc3D85GTyArqjwDLUbTdNiSbB2RhO2-enSesJ2Y946wXeIH0Xy_3NygeSJs96TwmbCdVIaw3VUx1zL6YIcB21nmGkLnULRAWJbGPfprxBGBZNuop7F9IoZBY9ILZW5OoZPOzQQCh8JbM4Xf_bmpb9fber3Z3D0-RhmNbZFk2wkr2tah9yTb0peUXrQBAOyd6KP5GY0u0Bd6ulLKGk6XkoJW0vZD0h61kqSkdf29H-oDhvqgrRS6PsmqVVzELWRFeWK_m3Y5Kjcku4OoYuaTbEPYbZyX3UUJunVR1zOPwklx-1JNNyybpBfbV-mvlHymxEQTpZE_zog5imc5vF4kuz3PyTmPc65Q-YWan6m9fXrV9pxW12Y1l1n87Yom5-clzev46ajK8L85FlHCf3Uw3hy69ANbMqya62yHGoXHuswnYs6vANl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