Skip to content

Commit 6f4add3

Browse files
authored
[compiler-rt] [Fuzzer] Fix ARMv7 test link failure by linking unwinder (#144495)
compiler-rt/lib/fuzzer/tests build was failing on armv7, with undefined references to unwinder symbols, such as __aeabi_unwind_cpp_pr0. This occurs because the test is built with `-nostdlib++` but `libunwind` is not explicitly linked to the final test executable. This patch resolves the issue by adding CMake logic to explicitly link the required unwinder to the fuzzer tests, inspired by the same solution used to fix Scudo build failures by https://reviews.llvm.org/D142888.
1 parent ee070d0 commit 6f4add3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

compiler-rt/lib/fuzzer/tests/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
3535
COMPILER_RT_LIBCXXABI_PATH)
3636
list(APPEND LIBFUZZER_UNITTEST_CFLAGS -nostdinc++ -fno-exceptions)
3737
list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -nostdlib++ -fno-exceptions)
38+
39+
# When we use -nostdlib++, we remove the default C++ runtime which normally
40+
# provides the stack unwinding symbols (like __aeabi_unwind_cpp_pr0).
41+
# We must now manually find and link a suitable unwinder library.
42+
set(FUZZER_UNWINDER_LIBS)
43+
if(COMPILER_RT_USE_LLVM_UNWINDER)
44+
# Prefer LLVM's own libunwind.
45+
list(APPEND FUZZER_UNWINDER_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS})
46+
elseif(COMPILER_RT_HAS_GCC_S_LIB)
47+
# As a fallback, use the shared libgcc_s library.
48+
list(APPEND FUZZER_UNWINDER_LIBS gcc_s)
49+
elseif(COMPILER_RT_HAS_GCC_LIB)
50+
# As a final fallback, use the static libgcc library.
51+
list(APPEND FUZZER_UNWINDER_LIBS gcc)
52+
elseif(NOT COMPILER_RT_USE_BUILTINS_LIBRARY)
53+
# If no unwinder is found and we aren't using the builtins library
54+
message(FATAL_ERROR "Fuzzer tests require a suitable unwinder, but none was found.")
55+
endif()
56+
# Add the detected unwinder library to our link flags.
57+
list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS ${FUZZER_UNWINDER_LIBS})
58+
3859
endif()
3960

4061
if ("-fvisibility=hidden" IN_LIST LIBFUZZER_CFLAGS)

0 commit comments

Comments
 (0)