[libcxx-commits] [PATCH] D112112: [libunwind] Link with -unwindlib=none

Harald van Dijk via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 20 10:40:08 PDT 2021


hvdijk added a comment.

In D112112#3074741 <https://reviews.llvm.org/D112112#3074741>, @mstorsjo wrote:

> If inspecting `CMakeFiles/CMakeError.log` to see what happened when testing the `-unwindlib=none` flag, I find this:
>
>   Performing C SOURCE FILE Test LIBUNWIND_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG failed with the following output:
>   Change Dir: /build/llvm-project/libunwind/build-i686-shared/CMakeFiles/CMakeTmp
>   
>   Run Build Command(s):/usr/bin/ninja cmTC_94016 && [1/2] Building C object CMakeFiles/cmTC_94016.dir/src.c.obj
>   [2/2] Linking C executable cmTC_94016.exe
>   FAILED: cmTC_94016.exe
>   : && /opt/llvm-mingw/bin/i686-w64-mingw32-clang   CMakeFiles/cmTC_94016.dir/src.c.obj -o cmTC_94016.exe -Wl,--out-implib,libcmTC_94016.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && :
>   lld: error: unable to find library -lunwind
>   lld: error: unable to find library -lunwind
>   clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
>   ninja: build stopped: subcommand failed.
>
> During this particular test, CMake does apply the tested flag, `-unwindlib=none`, when compiling the test object (`CMakeFiles/cmTC_94016.dir/src.c.obj`) although that's not visible in the log. But it's not applying that flag when it does linking of the test executable. See e.g. https://gitlab.kitware.com/cmake/cmake/-/issues/15934 for discussion on that issue.
>
> If we just blindly add the flag to `CMAKE_REQUIRED_FLAGS` as I do in D112126 <https://reviews.llvm.org/D112126>, it will get included when doing tests, both when compiling and linking the test objects, making the tests succeed.

Keep in mind that this applies to situations where both 1) clang passes -lunwind by default and 2) libunwind is not available. How this gets handled may differ between different CMake versions, but in the one I'm using (3.21.3) that's a hard error by default because the toolchain doesn't work, it requires adding `-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY` to the CMake options anyway (even in LLVM 12) which disables CMake's link tests. And when that is added, that means there are no longer any link tests performed from CMake that LLVM needs to disable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112112/new/

https://reviews.llvm.org/D112112



More information about the libcxx-commits mailing list