[libc-commits] [libc] [libc][annex_k] Add abort_handler_s. (PR #164089)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Mon Apr 13 01:24:57 PDT 2026
https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/164089
>From 8074ad62e7e4abd28515250a9ded01e7498a534e Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Tue, 14 Oct 2025 00:42:14 +0300
Subject: [PATCH 1/2] [libc][annex_k] Add abort_handler_s.
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/include/stdlib.yaml | 14 ++++++-
libc/src/__support/CMakeLists.txt | 1 +
libc/src/__support/annex_k/CMakeLists.txt | 12 ++++++
libc/src/__support/annex_k/abort_handler_s.h | 43 ++++++++++++++++++++
libc/src/stdlib/CMakeLists.txt | 10 +++++
libc/src/stdlib/abort_handler_s.cpp | 20 +++++++++
libc/src/stdlib/abort_handler_s.h | 22 ++++++++++
10 files changed, 124 insertions(+), 1 deletion(-)
create mode 100644 libc/src/__support/annex_k/CMakeLists.txt
create mode 100644 libc/src/__support/annex_k/abort_handler_s.h
create mode 100644 libc/src/stdlib/abort_handler_s.cpp
create mode 100644 libc/src/stdlib/abort_handler_s.h
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 72836d031c0e8..91be2d1f535e0 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1109,6 +1109,7 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 2038b776e539b..0e56884e8c065 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1238,6 +1238,7 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index b43ec51d1ece8..3a5d1a1457ab1 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1296,6 +1296,7 @@ if(LLVM_LIBC_FULL_BUILD)
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.at_quick_exit
libc.src.stdlib.atexit
libc.src.stdlib.exit
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index a751f8306be24..4369434c0e194 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -4,7 +4,9 @@ standards:
merge_yaml_files:
- stdlib-malloc.yaml
macros:
- - macro_name: "NULL"
+ - macro_name: 'LIBC_HAS_ANNEX_K'
+ macro_header: annex-k-macros.h
+ - macro_name: 'NULL'
macro_header: null-macro.h
- macro_name: EXIT_SUCCESS
macro_header: stdlib-macros.h
@@ -17,6 +19,7 @@ types:
- type_name: __search_compare_t
- type_name: constraint_handler_t
- type_name: div_t
+ - type_name: errno_t
- type_name: ldiv_t
- type_name: lldiv_t
- type_name: locale_t
@@ -203,6 +206,15 @@ functions:
return_type: int
arguments:
- type: void
+ - name: abort_handler_s
+ standards:
+ - stdc
+ return_type: void
+ arguments:
+ - type: const char *__restrict
+ - type: void *__restrict
+ - type: errno_t
+ guard: 'LIBC_HAS_ANNEX_K'
- name: srand
standards:
- stdc
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index ce69d4e6f69ac..965dbe51cbf75 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -1,3 +1,4 @@
+add_subdirectory(annex_k)
add_subdirectory(CPP)
add_subdirectory(macros)
diff --git a/libc/src/__support/annex_k/CMakeLists.txt b/libc/src/__support/annex_k/CMakeLists.txt
new file mode 100644
index 0000000000000..78f5b3cddebd7
--- /dev/null
+++ b/libc/src/__support/annex_k/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_header_library(
+ abort_handler_s
+ HDRS
+ abort_handler_s.h
+ DEPENDS
+ libc.hdr.stdio_macros
+ libc.hdr.types.errno_t
+ libc.src.__support.macros.config
+ libc.src.__support.macros.attributes
+ libc.src.__support.OSUtil.osutil
+ libc.src.stdlib.abort
+)
diff --git a/libc/src/__support/annex_k/abort_handler_s.h b/libc/src/__support/annex_k/abort_handler_s.h
new file mode 100644
index 0000000000000..dca3dcc2d9825
--- /dev/null
+++ b/libc/src/__support/annex_k/abort_handler_s.h
@@ -0,0 +1,43 @@
+//===-- Implementation for abort_handler_s ----------------------*- 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___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
+#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
+
+#include "hdr/stdio_macros.h"
+#include "hdr/types/errno_t.h"
+#include "src/__support/OSUtil/io.h"
+#include "src/__support/common.h"
+#include "src/stdlib/abort.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace annex_k {
+
+LIBC_INLINE static void abort_handler_s(const char *__restrict msg,
+ [[maybe_unused]] void *__restrict ptr,
+ [[maybe_unused]] errno_t error) {
+ write_to_stderr("abort_handler_s was called in response to a "
+ "runtime-constraint violation.\n\n");
+
+ if (msg)
+ write_to_stderr(msg);
+
+ write_to_stderr(
+ "\n\nNote to end users: This program was terminated as a result\
+of a bug present in the software. Please reach out to your\
+software's vendor to get more help.\n");
+
+ abort();
+}
+
+} // namespace annex_k
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 4265e0de57654..1ff5fe35a5719 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -731,6 +731,16 @@ add_entrypoint_object(
.abort_utils
)
+add_entrypoint_object(
+ abort_handler_s
+ SRCS
+ abort_handler_s.cpp
+ HDRS
+ abort_handler_s.h
+ DEPENDS
+ libc.src.__support.annex_k.abort_handler_s
+)
+
add_entrypoint_object(
system
ALIAS
diff --git a/libc/src/stdlib/abort_handler_s.cpp b/libc/src/stdlib/abort_handler_s.cpp
new file mode 100644
index 0000000000000..85a4cd4858315
--- /dev/null
+++ b/libc/src/stdlib/abort_handler_s.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for abort_handler_s ----------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdlib/abort_handler_s.h"
+#include "src/__support/annex_k/abort_handler_s.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(void, abort_handler_s,
+ (const char *__restrict msg, void *__restrict ptr,
+ errno_t error)) {
+ return annex_k::abort_handler_s(msg, ptr, error);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/abort_handler_s.h b/libc/src/stdlib/abort_handler_s.h
new file mode 100644
index 0000000000000..b97a081b036d2
--- /dev/null
+++ b/libc/src/stdlib/abort_handler_s.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for abort_handler_s ---------------*- 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_STDLIB_ABORT_HANDLER_S_H
+#define LLVM_LIBC_SRC_STDLIB_ABORT_HANDLER_S_H
+
+#include "hdr/types/errno_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+void abort_handler_s(const char *__restrict msg, void *__restrict ptr,
+ errno_t error);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDLIB_ABORT_HANDLER_S_H
>From 8f2e04038b777dc2a05dc559fed5f754788a83d7 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Mon, 13 Apr 2026 10:19:38 +0200
Subject: [PATCH 2/2] apply code review suggestions
---
libc/config/baremetal/aarch64/entrypoints.txt | 1 +
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/gpu/amdgpu/entrypoints.txt | 1 +
libc/config/gpu/nvptx/entrypoints.txt | 1 +
libc/include/stdlib.yaml | 1 -
libc/src/__support/annex_k/CMakeLists.txt | 5 ++---
libc/src/__support/annex_k/abort_handler_s.h | 4 ++--
libc/src/stdlib/abort_handler_s.cpp | 2 +-
9 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 82910c320b48a..327265dd83c9d 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -235,6 +235,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib._Exit
libc.src.stdlib.a64l
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.abs
libc.src.stdlib.aligned_alloc
libc.src.stdlib.atexit
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 4cf34764916f7..02bd42f6271e0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -235,6 +235,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib._Exit
libc.src.stdlib.a64l
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.abs
libc.src.stdlib.aligned_alloc
libc.src.stdlib.atexit
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index c4a11c6f87337..5b9025a2db782 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -232,6 +232,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib._Exit
libc.src.stdlib.a64l
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.abs
libc.src.stdlib.aligned_alloc
libc.src.stdlib.atexit
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 40566029c8a42..52dc7dac09ac4 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -159,6 +159,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.abs
libc.src.stdlib.atexit
libc.src.stdlib.atof
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 22f2bc849523e..adace784a80b7 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -159,6 +159,7 @@ set(TARGET_LIBC_ENTRYPOINTS
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
+ libc.src.stdlib.abort_handler_s
libc.src.stdlib.abs
libc.src.stdlib.atexit
libc.src.stdlib.atof
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index 4369434c0e194..80cb8abdf82e5 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -19,7 +19,6 @@ types:
- type_name: __search_compare_t
- type_name: constraint_handler_t
- type_name: div_t
- - type_name: errno_t
- type_name: ldiv_t
- type_name: lldiv_t
- type_name: locale_t
diff --git a/libc/src/__support/annex_k/CMakeLists.txt b/libc/src/__support/annex_k/CMakeLists.txt
index 78f5b3cddebd7..ac875c35dacfe 100644
--- a/libc/src/__support/annex_k/CMakeLists.txt
+++ b/libc/src/__support/annex_k/CMakeLists.txt
@@ -3,10 +3,9 @@ add_header_library(
HDRS
abort_handler_s.h
DEPENDS
- libc.hdr.stdio_macros
libc.hdr.types.errno_t
- libc.src.__support.macros.config
- libc.src.__support.macros.attributes
libc.src.__support.OSUtil.osutil
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
libc.src.stdlib.abort
)
diff --git a/libc/src/__support/annex_k/abort_handler_s.h b/libc/src/__support/annex_k/abort_handler_s.h
index dca3dcc2d9825..4684af8a6d28d 100644
--- a/libc/src/__support/annex_k/abort_handler_s.h
+++ b/libc/src/__support/annex_k/abort_handler_s.h
@@ -9,10 +9,10 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
-#include "hdr/stdio_macros.h"
#include "hdr/types/errno_t.h"
#include "src/__support/OSUtil/io.h"
-#include "src/__support/common.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
#include "src/stdlib/abort.h"
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/stdlib/abort_handler_s.cpp b/libc/src/stdlib/abort_handler_s.cpp
index 85a4cd4858315..5b9f9cda6018e 100644
--- a/libc/src/stdlib/abort_handler_s.cpp
+++ b/libc/src/stdlib/abort_handler_s.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/stdlib/abort_handler_s.h"
+#include "abort_handler_s.h"
#include "src/__support/annex_k/abort_handler_s.h"
namespace LIBC_NAMESPACE_DECL {
More information about the libc-commits
mailing list