增加__attribute__((constructor))支持

This commit is contained in:
zhangzheng
2023-11-18 23:40:56 +08:00
parent 1e384bee71
commit 3a70b7d297
9 changed files with 13 additions and 10 deletions

View File

@@ -9,8 +9,10 @@
#include <u_env.h>
#include <sys/uio.h>
#include <assert.h>
#include <u_util.h>
#include "fd_map.h"
AUTO_CALL(101)
void fs_backend_init(void)
{
assert(fd_map_alloc(0, 0, FD_TTY) >= 0);

View File

@@ -79,9 +79,13 @@ __init_libc(char **envp, char *pn)
static void libc_start_init(void)
{
_init();
extern void *app_start_addr;
unsigned long start_addr = ((unsigned long)app_start_addr) & (~3UL);
uintptr_t a = (uintptr_t)&__init_array_start;
for (; a < (uintptr_t)&__init_array_end; a += sizeof(void (*)()))
(*(void (**)(void))a)();
for (; a < (uintptr_t)&__init_array_end; a += sizeof(void (*)())) {
((void (*)(void))((uintptr_t)(*(void (**)(void))a) + start_addr | 0x1UL))();
}
}
weak_alias(libc_start_init, __libc_start_init);

View File

@@ -11,4 +11,5 @@
#define ROUND_UP(a, b) ROUND(a, b) //!< a除b向上取整数
#define ROUND_DOWN(a, b) ((a) / (b)) //!< a/b向下取整
#define ATTR_ALIGN(a) __attribute__((aligned(a)))
#define ATTR_ALIGN(a) __attribute__((aligned(a)))
#define AUTO_CALL(prio) __attribute__((constructor(prio)))

View File

@@ -5,6 +5,7 @@
#include "u_mm.h"
#include "u_sleep.h"
AUTO_CALL(101)
int u_drv_init(void)
{
msg_tag_t tag;

View File

@@ -35,7 +35,6 @@ void music2_send_bytes(u8 *bytes, int len)
void drv_init(void)
{
u_drv_init();
led_init();
relay_init();
IIC_Init();

View File

@@ -13,7 +13,6 @@ int main(int args, char *argv[])
obj_handler_t ipc_hd;
int ret;
u_drv_init();
ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);
assert(ret >= 0);
ns_register("/dev", ipc_hd);

View File

@@ -40,11 +40,11 @@ target_link_libraries(
rtthread_drv.elf
PUBLIC
start
muslc
--whole-archive
sys
sys_util
sys_svr
muslc
--whole-archive
src
drivers
stm32f103_onenet_nbiot

View File

@@ -11,9 +11,7 @@ extern void rt_hw_board_init(void);
extern int dfs_init(void);
int main(void)
{
fs_backend_init();
printf("test\n");
u_drv_init();
/* init board */
rt_hw_board_init();
dfs_init();

View File

@@ -14,7 +14,6 @@ static MKFS_PARM defopt = {FM_ANY, 0, 0, 0};
int main(int args, char *argv[])
{
u_drv_init();
obj_handler_t ipc_hd;
int ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd);
assert(ret >= 0);