[libc-commits] [libc] abd85cd - [libc] Remove the optional arguments for NVPTX constructors (#69536)

via libc-commits libc-commits at lists.llvm.org
Mon Nov 20 15:10:19 PST 2023


Author: Joseph Huber
Date: 2023-11-20T17:10:15-06:00
New Revision: abd85cd473afedf112bf00630a22382fee4a7853

URL: https://github.com/llvm/llvm-project/commit/abd85cd473afedf112bf00630a22382fee4a7853
DIFF: https://github.com/llvm/llvm-project/commit/abd85cd473afedf112bf00630a22382fee4a7853.diff

LOG: [libc] Remove the optional arguments for NVPTX constructors (#69536)

Summary:
We call the global constructors by function pointer. For whatever reason
the NVPTX architecture relies very specifically on the arguments to the
function pointer invocation matching what the function is implemented
as. This is problematic as most of these constructors are generated
with no arguments. This patch removes the extended arguments that GNU
and LLVM use for the constructors optionally so that it can support the
common case.

Added: 
    

Modified: 
    libc/startup/gpu/nvptx/start.cpp
    libc/test/integration/startup/gpu/init_fini_array_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/startup/gpu/nvptx/start.cpp b/libc/startup/gpu/nvptx/start.cpp
index 2c09430c5971ef0..77fe921be4e029e 100644
--- a/libc/startup/gpu/nvptx/start.cpp
+++ b/libc/startup/gpu/nvptx/start.cpp
@@ -24,13 +24,15 @@ uintptr_t *__fini_array_start [[gnu::visibility("protected")]];
 uintptr_t *__fini_array_end [[gnu::visibility("protected")]];
 }
 
-using InitCallback = void(int, char **, char **);
+// Nvidia requires that the signature of the function pointers match. This means
+// we cannot support the extended constructor arguments.
+using InitCallback = void(void);
 using FiniCallback = void(void);
 
-static void call_init_array_callbacks(int argc, char **argv, char **env) {
+static void call_init_array_callbacks(int, char **, char **) {
   size_t init_array_size = __init_array_end - __init_array_start;
   for (size_t i = 0; i < init_array_size; ++i)
-    reinterpret_cast<InitCallback *>(__init_array_start[i])(argc, argv, env);
+    reinterpret_cast<InitCallback *>(__init_array_start[i])();
 }
 
 static void call_fini_array_callbacks() {

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 ead05f0240585a4..ceedd5fc813589c 100644
--- a/libc/test/integration/startup/gpu/init_fini_array_test.cpp
+++ b/libc/test/integration/startup/gpu/init_fini_array_test.cpp
@@ -37,11 +37,11 @@ A global(GLOBAL_INDEX, INITVAL_INITIALIZER);
 int initval = 0;
 int before = 0;
 
-__attribute__((constructor(101))) void run_before(int, char **, char **) {
+__attribute__((constructor(101))) void run_before() {
   before = BEFORE_INITIALIZER;
 }
 
-__attribute__((constructor(65535))) void run_after(int, char **, char **) {
+__attribute__((constructor(65535))) void run_after() {
   ASSERT_EQ(before, BEFORE_INITIALIZER);
 }
 


        


More information about the libc-commits mailing list