Skip to content

Commit abd85cd

Browse files
authored
[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.
1 parent 44c796d commit abd85cd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

libc/startup/gpu/nvptx/start.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ uintptr_t *__fini_array_start [[gnu::visibility("protected")]];
2424
uintptr_t *__fini_array_end [[gnu::visibility("protected")]];
2525
}
2626

27-
using InitCallback = void(int, char **, char **);
27+
// Nvidia requires that the signature of the function pointers match. This means
28+
// we cannot support the extended constructor arguments.
29+
using InitCallback = void(void);
2830
using FiniCallback = void(void);
2931

30-
static void call_init_array_callbacks(int argc, char **argv, char **env) {
32+
static void call_init_array_callbacks(int, char **, char **) {
3133
size_t init_array_size = __init_array_end - __init_array_start;
3234
for (size_t i = 0; i < init_array_size; ++i)
33-
reinterpret_cast<InitCallback *>(__init_array_start[i])(argc, argv, env);
35+
reinterpret_cast<InitCallback *>(__init_array_start[i])();
3436
}
3537

3638
static void call_fini_array_callbacks() {

libc/test/integration/startup/gpu/init_fini_array_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ A global(GLOBAL_INDEX, INITVAL_INITIALIZER);
3737
int initval = 0;
3838
int before = 0;
3939

40-
__attribute__((constructor(101))) void run_before(int, char **, char **) {
40+
__attribute__((constructor(101))) void run_before() {
4141
before = BEFORE_INITIALIZER;
4242
}
4343

44-
__attribute__((constructor(65535))) void run_after(int, char **, char **) {
44+
__attribute__((constructor(65535))) void run_after() {
4545
ASSERT_EQ(before, BEFORE_INITIALIZER);
4646
}
4747

0 commit comments

Comments
 (0)