<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/90810>90810</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[packaging] clang-18 from apt.llvm.org on Ubuntu 23.10 mantic fails to build using pthread when LTO is enabled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
illwieckz
</td>
</tr>
</table>
<pre>
When I build the [Daemon game engine](https://github.com/DaemonEngine/Daemon) with Clang 18 from https://apt.llvm.org On Ubuntu 23.10 mantis and enable LTO, the configuration fails at the pthread detection step. It works with Clang 18 if I disable LTO. It also works with Clang 17 and 19 if I enable or disable LTO.
|Clang 17|Clang 18|Clang 19
-|-|-|-
LTO ON|✅️ ok|❌️ ko|✅️ ok
LTO OFF|✅️ ok|✅️ ok|✅️ ok
The reported Clang is `18.1.3`.
As a side note, I noticed that with Intel ICX `2024.1` which is based on Clang `18.0.0` I can configure and build with LTO enabled.
## Environment
```
$ dpkg -l clang-18 | grep -E '^ii'
ii clang-18 1:18.1.3~++20240322073236+ef6d1ec07c69-1~exp1~20240322193248.98 amd64 C, C++ and Objective-C compiler
$ clang-18 -v 2>&1 | head -n1
Ubuntu clang version 18.1.3 (++20240322073236+ef6d1ec07c69-1~exp1~20240322193248.98)
$ lsb_release -irc
Distributor ID: Ubuntu
Release: 23.10
Codename: mantic
```
## How to reproduce
```sh
git clone -b 'unvanquished/0.54.1' --recurse-submodules 'https://github.com/DaemonEngine/Daemon.git'
cd Daemon
mkdir build
cd build
cmake .. -D'CMAKE_C_COMPILER'='clang-18' -D'CMAKE_CXX_COMPILER'='clang++-18' -D'USE_LTO'='ON'
```
## Some logs
Here is an excerpt of the log, including the error:
```
$ rm -f CMakeCache.txt
$ cmake .. -D'CMAKE_C_COMPILER'='clang-18' -D'CMAKE_CXX_COMPILER'='clang'++-18' -D'USE_LTO'='ON'
-- The C compiler identification is Clang 18.1.3
-- The CXX compiler identification is Clang 18.1.3
…
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
CMake Error at /usr/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.27/Modules/FindThreads.cmake:226 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:580 (find_package)
-- Configuring incomplete, errors occurred!
```
It works if I use Clang 18 with LTO disabled, or if I use Clang 17 or Clang 19 with LTO enabled or disabled:
```
$ rm -f CMakeCache.txt
$ cmake .. -D'CMAKE_C_COMPILER'='clang-18' -D'CMAKE_CXX_COMPILER'='clang'++-18' -D'USE_LTO'='OFF'
-- The C compiler identification is Clang 18.1.3
-- The CXX compiler identification is Clang 18.1.3
…
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
…
-- Configuring done (7.2s)
-- Generating done (0.1s)
-- Build files have been written to: Daemon/build
```
```
$ rm -f CMakeCache.txt
$ cmake .. -D'CMAKE_C_COMPILER'='clang-17' -D'CMAKE_CXX_COMPILER'='clang'++-17' -D'USE_LTO'='ON'
-- The C compiler identification is Clang 17.0.6
-- The CXX compiler identification is Clang 17.0.6
…
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
…
-- Configuring done (7.2s)
-- Generating done (0.1s)
-- Build files have been written to: Daemon/build
```
```
$ rm -f CMakeCache.txt
$ cmake .. -D'CMAKE_C_COMPILER'='clang-19' -D'CMAKE_CXX_COMPILER'='clang'++-19' -D'USE_LTO'='ON'
-- The C compiler identification is Clang 19.0.0
-- The CXX compiler identification is Clang 19.0.0
…
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
…
-- Configuring done (7.2s)
-- Generating done (0.1s)
-- Build files have been written to: Daemon/build
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWN1y4jgWfhpxc8ouWwYMF1w4BneoSSepkOzmjhLywWgwEivJSe9e9LNvSTY_yaR7lt6e2tqaSSUBS-dfn44-ixkjKok4IYMrMpj2WGM3Sk9EXb8K5Nt_9Vaq_Ofk7xuUMIdVI-oS7AaBDK6mDHdKQsV2CCgrIZEMpoSONtbuDUkyQgtCi0rYTbMKudoRWrQqs1b48EjoGF6F3UBeM1lBPIK1Vjt4a4btbVjXL7tQ6QruJDytGmkboEkYR7Bj0goDTJaAkq1qhJvHO0JzHylXci2qRjMrlIQ1E7UBZv3U3m40shJKtMj9tLG4D2Fu4VXprXkXlljDHEphDh68IKuN-kA69dHE41api0rpN-okmpIo6_7ToVyZPUmuSJofbJy-jk5fx61CQNL89OeHbh7v4O6WpDmZUTLOyWhAZgW5GpFRAWp7GJ-SUX4a36pvyp9sFsXvGf2Px89SftwgaNwrbbHsyiYMkGEUj8I4TMgwelOhzAADI0oEqSy61Z27b4KjQySzbfnn0mIN8_zZGaIR7YcxGUbwuhF848yvmMESlOwctt6iMHJCc-BMHvGCfgVbxHvTrhTtQpbvli4hNIGZfBFayR1K-2Z2GHW_nXAfyv22gqAG7kII4hGQNIdK4x6CGRCaksFMCPfpNYSAk2T7E5Mka4v0ldArQq9colFCaZQmNBkSeoXrYRkjj1I-HAfxV_yyj78ehOJxQvujcDwCtiuH_c4m5K6keWvPp363-tXtihcMcuBqtxc16rd590-BBS9ASTIjdBj7dDZuXwU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