[libc-commits] [libc] 82be6e1 - [libc][posix] implement _exit (#87185)
via libc-commits
libc-commits at lists.llvm.org
Tue Apr 2 10:37:46 PDT 2024
Author: aniplcc
Date: 2024-04-02T10:37:42-07:00
New Revision: 82be6e186b5f88779325c5ede99ac714b2cfc4fa
URL: https://github.com/llvm/llvm-project/commit/82be6e186b5f88779325c5ede99ac714b2cfc4fa
DIFF: https://github.com/llvm/llvm-project/commit/82be6e186b5f88779325c5ede99ac714b2cfc4fa.diff
LOG: [libc][posix] implement _exit (#87185)
Fixes #87126.
Added:
libc/src/unistd/_exit.cpp
libc/src/unistd/_exit.h
libc/test/src/unistd/_exit_test.cpp
Modified:
libc/config/gpu/entrypoints.txt
libc/config/gpu/headers.txt
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/riscv/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/spec/posix.td
libc/src/unistd/CMakeLists.txt
libc/test/src/unistd/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 4fb87cb9f5a33e..827b5937e63602 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -211,6 +211,9 @@ set(TARGET_LIBC_ENTRYPOINTS
# gpu/rpc.h entrypoints
libc.src.gpu.rpc_host_call
+
+ # unistd.h entrypoints
+ libc.src.unistd._exit
)
set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/gpu/headers.txt b/libc/config/gpu/headers.txt
index dd16938da8a447..37c063a7ef6f7e 100644
--- a/libc/config/gpu/headers.txt
+++ b/libc/config/gpu/headers.txt
@@ -12,6 +12,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.errno
libc.include.stdlib
libc.include.stdio
+ libc.include.unistd
# Header for RPC extensions
libc.include.gpu_rpc
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 4ba2d8387b07eb..8bf99459f7898d 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -675,6 +675,7 @@ if(LLVM_LIBC_FULL_BUILD)
# unistd.h entrypoints
libc.src.unistd.__llvm_libc_syscall
+ libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
libc.src.unistd.getopt
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 25745513b920ba..4dc5e9d33f0f84 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -706,6 +706,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.time.time
# unistd.h entrypoints
+ libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
libc.src.unistd.fork
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index c1d2bfa848df5a..cc7671cab08184 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -774,6 +774,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.time.time
# unistd.h entrypoints
+ libc.src.unistd._exit
libc.src.unistd.environ
libc.src.unistd.execv
libc.src.unistd.fork
diff --git a/libc/spec/posix.td b/libc/spec/posix.td
index 8444a449ebe5be..cfa8d3afedde3f 100644
--- a/libc/spec/posix.td
+++ b/libc/spec/posix.td
@@ -404,6 +404,11 @@ def POSIX : StandardSpec<"POSIX"> {
],
[], // Enumerations
[
+ FunctionSpec<
+ "_exit",
+ RetValSpec<NoReturn>,
+ [ArgSpec<IntType>]
+ >,
FunctionSpec<
"access",
RetValSpec<IntType>,
diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt
index e22b0e1872caa1..58b44f5307ca7e 100644
--- a/libc/src/unistd/CMakeLists.txt
+++ b/libc/src/unistd/CMakeLists.txt
@@ -2,6 +2,17 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()
+add_entrypoint_object(
+ _exit
+ SRCS
+ _exit.cpp
+ HDRS
+ _exit.h
+ DEPENDS
+ libc.include.unistd
+ libc.src.__support.OSUtil.osutil
+)
+
add_entrypoint_object(
access
ALIAS
diff --git a/libc/src/unistd/_exit.cpp b/libc/src/unistd/_exit.cpp
new file mode 100644
index 00000000000000..6fbf3a51d42f46
--- /dev/null
+++ b/libc/src/unistd/_exit.cpp
@@ -0,0 +1,19 @@
+//===------------------- 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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/_exit.h"
+#include "src/__support/OSUtil/quick_exit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+[[noreturn]] LLVM_LIBC_FUNCTION(void, _exit, (int status)) {
+ quick_exit(status);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/unistd/_exit.h b/libc/src/unistd/_exit.h
new file mode 100644
index 00000000000000..141b8753218915
--- /dev/null
+++ b/libc/src/unistd/_exit.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for _exit -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_UNISTD__EXIT_H
+#define LLVM_LIBC_SRC_UNISTD__EXIT_H
+
+namespace LIBC_NAMESPACE {
+
+[[noreturn]] void _exit(int status);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_UNISTD__EXIT_H
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index 3a7fe6f45c0911..9de5081f0094ea 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -444,3 +444,17 @@ add_libc_test(
libc.src.stdio.fopencookie
libc.src.stdio.fflush
)
+
+if(LLVM_LIBC_FULL_BUILD)
+ add_libc_test(
+ _exit_test
+ UNIT_TEST_ONLY
+ SUITE
+ libc_unistd_unittests
+ SRCS
+ _exit_test.cpp
+ DEPENDS
+ libc.include.unistd
+ libc.src.unistd._exit
+ )
+endif()
diff --git a/libc/test/src/unistd/_exit_test.cpp b/libc/test/src/unistd/_exit_test.cpp
new file mode 100644
index 00000000000000..6d0e4465dbba1d
--- /dev/null
+++ b/libc/test/src/unistd/_exit_test.cpp
@@ -0,0 +1,15 @@
+//===-- Unittests for _exit -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/_exit.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcUniStd, _exit) {
+ EXPECT_EXITS([] { LIBC_NAMESPACE::_exit(1); }, 1);
+ EXPECT_EXITS([] { LIBC_NAMESPACE::_exit(65); }, 65);
+}
More information about the libc-commits
mailing list