<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64513>64513</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LTO] [OpenMP] Linker for Win32 PE fails to find OpenMP threadprivate symbols if full 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>
amyspark
</td>
</tr>
</table>
<pre>
Hi all,
This is to report that if both `-flto` and `-fopenmp` are enabled for a target, and it makes use of a static library that contains a symbol exported by `#pragma openmp threadprivate(...)`, linking will fail with the following error:
```
FAILED: subprojects/pixman-0.42.2/test/region-test.exe
"cc" -o subprojects/pixman-0.42.2/test/region-test.exe subprojects/pixman-0.42.2/test/region-test.exe.p/region-test.c.obj "-flto" "-Wl,--start-group" "subprojects\pixman-0.42.2\test\libtestutils.a" "subprojects\pixman-0.42.2\pixman\libpixman-1.a" "subprojects\pixman-0.42.2\pixman\libpixman-mmx.a" "subprojects\pixman-0.42.2\pixman\libpixman-sse2.a" "subprojects\pixman-0.42.2\pixman\libpixman-ssse3.a" "-pthread" "-fopenmp" "-fopenmp" "-lm" "D:/msys64/clang64/bin/../lib/libpng16.dll.a" "-Wl,--subsystem,console" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32" "-Wl,--end-group"
ld.lld: error: undefined symbol: thread-local initialization routine for prng_state
>>> referenced by ../subprojects/pixman-0.42.2/test/region-test.c
>>> subprojects/pixman-0.42.2/test/region-test.exe.p/region-test.c.obj
ld.lld: error: undefined symbol: thread-local initialization routine for prng_state_data
>>> referenced by ../subprojects/pixman-0.42.2/test/region-test.c
>>> subprojects/pixman-0.42.2/test/region-test.exe.p/region-test.c.obj
cc: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
```
Linking with `-flto=thin`, as well as building with GCC + `-flto`, both result in a working build.
To reproduce, please download https://www.cairographics.org/releases/pixman-0.42.2.tar.gz, unpack it, and then perform:
```
cd pixman-0.42.2
meson setup build -Ddefault_library=static -Db_lto=true -Dbackend_max_links=1
meson compile -C build
```
clang version 16.0.5
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:/msys64/clang64/bin
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk-v2zgO_zTKhbDhyEmad8jhNWl2C7xFeyjQYyBLtK0-WjIkOX_66ReSnTTpFsXOm5nDAIkjiiIZU-TvR-G9bgzihi3fs-VuJobQWrcR3cX3wr3OKqsum39rEESMb1mxY8Xz-PzSag_aQ7DgsLcuQGhFAF1DZUMLbFVkNQXLVgUIo0bZ9mi6Pm05BDSiIlRQWwcCgnANBsa36bgO0IlX9DB4BFuDAB9E0BJIV064yxhMWhOENj6qL11lCfAc_woqqC4xJONl70TTCRhDQ2gdCtU7fRQBGV_nec74Uzq5BdLmVZsGTpoIaqEJTjq0EFqE2hLZU1Sic9ax8vk-F9F-_CRx__zx5cOOlc_gh6p39hvK4Bnf9_rcCZMV-YLnnPF9QB8Y3ztstDVZlHI84-SScykZ5wCZfZObNxnl_U97MrfVN2Ccj5fJeVp_jcWQZT4IF7LG2aGfNPcxl9vHmMttirnckq7iagiafC7-L8tRHm0n3fztpl13frux98j_jLXH8mae9WM9XsVrg_xapG5axdJifN_5i18tGN9LEqZJq0obxvexpvekq_HZm2a-yhXRj7DX-xsqf_EBO8a30hpvCW-xXtEZpJLfNgaP7k5slL6TTtr43lq6bfgW6d7aEj5KYgj3zgd9SwJJ2ylq7rRCHUV_F276-2jUrfjGpiGVE6nYeNcuhcEorLVBNSFE3BuTnpGVgkAbHbQg_V0EbQ04OwRtMIFS70xziLhz7cnyw_gBhzU6NHIEmpTvP9xu8menf13D3mPT35aTgxJB_CMTI-VDOiLsowNpuy5STwR-VCP041lHllEIc2B8HckoO0bK84igzdHKlKFIIcm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