Skip to content

Commit

Permalink
[libc] Adjust NVPTX startup code
Browse files Browse the repository at this point in the history
Summary:
The startup code needs to include the environment pointer so we add this
to the arguments. Also we need to ensure that the `crt1.o` file is made
with `-fgpu-rdc` set so we can actually use it without undefined
reference errors.
  • Loading branch information
jhuber6 committed Mar 23, 2023
1 parent 9855fe4 commit ae63b1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion libc/startup/gpu/nvptx/CMakeLists.txt
Expand Up @@ -8,11 +8,16 @@ add_startup_object(
-nogpulib # Do not include any GPU vendor libraries.
-nostdinc
-x cuda # Use the CUDA toolchain to emit the `_start` kernel.
-fgpu-rdc # Emit relocatable device code from CUDA.
--offload-device-only
--offload-arch=${LIBC_GPU_TARGET_ARCHITECTURE}
NO_GPU_BUNDLE # Compile this file directly without special GPU handling.
)
get_fq_target_name(crt1 fq_name)

# Ensure that clang uses the correct linker for this object type.
target_link_libraries(${fq_name} PUBLIC "--target=${LIBC_GPU_TARGET_TRIPLE}")
target_link_libraries(${fq_name}
PUBLIC
"-march=${LIBC_GPU_TARGET_ARCHITECTURE}"
"--target=${LIBC_GPU_TARGET_TRIPLE}"
)
7 changes: 4 additions & 3 deletions libc/startup/gpu/nvptx/start.cpp
Expand Up @@ -6,10 +6,11 @@
//
//===----------------------------------------------------------------------===//

extern "C" __attribute__((device)) int main(int argc, char **argv);
extern "C" __attribute__((device)) int main(int argc, char **argv, char **envp);

// TODO: We shouldn't need to use the CUDA language to emit a kernel for NVPTX.
extern "C" [[gnu::visibility("protected")]] __attribute__((global)) void
_start(int argc, char **argv, int *ret) {
__atomic_fetch_or(ret, main(argc, argv), __ATOMIC_RELAXED);
_start(int argc, char **argv, char **envp, int *ret, void *in, void *out,
void *buffer) {
__atomic_fetch_or(ret, main(argc, argv, envp), __ATOMIC_RELAXED);
}

0 comments on commit ae63b1a

Please sign in to comment.