[libc-commits] [libc] ae63b1a - [libc] Adjust NVPTX startup code

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Wed Mar 22 18:08:33 PDT 2023


Author: Joseph Huber
Date: 2023-03-22T20:08:08-05:00
New Revision: ae63b1a5767b89fe5af140365f9e3ccf74feb1f0

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

LOG: [libc] Adjust NVPTX startup code

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.

Added: 
    

Modified: 
    libc/startup/gpu/nvptx/CMakeLists.txt
    libc/startup/gpu/nvptx/start.cpp

Removed: 
    


################################################################################
diff  --git a/libc/startup/gpu/nvptx/CMakeLists.txt b/libc/startup/gpu/nvptx/CMakeLists.txt
index f7f58ec702bf..96ab7540cedb 100644
--- a/libc/startup/gpu/nvptx/CMakeLists.txt
+++ b/libc/startup/gpu/nvptx/CMakeLists.txt
@@ -8,6 +8,7 @@ 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.
@@ -15,4 +16,8 @@ add_startup_object(
 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}"
+)

diff  --git a/libc/startup/gpu/nvptx/start.cpp b/libc/startup/gpu/nvptx/start.cpp
index 61569423c7b5..cf4077c3d9ed 100644
--- a/libc/startup/gpu/nvptx/start.cpp
+++ b/libc/startup/gpu/nvptx/start.cpp
@@ -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);
 }


        


More information about the libc-commits mailing list