Skip to content

Commit

Permalink
Changed how the libasan library path is determined for Perl unit test…
Browse files Browse the repository at this point in the history
…s to work also on the build server.

On Centos 7 calling "gcc -print-file-name=libasan.so" returns a path to "ld script" instead of a path to a shared library.
  • Loading branch information
hejllukas committed Feb 9, 2022
1 parent 8916a00 commit 81e9582
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions xs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,24 @@ else ()
endif ()

set(PERL_ENV_VARS "")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_CROSSCOMPILING AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
if (SLIC3R_ASAN OR SLIC3R_UBSAN)
set(PERL_ENV_VARS env)
endif ()

if (SLIC3R_ASAN)
# Find the location of libasan.so for passing it into LD_PRELOAD. It works with GCC and Clang on Linux.
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libasan.so OUTPUT_VARIABLE LIBASAN_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
set(PERL_ENV_VARS ${PERL_ENV_VARS} "LD_PRELOAD=${LIBASAN_PATH}")
# On Centos 7 calling "gcc -print-file-name=libasan.so" returns path to "ld script" instead of path to shared library.
set(_asan_compiled_bin ${CMAKE_CURRENT_BINARY_DIR}/detect_libasan)
set(_asan_source_file ${_asan_compiled_bin}.c)
# Compile and link simple C application with enabled address sanitizer.
file(WRITE ${_asan_source_file} "int main(){}")
include(GetPrerequisites)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${_asan_source_file} -fsanitize=address -lasan -o ${_asan_compiled_bin})
# Extract from the compiled application absolute path of libasan.
get_prerequisites(${_asan_compiled_bin} _asan_shared_libraries_list 0 0 "" "")
list(FILTER _asan_shared_libraries_list INCLUDE REGEX libasan)
set(PERL_ENV_VARS ${PERL_ENV_VARS} "LD_PRELOAD=${_asan_shared_libraries_list}")

# Suppressed memory leak reports that come from Perl.
set(PERL_LEAK_SUPPRESSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/leak_suppression.txt)
Expand Down

0 comments on commit 81e9582

Please sign in to comment.