<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54517>54517</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[compiler-rt] BUG: `COMPILER_RT_STANDALONE_BUILD` still builds libcxx, fails in various ways
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
h-vetinari
</td>
</tr>
</table>
<pre>
To package the LLVM stack for conda-forge, we tend to build the pieces one by one, to not carry around huge artefacts for projects that only depend on specific things.
As such, we were building from the `compiler-rt.src.tar.xz` sources directly until LLVM 13, but this broke with #53281. Since we were stuck resp. waiting for the fix for this for a while, the following report unfortunately didn't make it during the rc-phase.
We're now [looking](https://github.com/conda-forge/compiler-rt-feedstock/pull/38) to build from the full `llvm-project.src.tar.xz`, but still only building compiler-rt, therefore setting `COMPILER_RT_STANDALONE_BUILD`.
On linux-x86-64, and linux-aarh64, this [runs into](https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=479982&view=results) the first problem that the standalone build still tries to rebuild parts of libcxx (which fails for various reasons not directly relevant here). After studying [`compiler-rt/CMakeLists.txt`](https://github.com/llvm/llvm-project/blame/llvmorg-14.0.0/compiler-rt/CMakeLists.txt), I then added
```
export CMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS -stdlib=libcxx"
```
to make [sure](https://github.com/llvm/llvm-project/blame/llvmorg-14.0.0/compiler-rt/CMakeLists.txt#L178-L181) we use the already-built `libcxx`. This didn't have any effect, so after further searching, I added the (IMO confusingly named; I still want to _use_ it, just not _build_ it)
```
-DCOMPILER_RT_USE_LIBCXX=OFF
```
in order to [really](https://github.com/llvm/llvm-project/blame/llvmorg-14.0.0/compiler-rt/CMakeLists.txt#L607-L608) not rebuild `libcxx`.
Interestingly, this made the failure [go away](https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=480029&view=results) on aarch, but on x86-64, it surfaced the following build error, which I presume is a missing header since perhaps no-one is building `compiler-rt` fully stand-alone in CI or for the release-preparation...?
```
[ 57%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.x86_64.dir/sanitizer_platform_limits_posix.cpp.o
cd $SRC_DIR/build/lib/sanitizer_common && $BUILD_PREFIX/bin/x86_64-conda-linux-gnu-c++ -DHAVE_RPC_XDR_H=1 -I$SRC_DIR/compiler-rt/lib/sanitizer_common/.. -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem $PREFIX/include -fdebug-prefix-map=$SRC_DIR=/usr/local/src/conda/compiler-rt-packages-14.0.0.rc4 -fdebug-prefix-map=$PREFIX=/usr/local/src/conda-prefix -D__STDC_FORMAT_MACROS=1 -Wall -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG -m64 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-lto -O3 -g -Wno-variadic-macros -nostdinc++ -Wno-format -fno-rtti -Wframe-larger-than=570 -MD -MT lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.x86_64.dir/sanitizer_platform_limits_posix.cpp.o -MF CMakeFiles/RTSanitizerCommonNoTermination.x86_64.dir/sanitizer_platform_limits_posix.cpp.o.d -o CMakeFiles/RTSanitizerCommonNoTermination.x86_64.dir/sanitizer_platform_limits_posix.cpp.o -c $SRC_DIR/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
cc1: warning: command-line option '-nostdinc++' is valid for C++/ObjC++ but not for C
/home/conda/feedstock_root/build_artifacts/compiler-rt-packages_1648085029499/work/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp: In function 'unsigned int __sanitizer::ucontext_t_sz(void*)':
/home/conda/feedstock_root/build_artifacts/compiler-rt-packages_1648085029499/work/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp:227:26: error: 'FP_XSTATE_MAGIC1' was not declared in this scope
227 | if (after_xmm[12] == FP_XSTATE_MAGIC1)
| ^~~~~~~~~~~~~~~~
```
I ended up digging a bit further still and added `COMPILER_RT_HAS_LIBCXX` as well as `HAS_LIBCXX` which are used [here](https://github.com/llvm/llvm-project/blob/llvmorg-14.0.0/compiler-rt/CMakeLists.txt#L521) and [here](https://github.com/llvm/llvm-project/blob/llvmorg-14.0.0/compiler-rt/lib/fuzzer/CMakeLists.txt#L67), though I didn't expect much improvement. This then breaks with several errors of the kind:
```
CMake Error at cmake/Modules/AddCompilerRT.cmake:71 (add_dependencies):
The dependency target "cxx-headers" of target "RTXray.x86_64" does not
exist.
```
Finally removing `HAS_LIBCXX` again runs into the same error (with `FP_XSTATE_MAGIC1`) as above.
Long story short, in my opinion `COMPILER_RT_STANDALONE_BUILD` alone should set all the necessary flags etc. to make sure that things like libcxx are being picked up correctly (perhaps error if not found or the already existing `COMPILER_RT_LIBCXX_PATH` is not set), and not need further CMake entrail reading (it's possible that we need to add `LIBCXX_INSTALL_HEADERS` to our `libcxx` builds to get the `cxx-headers` target, but it's bizarre to me that it only fails on one OS/platform combination).
PS. A similar line of thought [affects](https://github.com/llvm/llvm-project/blame/llvmorg-14.0.0/compiler-rt/CMakeLists.txt#L662-L671) `lit` which IMO really shouldn't be rebuilt if `LLVM_EXTERNAL_LIT` is set.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVWFtz4jgW_jXkRWUXmPtDHgiXbmpJJ0Xonry5hC2DJsZySTKE_vX7HcmmQyazszM101vbRQcsydLRd75z3ar0fLtRrOTJC98JZveCrVbf7pmxGGGZ0ixRRcoD_NqJVjRlJywSRcqsYttK5ql7pZQiEYapQrDtmb5oJVYUyrKEa31mXKsKb-0rHMK1FRlPrHH7l1r9KujB7rnFu_mZpaKkI1TBTCkSmckEk7LYmbDVnrXaE_93Ypipkn0t1Elo4SXCQpZp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