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} -fno-use-cxa-atexit --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,8 +13,16 @@ LibcDeathTestExecutors.cpp ExecuteFunctionUnix.cpp) endif() +# The Nvidia 'nvlink' linker does not support static libraries. +if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX) + set(library_type OBJECT) +else() + set(library_type STATIC) +endif() + add_library( LibcUnitTest + ${library_type} EXCLUDE_FROM_ALL ${libc_test_srcs_common} ${libc_death_test_srcs} @@ -22,6 +30,7 @@ add_library( LibcHermeticTest + ${library_type} EXCLUDE_FROM_ALL ${libc_test_srcs_common} HermeticTestUtils.cpp @@ -29,6 +38,7 @@ add_library( LibcUnitTestMain + ${library_type} EXCLUDE_FROM_ALL LibcTestMain.cpp ) @@ -36,6 +46,7 @@ add_library( LibcHermeticTestMain + ${library_type} EXCLUDE_FROM_ALL LibcTestMain.cpp ) @@ -97,6 +108,7 @@ add_library( LibcMemoryHelpers + ${library_type} MemoryMatcher.h MemoryMatcher.cpp ) 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 @@ -17,6 +17,7 @@ void *memcpy(void *__restrict, const void *__restrict, size_t); void *memmove(void *dst, const void *src, size_t count); void *memset(void *ptr, int value, size_t count); +int atexit(void (*func)(void)); } // namespace __llvm_libc @@ -57,6 +58,9 @@ return __llvm_libc::memset(ptr, value, count); } +// This is needed if the test was compiled with '-fno-use-cxa-atexit'. +int atexit(void (*func)(void)) { return __llvm_libc::atexit(func); } + void *malloc(size_t s) { void *mem = ptr; ptr += s; @@ -78,7 +82,7 @@ __builtin_trap(); } -// Integration tests are linked with -nostdlib. BFD linker expects +// Hermetic tests are linked with -nostdlib. BFD linker expects // __dso_handle when -nostdlib is used. void *__dso_handle = nullptr; diff --git a/libc/test/src/__support/CPP/atomic_test.cpp b/libc/test/src/__support/CPP/atomic_test.cpp --- a/libc/test/src/__support/CPP/atomic_test.cpp +++ b/libc/test/src/__support/CPP/atomic_test.cpp @@ -14,21 +14,21 @@ TEST(LlvmLibcAtomicTest, LoadStore) { __llvm_libc::cpp::Atomic aint(123); - ASSERT_EQ(aint.load(), 123); + ASSERT_EQ(aint.load(__llvm_libc::cpp::MemoryOrder::RELAXED), 123); - aint.store(100); - ASSERT_EQ(aint.load(), 100); + aint.store(100, __llvm_libc::cpp::MemoryOrder::RELAXED); + ASSERT_EQ(aint.load(__llvm_libc::cpp::MemoryOrder::RELAXED), 100); aint = 1234; // Equivalent of store - ASSERT_EQ(aint.load(), 1234); + ASSERT_EQ(aint.load(__llvm_libc::cpp::MemoryOrder::RELAXED), 1234); } TEST(LlvmLibcAtomicTest, CompareExchangeStrong) { int desired = 123; __llvm_libc::cpp::Atomic aint(desired); ASSERT_TRUE(aint.compare_exchange_strong(desired, 100)); - ASSERT_EQ(aint.load(), 100); + ASSERT_EQ(aint.load(__llvm_libc::cpp::MemoryOrder::RELAXED), 100); ASSERT_FALSE(aint.compare_exchange_strong(desired, 100)); - ASSERT_EQ(aint.load(), 100); + ASSERT_EQ(aint.load(__llvm_libc::cpp::MemoryOrder::RELAXED), 100); }