Index: lib/asan/tests/CMakeLists.txt =================================================================== --- lib/asan/tests/CMakeLists.txt +++ lib/asan/tests/CMakeLists.txt @@ -70,7 +70,13 @@ set(ASAN_UNITTEST_NOINST_LINKFLAGS ${ASAN_UNITTEST_COMMON_LINKFLAGS} - -ldl -lm) + -lm) + +# There's no libdl on FreeBSD. +if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + list(APPEND ASAN_UNITTEST_NOINST_LINKFLAGS -ldl) +endif() + if(NOT ANDROID) list(APPEND ASAN_UNITTEST_NOINST_LINKFLAGS -lpthread) endif() Index: lib/msan/tests/CMakeLists.txt =================================================================== --- lib/msan/tests/CMakeLists.txt +++ lib/msan/tests/CMakeLists.txt @@ -61,10 +61,15 @@ ) set(MSAN_UNITTEST_LINK_FLAGS -fsanitize=memory - -ldl # FIXME: we build libcxx without cxxabi and need libstdc++ to provide it. -lstdc++ ) + +# There's no libdl on FreeBSD. +if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + list(APPEND MSAN_UNITTEST_LINK_FLAGS -ldl) +endif() + set(MSAN_LOADABLE_LINK_FLAGS -fsanitize=memory -shared Index: lib/sanitizer_common/tests/CMakeLists.txt =================================================================== --- lib/sanitizer_common/tests/CMakeLists.txt +++ lib/sanitizer_common/tests/CMakeLists.txt @@ -41,7 +41,12 @@ -Wall -Werror -Werror=sign-compare) set(SANITIZER_TEST_LINK_FLAGS_COMMON - -lstdc++ -ldl) + -lstdc++) + +# There's no libdl on FreeBSD. +if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON -ldl) +endif() include_directories(..) include_directories(../..)