Skip to content

Commit 07bd439

Browse files
authored
[libc] added quick_exit function (#93620)
- In /libc/src/__support/ OSUtil, changed quick_exit to just exit, and put in namespace LIBC_NAMESPACE::internal. - In /libc/src/stdlib added quick_exit - Added test files for quick_exit
1 parent 6416958 commit 07bd439

File tree

20 files changed

+125
-44
lines changed

20 files changed

+125
-44
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ set(TARGET_LIBC_ENTRYPOINTS
173173
libc.src.stdlib.atoll
174174
libc.src.stdlib.bsearch
175175
libc.src.stdlib.div
176+
libc.src.stdlib.quick_exit
176177
libc.src.stdlib.labs
177178
libc.src.stdlib.ldiv
178179
libc.src.stdlib.llabs

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ def StdC : StandardSpec<"stdc"> {
10721072
FunctionSpec<"_Exit", RetValSpec<NoReturn>, [ArgSpec<IntType>]>,
10731073
FunctionSpec<"exit", RetValSpec<NoReturn>, [ArgSpec<IntType>]>,
10741074
FunctionSpec<"atexit", RetValSpec<IntType>, [ArgSpec<AtexitHandlerT>]>,
1075+
FunctionSpec<"quick_exit", RetValSpec<NoReturn>, [ArgSpec<IntType>]>,
10751076
]
10761077
>;
10771078

libc/src/__support/OSUtil/baremetal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ add_object_library(
22
baremetal_util
33
SRCS
44
io.cpp
5-
quick_exit.cpp
5+
exit.cpp
66
HDRS
77
io.h
88
DEPENDS
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//===----- Baremetal implementation of a quick exit function ----*- C++ -*-===//
1+
//===-------- Baremetal implementation of an exit function ------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/__support/OSUtil/quick_exit.h"
9+
#include "src/__support/OSUtil/exit.h"
1010

1111
// This is intended to be provided by the vendor.
12-
extern "C" [[noreturn]] void __llvm_libc_quick_exit(int status);
12+
extern "C" [[noreturn]] void __llvm_libc_exit(int status);
1313

14-
namespace LIBC_NAMESPACE {
14+
namespace LIBC_NAMESPACE::internal {
1515

16-
[[noreturn]] void quick_exit(int status) { __llvm_libc_quick_exit(status); }
16+
[[noreturn]] void exit(int status) { __llvm_libc_exit(status); }
1717

18-
} // namespace LIBC_NAMESPACE
18+
} // namespace LIBC_NAMESPACE::internal

libc/src/__support/OSUtil/exit.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===------------ Implementation of an exit function ------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_EXIT_H
10+
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_EXIT_H
11+
12+
namespace LIBC_NAMESPACE::internal {
13+
14+
[[noreturn]] void exit(int status);
15+
16+
}
17+
18+
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_EXIT_H

libc/src/__support/OSUtil/gpu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_object_library(
22
gpu_util
33
SRCS
4-
quick_exit.cpp
4+
exit.cpp
55
io.cpp
66
HDRS
77
io.h
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//===---------- GPU implementation of a quick exit function -----*- C++ -*-===//
1+
//===------------- GPU implementation of an exit function -------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/__support/OSUtil/quick_exit.h"
9+
#include "src/__support/OSUtil/exit.h"
1010

1111
#include "src/__support/RPC/rpc_client.h"
1212
#include "src/__support/macros/properties/architectures.h"
1313

14-
namespace LIBC_NAMESPACE {
14+
namespace LIBC_NAMESPACE::internal {
1515

16-
[[noreturn]] void quick_exit(int status) {
16+
[[noreturn]] void exit(int status) {
1717
// We want to first make sure the server is listening before we exit.
1818
rpc::Client::Port port = rpc::client.open<RPC_EXIT>();
1919
port.send_and_recv([](rpc::Buffer *) {}, [](rpc::Buffer *) {});
@@ -25,4 +25,4 @@ namespace LIBC_NAMESPACE {
2525
gpu::end_program();
2626
}
2727

28-
} // namespace LIBC_NAMESPACE
28+
} // namespace LIBC_NAMESPACE::internal

libc/src/__support/OSUtil/linux/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_subdirectory(${LIBC_TARGET_ARCHITECTURE})
77
add_object_library(
88
linux_util
99
SRCS
10-
quick_exit.cpp
10+
exit.cpp
1111
HDRS
1212
io.h
1313
syscall.h
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===---------- Linux implementation of a quick exit function ---*- C++ -*-===//
1+
//===------------ Linux implementation of an exit function ------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,19 +10,19 @@
1010
#include "syscall.h" // For internal syscall function.
1111
#include <sys/syscall.h> // For syscall numbers.
1212

13-
namespace LIBC_NAMESPACE {
13+
namespace LIBC_NAMESPACE::internal {
1414

1515
// mark as no_stack_protector for x86 since TLS can be torn down before calling
16-
// quick_exit so that the stack protector canary cannot be loaded.
16+
// exit so that the stack protector canary cannot be loaded.
1717
#ifdef LIBC_TARGET_ARCH_IS_X86
18-
__attribute__((no_stack_protector))
18+
[[clang::no_stack_protector]]
1919
#endif
20-
__attribute__((noreturn)) void
21-
quick_exit(int status) {
20+
[[noreturn]] void
21+
exit(int status) {
2222
for (;;) {
2323
LIBC_NAMESPACE::syscall_impl<long>(SYS_exit_group, status);
2424
LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, status);
2525
}
2626
}
2727

28-
} // namespace LIBC_NAMESPACE
28+
} // namespace LIBC_NAMESPACE::internal

libc/src/__support/libc_assert.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
#else // Not LIBC_COPT_USE_C_ASSERT
2222

23+
#include "src/__support/OSUtil/exit.h"
2324
#include "src/__support/OSUtil/io.h"
24-
#include "src/__support/OSUtil/quick_exit.h"
2525
#include "src/__support/integer_to_string.h"
2626
#include "src/__support/macros/attributes.h" // For LIBC_INLINE
2727

@@ -51,7 +51,7 @@ LIBC_INLINE void report_assertion_failure(const char *assertion,
5151

5252
// The public "assert" macro calls abort on failure. Should it be same here?
5353
// The libc internal assert can fire from anywhere inside the libc. So, to
54-
// avoid potential chicken-and-egg problems, it is simple to do a quick_exit
54+
// avoid potential chicken-and-egg problems, it is simple to do an exit
5555
// on assertion failure instead of calling abort. We also don't want to use
5656
// __builtin_trap as it could potentially be implemented using illegal
5757
// instructions which can be very misleading when debugging.
@@ -76,7 +76,7 @@ LIBC_INLINE void report_assertion_failure(const char *assertion,
7676
"' in function: '"); \
7777
LIBC_NAMESPACE::write_to_stderr(__PRETTY_FUNCTION__); \
7878
LIBC_NAMESPACE::write_to_stderr("'\n"); \
79-
LIBC_NAMESPACE::quick_exit(0xFF); \
79+
LIBC_NAMESPACE::internal::exit(0xFF); \
8080
} \
8181
} while (false)
8282
#endif // NDEBUG

0 commit comments

Comments
 (0)