Skip to content

Commit 92b18c5

Browse files
committed
add default handlers
1 parent 80586f1 commit 92b18c5

File tree

11 files changed

+133
-56
lines changed

11 files changed

+133
-56
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,8 @@ if(LLVM_LIBC_FULL_BUILD)
11681168
libc.src.stdlib.getenv
11691169
libc.src.stdlib.quick_exit
11701170
libc.src.stdlib.set_constraint_handler_s
1171+
libc.src.stdlib.abort_handler_s
1172+
libc.src.stdlib.ignore_handler_s
11711173

11721174
# signal.h entrypoints
11731175
libc.src.signal.kill

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
3131
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
3232
endif()
3333

34+
add_macro_header(
35+
annex_k_macros
36+
HDR
37+
annex-k-macros.h
38+
)
39+
3440
add_macro_header(
3541
assert_macros
3642
HDR
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Definition of macros to be used with Annex K functions ------------===//
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_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H
10+
#define LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H
11+
12+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && \
13+
defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
14+
15+
#define LIBC_HAS_ANNEX_K
16+
17+
#endif
18+
19+
#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H

libc/src/__support/annex_k/CMakeLists.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
add_header_library(
2-
abort_handler_s
3-
HDRS
4-
abort_handler_s.h
5-
DEPENDS
6-
libc.hdr.stdio_macros
7-
libc.hdr.types.errno_t
8-
libc.src.__support.macros.config
9-
libc.src.__support.macros.attributes
10-
libc.src.__support.File.file
11-
libc.src.__support.OSUtil.io
12-
)
13-
14-
add_header_library(
15-
ignore_handler_s
16-
HDRS
17-
ignore_handler_s.h
18-
DEPENDS
19-
libc.hdr.types.errno_t
20-
libc.src.__support.libc_errno
21-
libc.src.__support.macros.config
22-
libc.src.__support.macros.attributes
23-
)
24-
251
add_header_library(
262
helper_macros
273
HDRS

libc/src/__support/annex_k/libc_constraint_handler.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_LIBC_CONSTRAINT_HANDER_H
10-
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_LIBC_CONSTRAINT_HANDER_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_LIBC_CONSTRAINT_HANDLER_H
10+
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_LIBC_CONSTRAINT_HANDLER_H
1111

12-
#include "abort_handler_s.h"
1312
#include "hdr/types/constraint_handler_t.h"
13+
#include "src/__support/common.h"
14+
#include "src/stdlib/abort_handler_s.h"
1415

1516
namespace LIBC_NAMESPACE_DECL {
1617

@@ -19,4 +20,4 @@ LIBC_INLINE static constraint_handler_t libc_constraint_handler =
1920

2021
}
2122

22-
#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_LIBC_CONSTRAINT_HANDER_H
23+
#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_LIBC_CONSTRAINT_HANDLER_H

libc/src/stdlib/CMakeLists.txt

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,49 @@ add_entrypoint_object(
660660
HDRS
661661
set_constraint_handler_s.h
662662
DEPENDS
663-
libc.src.__support.annex_k.abort_handler_s
663+
.abort_handler_s
664664
libc.src.__support.annex_k.libc_constraint_handler
665665
libc.src.__support.macros.config
666666
)
667+
668+
add_entrypoint_object(
669+
abort_handler_s
670+
SRCS
671+
abort_handler_s.cpp
672+
HDRS
673+
abort_handler_s.h
674+
DEPENDS
675+
libc.hdr.stdio_macros
676+
libc.hdr.types.errno_t
677+
libc.src.__support.macros.config
678+
libc.src.__support.macros.attributes
679+
libc.src.__support.File.file
680+
)
681+
682+
add_header_library(
683+
libc_constraint_handler
684+
HDRS
685+
libc_constraint_handler.h
686+
DEPENDS
687+
.abort_handler_s
688+
libc.hdr.types.constraint_handler_t
689+
)
690+
691+
add_header_library(
692+
annex_k_helper_macros
693+
HDRS
694+
annex_k_helper_macros.h
695+
)
696+
697+
add_entrypoint_object(
698+
ignore_handler_s
699+
HDRS
700+
ignore_handler_s.h
701+
SRCS
702+
ignore_handler_s.cpp
703+
DEPENDS
704+
libc.hdr.types.errno_t
705+
libc.src.__support.libc_errno
706+
libc.src.__support.macros.config
707+
libc.src.__support.macros.attributes
708+
)
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
1-
//===-- Implementation header for abort_handler_s ---------------*- C++ -*-===//
1+
//===-- Implementation for abort_handler_s ----------------------*- 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-
#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
10-
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
11-
9+
#include "src/stdlib/abort_handler_s.h"
1210
#include "hdr/stdio_macros.h"
1311
#include "hdr/types/errno_t.h"
12+
#include "src/__support/common.h"
1413
#include "src/__support/libc_errno.h"
15-
#include "src/__support/macros/attributes.h"
16-
#include "src/__support/macros/config.h"
17-
#include "src/__support/OSUtil/io.h"
14+
#include <stdio.h>
1815
#include <stdlib.h>
1916

2017
namespace LIBC_NAMESPACE_DECL {
2118

22-
LIBC_INLINE static void abort_handler_s(const char *__restrict msg,
23-
[[maybe_unused]] void *__restrict ptr,
24-
errno_t error) {
19+
LLVM_LIBC_FUNCTION(void, abort_handler_s,
20+
(const char *__restrict msg,
21+
[[maybe_unused]] void *__restrict ptr, errno_t error)) {
2522
libc_errno = error;
26-
write_to_stderr("abort_handler_s was called in response to a "
23+
fprintf(stderr, "abort_handler_s was called in response to a "
2724
"runtime-constraint violation.\n\n");
28-
if (msg) {
29-
write_to_stderr(msg);
30-
write_to_stderr("\n");
31-
}
32-
33-
write_to_stderr(
25+
if (msg)
26+
fprintf(stderr, "%s\n", msg);
27+
fprintf(stderr,
3428
"\n\nNote to end users: This program was terminated as a result\
3529
of a bug present in the software. Please reach out to your \
3630
software's vendor to get more help.\n");
3731

32+
fflush(stderr);
33+
3834
abort();
3935
}
4036

4137
} // namespace LIBC_NAMESPACE_DECL
42-
43-
#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H

libc/src/stdlib/abort_handler_s.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for abort_handler_s ---------------*- 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_STDLIB_ABORT_HANDLER_S_H
10+
#define LLVM_LIBC_SRC_STDLIB_ABORT_HANDLER_S_H
11+
12+
#include "hdr/types/errno_t.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
void abort_handler_s(const char *__restrict msg, void *__restrict ptr,
18+
errno_t error);
19+
20+
} // namespace LIBC_NAMESPACE_DECL
21+
22+
#endif // LLVM_LIBC_SRC_STDLIB_ABORT_HANDLER_S_H
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===-- Implementation header for ignore_handler_s --------------*- 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+
#include "src/stdlib/ignore_handler_s.h"
10+
11+
namespace LIBC_NAMESPACE_DECL {
12+
13+
LLVM_LIBC_FUNCTION(void, ignore_handler_s,
14+
(const char *__restrict, void *__restrict, errno_t)) {}
15+
16+
} // namespace LIBC_NAMESPACE_DECL

libc/src/__support/annex_k/ignore_handler_s.h renamed to libc/src/stdlib/ignore_handler_s.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_ANNEX_K_IGNORE_HANDLER_S_H
10-
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_IGNORE_HANDLER_S_H
9+
#ifndef LLVM_LIBC_SRC_STDLIB_IGNORE_HANDLER_S_H
10+
#define LLVM_LIBC_SRC_STDLIB_IGNORE_HANDLER_S_H
1111

1212
#include "hdr/types/errno_t.h"
13-
#include "src/__support/macros/attributes.h"
14-
#include "src/__support/macros/config.h"
13+
#include "src/__support/common.h"
1514

1615
namespace LIBC_NAMESPACE_DECL {
1716

18-
LIBC_INLINE static void ignore_handler_s(const char *__restrict msg,
19-
void *__restrict ptr, errno_t error) {}
17+
void ignore_handler_s(const char *__restrict msg, void *__restrict ptr,
18+
errno_t error);
2019

2120
} // namespace LIBC_NAMESPACE_DECL
2221

23-
#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_IGNORE_HANDLER_S_H
22+
#endif // LLVM_LIBC_SRC_STDLIB_IGNORE_HANDLER_S_H

0 commit comments

Comments
 (0)