优化可执行文件体积
This commit is contained in:
68
mkrtos_user/lib/libc_backend/src/be_exit.c
Normal file
68
mkrtos_user/lib/libc_backend/src/be_exit.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "u_ipc.h"
|
||||
#include "u_types.h"
|
||||
#include "u_factory.h"
|
||||
#include "u_thread.h"
|
||||
#include "u_task.h"
|
||||
#include "u_hd_man.h"
|
||||
#include "u_log.h"
|
||||
#include "pm_cli.h"
|
||||
#include "u_sig.h"
|
||||
#include "futex_queue.h"
|
||||
#include "u_ipc.h"
|
||||
#include "u_sys.h"
|
||||
#include "u_futex.h"
|
||||
#include <futex.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread_impl.h>
|
||||
#include <atomic.h>
|
||||
#define FUTEX_WAKE_CLEAR 10
|
||||
|
||||
void be_exit(long exit_code)
|
||||
{
|
||||
struct pthread *pt = __pthread_self();
|
||||
int th_hd = pt->hd;
|
||||
int *old_ctid = (int *)(pt->ctid);
|
||||
|
||||
if (th_hd != THREAD_MAIN)
|
||||
{
|
||||
if (old_ctid)
|
||||
{
|
||||
be_futex(old_ctid, FUTEX_WAKE_CLEAR, 1, 0, 0, 0);
|
||||
}
|
||||
if (pthread_cnt_dec() == 1)
|
||||
{
|
||||
/*删除整个进程*/
|
||||
goto del_task;
|
||||
}
|
||||
else
|
||||
{
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th_hd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
umword_t pid;
|
||||
del_task:
|
||||
/*TODO:删除其它东西*/
|
||||
|
||||
task_get_pid(TASK_THIS, &pid);
|
||||
pm_kill_task(pid, KILL_SIG);
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); //!< 删除当前task,以及申请得所有对象
|
||||
a_crash(); //!< 强制退出
|
||||
}
|
||||
}
|
||||
|
||||
void sys_exit(va_list ap)
|
||||
{
|
||||
long exit_code;
|
||||
|
||||
ARG_1_BE(ap, exit_code, long);
|
||||
be_exit(exit_code);
|
||||
}
|
||||
|
||||
0
mkrtos_user/lib/libc_backend/src/pthread_backend.c
Normal file
0
mkrtos_user/lib/libc_backend/src/pthread_backend.c
Normal file
@@ -119,46 +119,4 @@ int be_clone(int (*func)(void *), void *stack, int flags, void *args, pid_t *pti
|
||||
|
||||
return 0;
|
||||
}
|
||||
#define FUTEX_WAKE_CLEAR 10
|
||||
|
||||
void be_exit(long exit_code)
|
||||
{
|
||||
struct pthread *pt = __pthread_self();
|
||||
int th_hd = pt->hd;
|
||||
int *old_ctid = (int *)(pt->ctid);
|
||||
|
||||
if (th_hd != THREAD_MAIN)
|
||||
{
|
||||
if (old_ctid)
|
||||
{
|
||||
be_futex(old_ctid, FUTEX_WAKE_CLEAR, 1, 0, 0, 0);
|
||||
}
|
||||
if (pthread_cnt_dec() == 1)
|
||||
{
|
||||
/*删除整个进程*/
|
||||
goto del_task;
|
||||
}
|
||||
else
|
||||
{
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, th_hd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
umword_t pid;
|
||||
del_task:
|
||||
/*TODO:删除其它东西*/
|
||||
|
||||
task_get_pid(TASK_THIS, &pid);
|
||||
pm_kill_task(pid, KILL_SIG);
|
||||
task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); //!< 删除当前task,以及申请得所有对象
|
||||
a_crash(); //!< 强制退出
|
||||
}
|
||||
}
|
||||
void sys_exit(va_list ap)
|
||||
{
|
||||
long exit_code;
|
||||
|
||||
ARG_1_BE(ap, exit_code, long);
|
||||
be_exit(exit_code);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,6 @@ int __libc_start_main(int (*main)(int, char **, char **), int argc, char **argv,
|
||||
* are used to prevent the stack frame used during init from
|
||||
* persisting for the entire process lifetime. */
|
||||
__init_libc(envp, argv[0]);
|
||||
// cons_active();
|
||||
sig_init();
|
||||
|
||||
/* Barrier against hoisting application code or anything using ssp
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cons_cli.h>
|
||||
static char *itoa(char *p, unsigned x) {
|
||||
p += 3*sizeof(int);
|
||||
*--p = 0;
|
||||
do {
|
||||
*--p = '0' + x % 10;
|
||||
x /= 10;
|
||||
} while (x);
|
||||
return p;
|
||||
}
|
||||
_Noreturn void __assert_fail(const char *expr, const char *file, int line, const char *func)
|
||||
{
|
||||
fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
|
||||
char data[12];
|
||||
// fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
|
||||
cons_write_str("Assertion failed:");
|
||||
cons_write_str(expr);
|
||||
cons_write_str(file);
|
||||
cons_write_str(func);
|
||||
itoa(data, line);
|
||||
cons_write_str(data);
|
||||
cons_write_str("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ target_link_libraries(
|
||||
muslc
|
||||
cpio
|
||||
)
|
||||
set_target_properties(sys_util PROPERTIES LINK_FLAGS "-pie ")
|
||||
add_dependencies(sys_util sys)
|
||||
add_dependencies(sys_util muslc)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "u_task.h"
|
||||
#include "u_hd_man.h"
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#define HANDLER_START_INX 10 //!< fd开始的值,前10个内核保留
|
||||
#define HANDLER_MAX_NR (HANDLER_START_INX + \
|
||||
(CONFIG_OBJ_MAP_ENTRY_SIZE) * (CONFIG_OBJ_MAP_TAB_SIZE)) //!< 单个task最大支持的hd数量
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "rpc_prot.h"
|
||||
#include "u_err.h"
|
||||
#include "u_rpc_buf.h"
|
||||
#include "cons_cli.h"
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
@@ -79,7 +80,7 @@ static msg_tag_t rpc_meta_t_dispatch(struct rpc_svr_obj *obj, msg_tag_t in_tag,
|
||||
|
||||
if (msg_tag_get_prot(in_tag) == META_PROT)
|
||||
{
|
||||
printf("unknow prot.\n");
|
||||
cons_write_str("unknow prot.\n");
|
||||
return msg_tag_init4(0, 0, 0, -EPROTO);
|
||||
}
|
||||
else
|
||||
@@ -89,13 +90,13 @@ static msg_tag_t rpc_meta_t_dispatch(struct rpc_svr_obj *obj, msg_tag_t in_tag,
|
||||
|
||||
if (svr_obj == NULL)
|
||||
{
|
||||
printf("unknow prot.\n");
|
||||
cons_write_str("unknow prot.\n");
|
||||
|
||||
return msg_tag_init4(0, 0, 0, -EPROTO);
|
||||
}
|
||||
if (svr_obj->dispatch == NULL)
|
||||
{
|
||||
printf("unknow dispatch.\n");
|
||||
cons_write_str("unknow dispatch.\n");
|
||||
return msg_tag_init4(0, 0, 0, -EPROTO);
|
||||
}
|
||||
msg = svr_obj->dispatch(svr_obj, in_tag, ipc_msg);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <u_sig.h>
|
||||
#include <pm_cli.h>
|
||||
#include <rpc_prot.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
static sig_call_back sig_cb_func;
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
|
||||
-fPIC -n -pie -fpie -fpic -msingle-pic-base -mno-pic-data-is-text-relative \
|
||||
-D__dietlibc__ -D__arm__ -D__WORDSIZE=32 -D__ARM_ARCH_7M__ \
|
||||
" )
|
||||
set(CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS})
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " )
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ")
|
||||
|
||||
file(GLOB_RECURSE deps *.c *.S)
|
||||
add_library(
|
||||
@@ -36,6 +32,7 @@ target_link_libraries(
|
||||
muslc
|
||||
cpio
|
||||
)
|
||||
set_target_properties(util PROPERTIES LINK_FLAGS "-pie ")
|
||||
add_dependencies(util sys)
|
||||
add_dependencies(util muslc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user