Fix linking with address sanitizer.

`-fsanitize=address` also needs to be passed to the linker.
This commit is contained in:
iphydf 2018-06-17 23:56:58 +00:00
parent 16f5cc8c24
commit 90e1d969ac
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
2 changed files with 7 additions and 10 deletions

View File

@ -191,18 +191,14 @@ endif()
option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF) option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF)
if(ASAN) if(ASAN)
set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
add_cflag("-fsanitize=address") add_cflag("-fsanitize=address")
set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}") add_dllflag("-fsanitize=address")
endif()
if(LINUX)
add_dllflag("-Wl,-z,defs")
else() else()
# Forbid undefined symbols in shared libraries. This is incompatible with add_dllflag("-undefined error")
# asan, so it's in the else branch here.
if(LINUX)
add_dllflag("-Wl,-z,defs")
else()
add_dllflag("-undefined error")
endif()
endif() endif()
option(USE_IPV6 "Use IPv6 in tests" ON) option(USE_IPV6 "Use IPv6 in tests" ON)

View File

@ -37,6 +37,7 @@ function(add_dllflag flag)
check_c_compiler_flag("${flag}" HAVE_LD${var} QUIET) check_c_compiler_flag("${flag}" HAVE_LD${var} QUIET)
if(HAVE_LD${var}) if(HAVE_LD${var})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag}" PARENT_SCOPE) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${flag}" PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}" PARENT_SCOPE)
endif() endif()
endfunction() endfunction()