forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Provide __libc_{init,fini}_array for baremetal (llvm#90828)
These are provided by newlib and many baremetal projects assume they're available rather than providing their own implementation.
- Loading branch information
Showing
6 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_entrypoint_object( | ||
init | ||
SRCS | ||
init.cpp | ||
) | ||
|
||
add_entrypoint_object( | ||
fini | ||
SRCS | ||
fini.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===-- Implementation file of __libc_fini_array --------------------------===// | ||
// | ||
// 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 <stddef.h> | ||
#include <stdint.h> | ||
|
||
extern "C" { | ||
extern uintptr_t __fini_array_start[]; | ||
extern uintptr_t __fini_array_end[]; | ||
} | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
using FiniCallback = void(void); | ||
|
||
extern "C" void __libc_fini_array(void) { | ||
size_t fini_array_size = __fini_array_end - __fini_array_start; | ||
for (size_t i = fini_array_size; i > 0; --i) | ||
reinterpret_cast<FiniCallback *>(__fini_array_start[i - 1])(); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//===-- Implementation file of __libc_init_array --------------------------===// | ||
// | ||
// 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 <stddef.h> | ||
#include <stdint.h> | ||
|
||
extern "C" { | ||
extern uintptr_t __preinit_array_start[]; | ||
extern uintptr_t __preinit_array_end[]; | ||
extern uintptr_t __init_array_start[]; | ||
extern uintptr_t __init_array_end[]; | ||
} | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
using InitCallback = void(void); | ||
|
||
extern "C" void __libc_init_array(void) { | ||
size_t preinit_array_size = __preinit_array_end - __preinit_array_start; | ||
for (size_t i = 0; i < preinit_array_size; ++i) | ||
reinterpret_cast<InitCallback *>(__preinit_array_start[i])(); | ||
size_t init_array_size = __init_array_end - __init_array_start; | ||
for (size_t i = 0; i < init_array_size; ++i) | ||
reinterpret_cast<InitCallback *>(__init_array_start[i])(); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |