<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/105997>105997</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Building openmp on Apple Silicon fails with missing symbol `___divdc3`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          keith
      </td>
    </tr>
</table>

<pre>
    This is a new issue for the same error described here https://github.com/llvm/llvm-project/issues/54596 but this is a more common use case.

The core issue is that openmp relies on `___divdc3` and `___divsc3` which when building normally on macOS implicitly come from the compiler_rt that is shipped with Xcode, you can see this by linking `libomp.dylib` and producing a map file:

```
[ 36] /Applications/Xcode-15.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.osx.a[arm64][47](divdc3.c.o)
[ 37] /Applications/Xcode-15.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.osx.a[arm64][53](divsc3.c.o)
```

When you build in the release process, the multi-stage nature of those builds is such that we do not produce a compiler rt alongside the clang that is used in thee final stage of the build, and therefore the omp link cannot implicitly pick up this library. This results in the failure.

There are a few ways to reproduce this, using the test-release script is one, but a probably easier method is to build clang as usual with cmake, making sure _not_ to build compiler rt, then point a second cmake build directory to your first clang like this:

```
CC=/Users/ksmiley/dev/llvm/llvm-project/final/Phase2/Release/llvmCore-18.1.8-final.install/usr/local/bin/clang CXX=/Users/ksmiley/dev/llvm/llvm-project/final/Phase2/Release/llvmCore-18.1.8-final.install/usr/local/bin/clang++ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;openmp" -DLLVM_ENABLE_RUNTIMES= ../llvm --fresh
```

Then run `ninja omp` and you will see this error:

```
Undefined symbols for architecture arm64:
 "___divdc3", referenced from:
      ___kmpc_atomic_cmplx8_div in kmp_atomic.cpp.o
      ___kmpc_atomic_cmplx8_div in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div_cmplx8 in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div_cmplx8 in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx8_div_cpt in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx8_div_cpt in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx10_div_cpt in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx10_div_cpt in kmp_atomic.cpp.o
      ...
 "___divsc3", referenced from:
      ___kmpc_atomic_cmplx4_div in kmp_atomic.cpp.o
      ___kmpc_atomic_cmplx4_div in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div_cpt in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div_cpt in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div_cpt in kmp_atomic.cpp.o
 ___kmpc_atomic_cmplx4_div_cpt in kmp_atomic.cpp.o
 ...
```

I verified that the fix referenced in the other issue https://github.com/llvm/llvm-project/pull/83767 does fix this issue @ HEAD. This still repros @ [HEAD](https://github.com/llvm/llvm-project/commit/33f3ebc86e7d3afcb65c551feba5bbc2421b42ed) today.

This blocks producing macOS arm64 release binaries that include openmp.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV91z2rgW_2vEyxk8tozBPPAQINzbe9OPaZPd7pNHlo-xiix5JDmE_35HsoFMttudtrudLpPgxDrf-p0vZq3YK8QVydYk205Y7xptVgcUrpmUujqt7hthQVhgoPAIwtoeodYGXINgWYuAxmgDFVpuRIkVNGgQGuc6S9IbQneE7vbCNX0Zcd0SupPy8fyYdkZ_Qu4I3QXBltBdNsuWcyh7B-6iudUGgeu21Qp6i8CZxYjEWxLfDN_3jT83ONonLLiGOdAdqrYDg1KgBa2Az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