diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -551,7 +551,8 @@ -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto --target=${LIBC_GPU_TARGET_TRIPLE}) elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE}) - list(APPEND ${nvptx_options} --target=${LIBC_GPU_TARGET_TRIPLE}) + list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS + ${nvptx_options} --target=${LIBC_GPU_TARGET_TRIPLE}) endif() # Rule to add a hermetic test. A hermetic test is one whose executable is fully diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt --- a/libc/test/CMakeLists.txt +++ b/libc/test/CMakeLists.txt @@ -22,10 +22,8 @@ return() endif() -if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) - add_subdirectory(src) - add_subdirectory(utils) -endif() +add_subdirectory(src) +add_subdirectory(utils) if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_BAREMETAL) add_subdirectory(IntegrationTest) diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt --- a/libc/test/UnitTest/CMakeLists.txt +++ b/libc/test/UnitTest/CMakeLists.txt @@ -13,32 +13,66 @@ LibcDeathTestExecutors.cpp ExecuteFunctionUnix.cpp) endif() -add_library( - LibcUnitTest - EXCLUDE_FROM_ALL - ${libc_test_srcs_common} - ${libc_death_test_srcs} -) +# The Nvidia 'nvlink' linker does not support static libraries. +if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) + add_library( + LibcUnitTest + OBJECT + EXCLUDE_FROM_ALL + ${libc_test_srcs_common} + ${libc_death_test_srcs} + ) -add_library( - LibcHermeticTest - EXCLUDE_FROM_ALL - ${libc_test_srcs_common} - HermeticTestUtils.cpp -) + add_library( + LibcHermeticTest + OBJECT + EXCLUDE_FROM_ALL + ${libc_test_srcs_common} + HermeticTestUtils.cpp + ) -add_library( - LibcUnitTestMain - EXCLUDE_FROM_ALL - LibcTestMain.cpp -) -add_dependencies(LibcUnitTestMain LibcUnitTest) + add_library( + LibcUnitTestMain + OBJECT + EXCLUDE_FROM_ALL + LibcTestMain.cpp + ) -add_library( - LibcHermeticTestMain - EXCLUDE_FROM_ALL - LibcTestMain.cpp -) + add_library( + LibcHermeticTestMain + OBJECT + EXCLUDE_FROM_ALL + LibcTestMain.cpp + ) +else() + add_library( + LibcUnitTest + EXCLUDE_FROM_ALL + ${libc_test_srcs_common} + ${libc_death_test_srcs} + ) + + add_library( + LibcHermeticTest + EXCLUDE_FROM_ALL + ${libc_test_srcs_common} + HermeticTestUtils.cpp + ) + + add_library( + LibcUnitTestMain + EXCLUDE_FROM_ALL + LibcTestMain.cpp + ) + + add_library( + LibcHermeticTestMain + EXCLUDE_FROM_ALL + LibcTestMain.cpp + ) +endif() + +add_dependencies(LibcUnitTestMain LibcUnitTest) add_dependencies(LibcHermeticTestMain LibcHermeticTest) foreach(lib LibcUnitTest LibcUnitTestMain LibcHermeticTest LibcHermeticTestMain) diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp --- a/libc/test/UnitTest/HermeticTestUtils.cpp +++ b/libc/test/UnitTest/HermeticTestUtils.cpp @@ -78,9 +78,15 @@ __builtin_trap(); } -// Integration tests are linked with -nostdlib. BFD linker expects +#if defined(__NVPTX__) +// FIXME: For unknown reason the Nvidia toolchain defines this to be a single +// byte and will error on a mismatched size otherwise. +uint8_t __dso_handle = 0; +#else +// Hermetic tests are linked with -nostdlib. BFD linker expects // __dso_handle when -nostdlib is used. void *__dso_handle = nullptr; +#endif } // extern "C"