Skip to content

Commit

Permalink
Fix the cross compilation of unit tests. NFC (second attempt)
Browse files Browse the repository at this point in the history
With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling
environment, the unit tests fail to link. This patch does the following changes

>Rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the 
way it's used.
>Add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so 
that cross-compiler would be able to build/compile the unit tests
>Add COMPILER_RT_UNITTEST_LINKFLAGS to COMPILER_RT_UNITTEST_CFLAGS so 
that cross-compiler would be able to link the unit tests (if needed)

Differential Revision: http://reviews.llvm.org/D16165

llvm-svn: 257783
  • Loading branch information
Sumanth Gundapaneni committed Jan 14, 2016
1 parent 944cd4d commit b76bf10
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
11 changes: 7 additions & 4 deletions compiler-rt/cmake/Modules/AddCompilerRT.cmake
Expand Up @@ -165,7 +165,10 @@ function(add_compiler_rt_runtime name type)
endif()
endfunction()

set(COMPILER_RT_TEST_CFLAGS)
# when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help
# in compilation and linking of unittests.
string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
set(COMPILER_RT_UNITTEST_LINKFLAGS ${COMPILER_RT_UNITTEST_CFLAGS})

# Unittests support.
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
Expand All @@ -177,14 +180,14 @@ set(COMPILER_RT_GTEST_CFLAGS
-I${COMPILER_RT_GTEST_PATH}
)

append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_TEST_CFLAGS)
append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)

if(MSVC)
# clang doesn't support exceptions on Windows yet.
list(APPEND COMPILER_RT_TEST_CFLAGS -D_HAS_EXCEPTIONS=0)
list(APPEND COMPILER_RT_UNITTEST_CFLAGS -D_HAS_EXCEPTIONS=0)

# We should teach clang to understand "#pragma intrinsic", see PR19898.
list(APPEND COMPILER_RT_TEST_CFLAGS -Wno-undefined-inline)
list(APPEND COMPILER_RT_UNITTEST_CFLAGS -Wno-undefined-inline)

# Clang doesn't support SEH on Windows yet.
list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0)
Expand Down
7 changes: 6 additions & 1 deletion compiler-rt/lib/asan/tests/CMakeLists.txt
Expand Up @@ -21,7 +21,7 @@ set(ASAN_UNITTEST_HEADERS
asan_test_utils.h)

set(ASAN_UNITTEST_COMMON_CFLAGS
${COMPILER_RT_TEST_CFLAGS}
${COMPILER_RT_UNITTEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
Expand All @@ -34,6 +34,11 @@ set(ASAN_UNITTEST_COMMON_CFLAGS
-Wno-non-virtual-dtor)
append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros ASAN_UNITTEST_COMMON_CFLAGS)

# This will ensure the target linker is used
# during cross compilation
set(ASAN_UNITTEST_COMMON_LINKFLAGS
${COMPILER_RT_UNITTEST_LINKFLAGS})

# -gline-tables-only must be enough for ASan, so use it if possible.
if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang")
list(APPEND ASAN_UNITTEST_COMMON_CFLAGS -gline-tables-only)
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/msan/tests/CMakeLists.txt
Expand Up @@ -20,7 +20,7 @@ set(MSAN_UNITTEST_HEADERS
set(MSAN_UNITTEST_COMMON_CFLAGS
-nostdinc++
-isystem ${COMPILER_RT_LIBCXX_PATH}/include
${COMPILER_RT_TEST_CFLAGS}
${COMPILER_RT_UNITTEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
Expand Up @@ -44,7 +44,7 @@ foreach(header ${SANITIZER_HEADERS})
endforeach()

set(SANITIZER_TEST_CFLAGS_COMMON
${COMPILER_RT_TEST_CFLAGS}
${COMPILER_RT_UNITTEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/tsan/tests/CMakeLists.txt
Expand Up @@ -6,7 +6,7 @@ set_target_properties(TsanUnitTests PROPERTIES

set(TSAN_UNITTEST_CFLAGS
${TSAN_CFLAGS}
${COMPILER_RT_TEST_CFLAGS}
${COMPILER_RT_UNITTEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/tsan/rtl
Expand Down

0 comments on commit b76bf10

Please sign in to comment.