[libc-commits] [libc] 443d715 - [libc] Implement `exit` for the GPU partially

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu Apr 27 18:32:12 PDT 2023


Author: Joseph Huber
Date: 2023-04-27T20:32:00-05:00
New Revision: 443d71527be0a052b2f533e4ad540733279ce46b

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

LOG: [libc] Implement `exit` for the GPU partially

This patch implements the `exit` function on the GPU. This required
breaking the entrypoints calling eachother on `linux` since this doesn't
work with a non-aliased target. This is only partial support because
full support requires a malloc / free implementation for the exit
callbacks array.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D149363

Added: 
    libc/src/stdlib/_Exit.cpp

Modified: 
    libc/config/gpu/entrypoints.txt
    libc/src/stdlib/CMakeLists.txt
    libc/src/stdlib/exit.cpp
    libc/src/stdlib/linux/CMakeLists.txt

Removed: 
    libc/src/stdlib/linux/_Exit.cpp


################################################################################
diff  --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 72c30676605e1..aa2a6eb01247c 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -62,7 +62,6 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.atoll
     libc.src.stdlib.labs
     libc.src.stdlib.llabs
-    libc.src.stdlib.atexit
     libc.src.stdlib.strtod
     libc.src.stdlib.strtof
     libc.src.stdlib.strtol
@@ -71,6 +70,11 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdlib.strtoul
     libc.src.stdlib.strtoull
 
+    # stdlib.h entrypoints
+    libc.src.stdlib._Exit
+    libc.src.stdlib.atexit
+    libc.src.stdlib.exit
+
     # Only implemented in the test suite
     libc.src.stdlib.malloc
     libc.src.stdlib.aligned_alloc

diff  --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index a9de969a55114..8067eebb532a4 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -313,9 +313,13 @@ endif()
 
 add_entrypoint_object(
   _Exit
-  ALIAS
+  SRCS
+    _Exit.cpp
+  HDRS
+    _Exit.h
   DEPENDS
-    .${LIBC_TARGET_OS}._Exit
+    libc.include.stdlib
+    libc.src.__support.OSUtil.osutil
 )
 
 add_entrypoint_object(
@@ -341,6 +345,7 @@ add_entrypoint_object(
   DEPENDS
     ._Exit
     .atexit
+    libc.src.__support.OSUtil.osutil
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/stdlib/linux/_Exit.cpp b/libc/src/stdlib/_Exit.cpp
similarity index 59%
rename from libc/src/stdlib/linux/_Exit.cpp
rename to libc/src/stdlib/_Exit.cpp
index 0300a08847cea..5aec134b1c71c 100644
--- a/libc/src/stdlib/linux/_Exit.cpp
+++ b/libc/src/stdlib/_Exit.cpp
@@ -1,4 +1,4 @@
-//===------------------- Linux Implementation of _Exit --------------------===//
+//===------------------- Implementation of _Exit --------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "include/sys/syscall.h"          // For syscall numbers.
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/quick_exit.h"
 #include "src/__support/common.h"
 
 #include "src/stdlib/_Exit.h"
@@ -15,10 +14,8 @@
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(void, _Exit, (int status)) {
-  for (;;) {
-    __llvm_libc::syscall_impl(SYS_exit_group, status);
-    __llvm_libc::syscall_impl(SYS_exit, status);
-  }
+  quick_exit(status);
+  __builtin_unreachable();
 }
 
 } // namespace __llvm_libc

diff  --git a/libc/src/stdlib/exit.cpp b/libc/src/stdlib/exit.cpp
index 92faea4da6ad0..71f5b1ecbf2c9 100644
--- a/libc/src/stdlib/exit.cpp
+++ b/libc/src/stdlib/exit.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/stdlib/exit.h"
+#include "src/__support/OSUtil/quick_exit.h"
 #include "src/__support/common.h"
-#include "src/stdlib/_Exit.h"
 
 namespace __llvm_libc {
 
@@ -18,7 +18,7 @@ void call_exit_callbacks();
 
 LLVM_LIBC_FUNCTION(void, exit, (int status)) {
   internal::call_exit_callbacks();
-  _Exit(status);
+  quick_exit(status);
 }
 
 } // namespace __llvm_libc

diff  --git a/libc/src/stdlib/linux/CMakeLists.txt b/libc/src/stdlib/linux/CMakeLists.txt
index 360d3634f361c..1d3c00a5e0ddb 100644
--- a/libc/src/stdlib/linux/CMakeLists.txt
+++ b/libc/src/stdlib/linux/CMakeLists.txt
@@ -1,15 +1,3 @@
-add_entrypoint_object(
-  _Exit
-  SRCS
-    _Exit.cpp
-  HDRS
-    ../_Exit.h
-  DEPENDS
-    libc.include.sys_syscall
-    libc.include.stdlib
-    libc.src.__support.OSUtil.osutil
-)
-
 add_entrypoint_object(
   abort
   SRCS


        


More information about the libc-commits mailing list