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 "src/__support/macros/config.h" |
10 | #include <stddef.h> |
11 | #include <stdint.h> |
12 | |
13 | namespace LIBC_NAMESPACE_DECL { |
14 | |
15 | extern "C"{ |
16 | extern uintptr_t __preinit_array_start[]; |
17 | extern uintptr_t __preinit_array_end[]; |
18 | extern uintptr_t __init_array_start[]; |
19 | extern uintptr_t __init_array_end[]; |
20 | } |
21 | |
22 | using InitCallback = void(void); |
23 | |
24 | extern "C"void __libc_init_array(void) { |
25 | size_t preinit_array_size = __preinit_array_end - __preinit_array_start; |
26 | for (size_t i = 0; i < preinit_array_size; ++i) |
27 | reinterpret_cast<InitCallback *>(__preinit_array_start[i])(); |
28 | size_t init_array_size = __init_array_end - __init_array_start; |
29 | for (size_t i = 0; i < init_array_size; ++i) |
30 | reinterpret_cast<InitCallback *>(__init_array_start[i])(); |
31 | } |
32 | |
33 | } // namespace LIBC_NAMESPACE_DECL |
34 |