diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2023-04-28 09:33:44 -0500 |
---|---|---|
committer | Joseph Huber <jhuber6@vols.utk.edu> | 2023-05-04 07:13:00 -0500 |
commit | 2e1c0ec6297958f73ca5ed35ce47803ea0f48dba (patch) | |
tree | 5ecac614701cb678d6c7623dd9d32b705c7af286 /libc/test | |
parent | f05ce9045af4a40232c08451cb0aef64b0e673b2 (diff) | |
download | llvm-2e1c0ec6297958f73ca5ed35ce47803ea0f48dba.tar.gz |
[libc] Support global constructors and destructors on NVPTX
This patch adds the necessary hacks to support global constructors and
destructors. This is an incredibly hacky process caused by the primary
fact that Nvidia does not provide any binary tools and very little
linker support. We first had to emit references to these functions and
their priority in D149451. Then we dig them out of the module once it's
loaded to manually create the list that the linker should have made for
us. This patch also contains a few Nvidia specific hacks, but it passes
the test, albeit with a stack size warning from `ptxas` for the
callback. But this should be fine given the resource usage of a common
test.
This also adds a dependency on LLVM to the NVPTX loader, which hopefully doesn't
cause problems with our CUDA buildbot.
Depends on D149451
Reviewed By: tra
Differential Revision: https://reviews.llvm.org/D149527
Diffstat (limited to 'libc/test')
-rw-r--r-- | libc/test/IntegrationTest/test.cpp | 4 | ||||
-rw-r--r-- | libc/test/integration/startup/gpu/CMakeLists.txt | 15 | ||||
-rw-r--r-- | libc/test/integration/startup/gpu/init_fini_array_test.cpp | 2 |
3 files changed, 11 insertions, 10 deletions
diff --git a/libc/test/IntegrationTest/test.cpp b/libc/test/IntegrationTest/test.cpp index 4d2a7f08cc06..e86e0a8d22c8 100644 --- a/libc/test/IntegrationTest/test.cpp +++ b/libc/test/IntegrationTest/test.cpp @@ -22,6 +22,7 @@ int memcmp(const void *lhs, const void *rhs, size_t count); 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 @@ -44,6 +45,9 @@ void *memset(void *ptr, int value, size_t count) { 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); } + } // extern "C" // Integration tests cannot use the SCUDO standalone allocator as SCUDO pulls diff --git a/libc/test/integration/startup/gpu/CMakeLists.txt b/libc/test/integration/startup/gpu/CMakeLists.txt index ab3f4c39fe48..754f36d8789c 100644 --- a/libc/test/integration/startup/gpu/CMakeLists.txt +++ b/libc/test/integration/startup/gpu/CMakeLists.txt @@ -26,12 +26,9 @@ add_integration_test( --threads 1 ) -# Constructors are currently only supported on AMDGPU. -if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU) - add_integration_test( - init_fini_array_test - SUITE libc-startup-tests - SRCS - init_fini_array_test.cpp - ) -endif() +add_integration_test( + init_fini_array_test + SUITE libc-startup-tests + SRCS + init_fini_array_test.cpp +) diff --git a/libc/test/integration/startup/gpu/init_fini_array_test.cpp b/libc/test/integration/startup/gpu/init_fini_array_test.cpp index 23064e1e85aa..1e61711f0fc4 100644 --- a/libc/test/integration/startup/gpu/init_fini_array_test.cpp +++ b/libc/test/integration/startup/gpu/init_fini_array_test.cpp @@ -53,7 +53,7 @@ __attribute__((destructor(1))) void reset_initval() { initval = 0; } -TEST_MAIN() { +TEST_MAIN(int argc, char **argv, char **env) { ASSERT_EQ(global.get(GLOBAL_INDEX), INITVAL_INITIALIZER); ASSERT_EQ(initval, INITVAL_INITIALIZER); return 0; |