File tree Expand file tree Collapse file tree 6 files changed +78
-3
lines changed Expand file tree Collapse file tree 6 files changed +78
-3
lines changed Original file line number Diff line number Diff line change @@ -246,9 +246,6 @@ function(create_entrypoint_object fq_target_name)
246246 if (NOT ADD_ENTRYPOINT_OBJ_SRCS)
247247 message (FATAL_ERROR "`add_entrypoint_object` rule requires SRCS to be specified." )
248248 endif ()
249- if (NOT ADD_ENTRYPOINT_OBJ_HDRS)
250- message (FATAL_ERROR "`add_entrypoint_object` rule requires HDRS to be specified." )
251- endif ()
252249 if (NOT ADD_ENTRYPOINT_OBJ_CXX_STANDARD)
253250 set (ADD_ENTRYPOINT_OBJ_CXX_STANDARD ${CMAKE_CXX_STANDARD} )
254251 endif ()
Original file line number Diff line number Diff line change @@ -183,6 +183,10 @@ set(TARGET_LIBC_ENTRYPOINTS
183183
184184 # time.h entrypoints
185185 libc.src.time.difftime
186+
187+ # internal entrypoints
188+ libc.startup.baremetal.init
189+ libc.startup.baremetal.fini
186190)
187191
188192set(TARGET_LIBM_ENTRYPOINTS
Original file line number Diff line number Diff line change @@ -183,6 +183,10 @@ set(TARGET_LIBC_ENTRYPOINTS
183183
184184 # time.h entrypoints
185185 libc.src.time.difftime
186+
187+ # internal entrypoints
188+ libc.startup.baremetal.init
189+ libc.startup.baremetal.fini
186190)
187191
188192set(TARGET_LIBM_ENTRYPOINTS
Original file line number Diff line number Diff line change 1+ add_entrypoint_object(
2+ init
3+ SRCS
4+ init.cpp
5+ )
6+
7+ add_entrypoint_object(
8+ fini
9+ SRCS
10+ fini.cpp
11+ )
Original file line number Diff line number Diff line change 1+ // ===-- Implementation file of __libc_fini_array --------------------------===//
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 < stddef.h>
10+ #include < stdint.h>
11+
12+ extern " C" {
13+ extern uintptr_t __fini_array_start[];
14+ extern uintptr_t __fini_array_end[];
15+ }
16+
17+ namespace LIBC_NAMESPACE {
18+
19+ using FiniCallback = void (void );
20+
21+ extern " C" void __libc_fini_array (void ) {
22+ size_t fini_array_size = __fini_array_end - __fini_array_start;
23+ for (size_t i = fini_array_size; i > 0 ; --i)
24+ reinterpret_cast <FiniCallback *>(__fini_array_start[i - 1 ])();
25+ }
26+
27+ } // namespace LIBC_NAMESPACE
Original file line number Diff line number Diff line change 1+ // ===-- Implementation file of __libc_init_array --------------------------===//
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 < stddef.h>
10+ #include < stdint.h>
11+
12+ extern " C" {
13+ extern uintptr_t __preinit_array_start[];
14+ extern uintptr_t __preinit_array_end[];
15+ extern uintptr_t __init_array_start[];
16+ extern uintptr_t __init_array_end[];
17+ }
18+
19+ namespace LIBC_NAMESPACE {
20+
21+ using InitCallback = void (void );
22+
23+ extern " C" void __libc_init_array (void ) {
24+ size_t preinit_array_size = __preinit_array_end - __preinit_array_start;
25+ for (size_t i = 0 ; i < preinit_array_size; ++i)
26+ reinterpret_cast <InitCallback *>(__preinit_array_start[i])();
27+ size_t init_array_size = __init_array_end - __init_array_start;
28+ for (size_t i = 0 ; i < init_array_size; ++i)
29+ reinterpret_cast <InitCallback *>(__init_array_start[i])();
30+ }
31+
32+ } // namespace LIBC_NAMESPACE
You can’t perform that action at this time.
0 commit comments