@@ -175,6 +175,23 @@ if (LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
175
175
list (APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt" )
176
176
endif ()
177
177
178
+ # Disable linker for running CMake checks
179
+ #
180
+ # This was originally added because when building libunwind for ARM Linux,
181
+ # we need to pass the -funwind-tables flag in order for it to work properly
182
+ # with ARM EHABI. However, this produces a false negative when performing CMake
183
+ # checks, causing libunwind to not be built with this flag.
184
+ #
185
+ # A similar dynamic occurred with the advent of CMAKE_REQUIRED_LINK_OPTIONS
186
+ # (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG), which causes flag checks for static
187
+ # targets to fail due to https://gitlab.kitware.com/cmake/cmake/-/issues/23454.
188
+ # Thus, to avoid failures with static targets, we cache the target type here,
189
+ # and reset it after the various flag support checks have been performed.
190
+ set (_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE} )
191
+ set (_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} )
192
+ set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )
193
+ set (CMAKE_REQUIRED_LINK_OPTIONS )
194
+
178
195
add_compile_flags_if_supported (-Werror=return-type )
179
196
180
197
if (LIBUNWIND_ENABLE_CET )
@@ -207,38 +224,16 @@ endif()
207
224
add_cxx_compile_flags_if_supported (-fstrict-aliasing )
208
225
add_cxx_compile_flags_if_supported (-EHsc )
209
226
210
- # Don't run the linker in this CMake check.
211
- #
212
- # The reason why this was added is that when building libunwind for
213
- # ARM Linux, we need to pass the -funwind-tables flag in order for it to
214
- # work properly with ARM EHABI.
215
- #
216
- # However, when performing CMake checks, adding this flag causes the check
217
- # to produce a false negative, because the compiler generates calls
218
- # to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
219
- # which isn't built yet, so the linker complains about undefined symbols.
220
- #
221
- # This leads to libunwind not being built with this flag, which makes
222
- # libunwind quite useless in this setup.
223
- #
224
- # NOTE: we need to work around https://gitlab.kitware.com/cmake/cmake/-/issues/23454
225
- # because CMAKE_REQUIRED_LINK_OPTIONS (c.f. CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
226
- # is incompatible with CMAKE_TRY_COMPILE_TARGET_TYPE==STATIC_LIBRARY.
227
- set (_previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE} )
228
- set (_previous_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS} )
229
- set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )
230
- set (CMAKE_REQUIRED_LINK_OPTIONS )
231
227
add_compile_flags_if_supported (-funwind-tables )
232
- add_cxx_compile_flags_if_supported (-fno-exceptions )
233
- add_cxx_compile_flags_if_supported (-fno-rtti )
234
- set (CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE} )
235
- set (CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS} )
236
228
237
229
if (LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG )
238
230
message (SEND_ERROR "The -funwind-tables flag must be supported "
239
231
"because this target uses ARM Exception Handling ABI" )
240
232
endif ()
241
233
234
+ add_cxx_compile_flags_if_supported (-fno-exceptions )
235
+ add_cxx_compile_flags_if_supported (-fno-rtti )
236
+
242
237
# Ensure that we don't depend on C++ standard library.
243
238
if (CXX_SUPPORTS_NOSTDINCXX_FLAG )
244
239
list (APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++ )
@@ -292,6 +287,10 @@ if (LIBUNWIND_ENABLE_ARM_WMMX)
292
287
add_compile_flags (-D__ARM_WMMX )
293
288
endif ()
294
289
290
+ # reset CMAKE_TRY_COMPILE_TARGET_TYPE & CMAKE_REQUIRED_LINK_OPTIONS after flag checks
291
+ set (CMAKE_TRY_COMPILE_TARGET_TYPE ${_previous_CMAKE_TRY_COMPILE_TARGET_TYPE} )
292
+ set (CMAKE_REQUIRED_LINK_OPTIONS ${_previous_CMAKE_REQUIRED_LINK_OPTIONS} )
293
+
295
294
if (LIBUNWIND_IS_BAREMETAL )
296
295
add_compile_definitions (_LIBUNWIND_IS_BAREMETAL )
297
296
endif ()
0 commit comments