libc库增加tiny模式,最小体积更小
This commit is contained in:
@@ -110,4 +110,4 @@ CONFIG_RT_USING_PIN=y
|
|||||||
CONFIG_CPU_TYPE="stm32f1"
|
CONFIG_CPU_TYPE="stm32f1"
|
||||||
CONFIG_RTT_DIR="./"
|
CONFIG_RTT_DIR="./"
|
||||||
CONFIG_ARCH="cortex-m3"
|
CONFIG_ARCH="cortex-m3"
|
||||||
CONFIG_KNL_EXRAM=y
|
CONFIG_KNL_EXRAM=n
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ crt/*.S
|
|||||||
crt/*.s)
|
crt/*.s)
|
||||||
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start_init.S)
|
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start_init.S)
|
||||||
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start.S)
|
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start.S)
|
||||||
|
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start_tiny.S)
|
||||||
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/ldso/dlstart.c)
|
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/ldso/dlstart.c)
|
||||||
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/ldso/dynlink.c)
|
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/ldso/dynlink.c)
|
||||||
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/rcrt1.c)
|
list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/rcrt1.c)
|
||||||
|
|
||||||
add_library(start_init ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start_init.S)
|
add_library(start_init ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start_init.S)
|
||||||
add_library(start ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start.S)
|
add_library(start ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start.S)
|
||||||
|
add_library(start_tiny ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/mlibc/crt/start_tiny.S)
|
||||||
|
|
||||||
add_library(muslc ${deps})
|
add_library(muslc ${deps})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
|
|||||||
21
mkrtos_user/lib/mlibc/crt/crt1_tiny.c
Normal file
21
mkrtos_user/lib/mlibc/crt/crt1_tiny.c
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <features.h>
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
#define START "_start"
|
||||||
|
|
||||||
|
// #include "crt_arch.h"
|
||||||
|
|
||||||
|
int main();
|
||||||
|
weak void _init();
|
||||||
|
weak void _fini();
|
||||||
|
int __libc_start_main_tiny(int (*main)(int, char **, char **), int argc, char **argv,
|
||||||
|
void (*init_dummy)(), void (*fini_dummy)());
|
||||||
|
extern void *app_start_addr;
|
||||||
|
void _start_tiny_init(long *p, void *start_addr)
|
||||||
|
{
|
||||||
|
int argc = p[0];
|
||||||
|
char **argv = (void *)(p + 1);
|
||||||
|
|
||||||
|
app_start_addr = start_addr; // ATShining add.
|
||||||
|
__libc_start_main_tiny(main, argc, argv, _init, _fini);
|
||||||
|
}
|
||||||
61
mkrtos_user/lib/mlibc/crt/start_tiny.S
Normal file
61
mkrtos_user/lib/mlibc/crt/start_tiny.S
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
.syntax unified
|
||||||
|
.section .first
|
||||||
|
|
||||||
|
.globl reloc
|
||||||
|
|
||||||
|
.align 2
|
||||||
|
.globl _start_
|
||||||
|
.type _start_, %function
|
||||||
|
_start_:
|
||||||
|
/*save r0 */
|
||||||
|
mov r12, r0
|
||||||
|
b __start
|
||||||
|
.SPACE 32 - (. - _start_)
|
||||||
|
_head_start:
|
||||||
|
.ascii "MKRTOS. "
|
||||||
|
.word __ram_size__
|
||||||
|
heap_offset: .word __heap_start__ - _start_
|
||||||
|
stack_offset: .word __stack_start__ - _start_
|
||||||
|
heap_size: .word __heap_size__
|
||||||
|
stack_size: .word __stack_size__
|
||||||
|
data_offset: .word __data_start__ - _start_
|
||||||
|
|
||||||
|
.word __bss_start__ - _start_
|
||||||
|
got_start: .word __got_start__
|
||||||
|
got_end: .word __got_end__
|
||||||
|
rel_start: .word __rel_start__
|
||||||
|
rel_end: .word __rel_end__
|
||||||
|
text_start: .word __text_start__
|
||||||
|
.SPACE 128 - (. - _start_)
|
||||||
|
|
||||||
|
.align
|
||||||
|
__start:
|
||||||
|
|
||||||
|
movs r1, #0
|
||||||
|
adr r2, _start_
|
||||||
|
bic r2, r2, #1
|
||||||
|
ldr r0, = __data_start__
|
||||||
|
add r0, r0, r2
|
||||||
|
ldr r3, = __data_end__
|
||||||
|
add r3, r3, r2
|
||||||
|
b LoopCopyDataInit
|
||||||
|
CopyDataInit:
|
||||||
|
ldr r2, [r0, r1]
|
||||||
|
str r2, [r9, r1]
|
||||||
|
adds r1, r1, #4
|
||||||
|
LoopCopyDataInit:
|
||||||
|
adds r2, r0, r1
|
||||||
|
cmp r2, r3
|
||||||
|
bcc CopyDataInit
|
||||||
|
|
||||||
|
mov r0, r9
|
||||||
|
adr r1, _start_
|
||||||
|
bic r1, r1, #1
|
||||||
|
bl _reloc
|
||||||
|
|
||||||
|
@ pop {r0, r12}
|
||||||
|
mov r0, sp
|
||||||
|
adr r1, _start_
|
||||||
|
bl _start_tiny_init
|
||||||
|
b .
|
||||||
|
.end
|
||||||
50
mkrtos_user/lib/mlibc/src/env/__libc_start_main_tiny.c
vendored
Normal file
50
mkrtos_user/lib/mlibc/src/env/__libc_start_main_tiny.c
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include <elf.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
static size_t fake_auxv[20];
|
||||||
|
#define AUX_CNT 38
|
||||||
|
|
||||||
|
int __libc_start_main_tiny(int (*main)(int, char **, char **), int argc, char **argv,
|
||||||
|
void (*init_dummy)(), void (*fini_dummy)())
|
||||||
|
{
|
||||||
|
char **envp = argv + argc + 1;
|
||||||
|
|
||||||
|
size_t i, *auxv, aux[AUX_CNT] = {0};
|
||||||
|
for (i = 0; envp[i]; i++)
|
||||||
|
;
|
||||||
|
libc.auxv = auxv = (void *)(envp + i + 1);
|
||||||
|
for (i = 0; auxv[i]; i += 2)
|
||||||
|
{
|
||||||
|
if (auxv[i] < AUX_CNT)
|
||||||
|
{
|
||||||
|
aux[auxv[i]] = auxv[i + 1];
|
||||||
|
}
|
||||||
|
else if (auxv[i] == 0xfe)
|
||||||
|
{
|
||||||
|
extern void u_env_init(void **in_env);
|
||||||
|
|
||||||
|
u_env_init((void *)auxv[i + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libc.page_size = 512;
|
||||||
|
libc.auxv = fake_auxv;
|
||||||
|
__init_tls(fake_auxv);
|
||||||
|
|
||||||
|
// _init();
|
||||||
|
extern void *app_start_addr;
|
||||||
|
extern weak hidden void (*const __init_array_start)(void), (*const __init_array_end)(void);
|
||||||
|
|
||||||
|
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))((uintptr_t)(*((unsigned long *)a)) + start_addr | 0x1UL))();
|
||||||
|
}
|
||||||
|
exit(main(0, NULL, 0));
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#define HEAP_SIZE 512
|
#define HEAP_SIZE 512
|
||||||
#define STACK_SIZE 1024 * 2
|
#define STACK_SIZE (2048)
|
||||||
|
|
||||||
#if defined(__CC_ARM)
|
#if defined(__CC_ARM)
|
||||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ add_custom_target(
|
|||||||
${CMAKE_SIZE} fatfs.elf
|
${CMAKE_SIZE} fatfs.elf
|
||||||
COMMAND
|
COMMAND
|
||||||
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
|
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
|
||||||
COMMAND
|
# COMMAND
|
||||||
cp fatfs.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/fatfs
|
# cp fatfs.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/fatfs
|
||||||
COMMAND
|
# COMMAND
|
||||||
cp fatfs.elf ${CMAKE_SOURCE_DIR}/build/output/fatfs.elf
|
# cp fatfs.elf ${CMAKE_SOURCE_DIR}/build/output/fatfs.elf
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(fatfs_dump fatfs.elf)
|
add_dependencies(fatfs_dump fatfs.elf)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ add_executable(hello.elf
|
|||||||
)
|
)
|
||||||
target_link_libraries(hello.elf
|
target_link_libraries(hello.elf
|
||||||
PUBLIC
|
PUBLIC
|
||||||
start
|
start_tiny
|
||||||
muslc
|
muslc
|
||||||
sys
|
sys
|
||||||
sys_util
|
sys_util
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
// #include <stdio.h>
|
||||||
|
#include <cons_cli.h>
|
||||||
int main(int argc, char *args[])
|
int main(int argc, char *args[])
|
||||||
{
|
{
|
||||||
printf("print test0.\n");
|
cons_write_str("Hello world.\n");
|
||||||
printf("print test1.\n");
|
// printf("print test0.\n");
|
||||||
printf("print test2.\n");
|
// printf("print test1.\n");
|
||||||
float a = 1.1;
|
// printf("print test2.\n");
|
||||||
float b = 1.2;
|
// float a = 1.1;
|
||||||
float c;
|
// float b = 1.2;
|
||||||
|
// float c;
|
||||||
|
|
||||||
while (1)
|
// while (1)
|
||||||
{
|
// {
|
||||||
c = a + b;
|
// c = a + b;
|
||||||
printf("%c %d %f\n", 'a', 1234, 1.1);
|
// printf("%c %d %f\n", 'a', 1234, 1.1);
|
||||||
printf("%c %d %lf\n", 'a', 1234, a * b);
|
// printf("%c %d %lf\n", 'a', 1234, a * b);
|
||||||
}
|
// }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#define HEAP_SIZE 2048
|
#define HEAP_SIZE 2048
|
||||||
#define STACK_SIZE 2048
|
#define STACK_SIZE (1024 + 256)
|
||||||
|
|
||||||
#if defined(__CC_ARM)
|
#if defined(__CC_ARM)
|
||||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||||
|
|||||||
@@ -91,10 +91,10 @@ add_custom_target(
|
|||||||
${CMAKE_SIZE} tcc.elf
|
${CMAKE_SIZE} tcc.elf
|
||||||
COMMAND
|
COMMAND
|
||||||
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
|
mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio
|
||||||
COMMAND
|
# COMMAND
|
||||||
cp tcc.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/tcc
|
# cp tcc.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/tcc
|
||||||
COMMAND
|
# COMMAND
|
||||||
cp tcc.elf ${CMAKE_SOURCE_DIR}/build/output/tcc.elf
|
# cp tcc.elf ${CMAKE_SOURCE_DIR}/build/output/tcc.elf
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(tcc_dump tcc.elf)
|
add_dependencies(tcc_dump tcc.elf)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
# -mfloat-abi=soft -u _printf_float
|
# -mfloat-abi=soft -u _printf_float
|
||||||
set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -lc -lrdimon -mfloat-abi=${FLOAT_TYPE} -u _printf_float -D=MKRTOS \
|
set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -Os -g3 -lc -lrdimon -mfloat-abi=${FLOAT_TYPE} -u _printf_float -D=MKRTOS \
|
||||||
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
|
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
|
||||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
||||||
-fno-stack-protector -Wl,--gc-sections \
|
-fno-stack-protector -Wl,--gc-sections \
|
||||||
|
|||||||
Reference in New Issue
Block a user