From: Joseph Huber Date: Thu, 27 Apr 2023 18:05:29 +0000 (-0500) Subject: [libc] Implement `exit` for the GPU partially X-Git-Tag: upstream/17.0.6~10118 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=443d71527be0a052b2f533e4ad540733279ce46b;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 72c3067..aa2a6eb 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 a9de969..8067eeb 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 0300a08..5aec134 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 92faea4..71f5b1e 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 360d363..1d3c00a 100644 --- a/libc/src/stdlib/linux/CMakeLists.txt +++ b/libc/src/stdlib/linux/CMakeLists.txt @@ -1,16 +1,4 @@ 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 abort.cpp