Skip to content

Commit

Permalink
[cmake] CheckIfuncSupport.cmake: Don't check for NOT DEFINED HAVE_IFUNC.
Browse files Browse the repository at this point in the history
Otherwise, if I add -fsanitize in a later run, IFUNC will remain enabled,
resulting in SIGSEGV.

Also, add checks for CFLAGS/CXXFLAGS in specific build types, similar to
libromdata.
  • Loading branch information
GerbilSoft committed Jan 25, 2025
1 parent bf4de23 commit 47296cf
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions cmake/macros/CheckIfuncSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
# Requires ELF. Currently supported by gcc, but not clang.

FUNCTION(CHECK_IFUNC_SUPPORT)
IF(NOT DEFINED HAVE_IFUNC)
# NOTE: ${CMAKE_MODULE_PATH} has two directories, macros/ and libs/,
# so we have to configure this manually.
SET(IFUNC_SOURCE_PATH "${CMAKE_SOURCE_DIR}/cmake/macros")
# NOTE: ${CMAKE_MODULE_PATH} has two directories, macros/ and libs/,
# so we have to configure this manually.
SET(IFUNC_SOURCE_PATH "${CMAKE_SOURCE_DIR}/cmake/macros")

# NOTE: If -fsanitize is specified, disable IFUNC.
# Otherwise, SIGSEGV will happen.
IF(CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
SET(IS_SANITIZE 1)
ENDIF()
# NOTE: If -fsanitize is specified, disable IFUNC.
# Otherwise, SIGSEGV will happen.
IF(CMAKE_C_FLAGS MATCHES "-fsanitize" OR CMAKE_CXX_FLAGS MATCHES "-fsanitize")
SET(IS_SANITIZE 1)
ELSEIF(CMAKE_C_FLAGS_${BUILD_TYPE_UCASE} MATCHES "-fsanitize" OR CMAKE_CXX_FLAGS_${BUILD_TYPE_UCASE} MATCHES "-fsanitize")
SET(IS_SANITIZE 1)
ENDIF()

# Check for IFUNC support.
MESSAGE(STATUS "Checking if IFUNC is supported")
IF(WIN32 OR APPLE)
# No IFUNC for Windows or Mac OS X.
# Shortcut here to avoid needing a cross-compiled test program.
# Check for IFUNC support.
MESSAGE(STATUS "Checking if IFUNC is supported")
IF(WIN32 OR APPLE)
# No IFUNC for Windows or Mac OS X.
# Shortcut here to avoid needing a cross-compiled test program.
MESSAGE(STATUS "Checking if IFUNC is supported - no")
SET(TMP_HAVE_IFUNC FALSE)
ELSEIF(IS_SANITIZE)
MESSAGE(STATUS "Checking if IFUNC is supported - disabled due to -fsanitize")
SET(TMP_HAVE_IFUNC FALSE)
ELSE()
TRY_RUN(TMP_HAVE_IFUNC_RUN TMP_HAVE_IFUNC_COMPILE
"${CMAKE_BINARY_DIR}"
"${IFUNC_SOURCE_PATH}/IfuncTest.c")
IF(TMP_HAVE_IFUNC_COMPILE AND (TMP_HAVE_IFUNC_RUN EQUAL 0))
MESSAGE(STATUS "Checking if IFUNC is supported - yes")
SET(TMP_HAVE_IFUNC TRUE)
ELSE()
MESSAGE(STATUS "Checking if IFUNC is supported - no")
SET(TMP_HAVE_IFUNC FALSE)
ELSEIF(IS_SANITIZE)
MESSAGE(STATUS "Checking if IFUNC is supported - disabled due to -fsanitize")
SET(TMP_HAVE_IFUNC FALSE)
ELSE()
TRY_RUN(TMP_HAVE_IFUNC_RUN TMP_HAVE_IFUNC_COMPILE
"${CMAKE_BINARY_DIR}"
"${IFUNC_SOURCE_PATH}/IfuncTest.c")
IF(TMP_HAVE_IFUNC_COMPILE AND (TMP_HAVE_IFUNC_RUN EQUAL 0))
MESSAGE(STATUS "Checking if IFUNC is supported - yes")
SET(TMP_HAVE_IFUNC TRUE)
ELSE()
MESSAGE(STATUS "Checking if IFUNC is supported - no")
SET(TMP_HAVE_IFUNC FALSE)
ENDIF()
ENDIF()

SET(HAVE_IFUNC ${TMP_HAVE_IFUNC} CACHE INTERNAL "Is IFUNC supported?")
ENDIF()

SET(HAVE_IFUNC ${TMP_HAVE_IFUNC} CACHE INTERNAL "Is IFUNC supported?")
ENDFUNCTION(CHECK_IFUNC_SUPPORT)

0 comments on commit 47296cf

Please sign in to comment.