diff --git a/compiler-rt/lib/fuzzer/tests/CMakeLists.txt b/compiler-rt/lib/fuzzer/tests/CMakeLists.txt index adfae3d63e648..543f486a9d501 100644 --- a/compiler-rt/lib/fuzzer/tests/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/tests/CMakeLists.txt @@ -35,6 +35,27 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND COMPILER_RT_LIBCXXABI_PATH) list(APPEND LIBFUZZER_UNITTEST_CFLAGS -nostdinc++ -fno-exceptions) list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -nostdlib++ -fno-exceptions) + + # When we use -nostdlib++, we remove the default C++ runtime which normally + # provides the stack unwinding symbols (like __aeabi_unwind_cpp_pr0). + # We must now manually find and link a suitable unwinder library. + set(FUZZER_UNWINDER_LIBS) + if(COMPILER_RT_USE_LLVM_UNWINDER) + # Prefer LLVM's own libunwind. + list(APPEND FUZZER_UNWINDER_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS}) + elseif(COMPILER_RT_HAS_GCC_S_LIB) + # As a fallback, use the shared libgcc_s library. + list(APPEND FUZZER_UNWINDER_LIBS gcc_s) + elseif(COMPILER_RT_HAS_GCC_LIB) + # As a final fallback, use the static libgcc library. + list(APPEND FUZZER_UNWINDER_LIBS gcc) + elseif(NOT COMPILER_RT_USE_BUILTINS_LIBRARY) + # If no unwinder is found and we aren't using the builtins library + message(FATAL_ERROR "Fuzzer tests require a suitable unwinder, but none was found.") + endif() + # Add the detected unwinder library to our link flags. + list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS ${FUZZER_UNWINDER_LIBS}) + endif() if ("-fvisibility=hidden" IN_LIST LIBFUZZER_CFLAGS)