From bdd663a33fb0af8864344a7bf568a706669d96d4 Mon Sep 17 00:00:00 2001 From: "Man, Jianting (Meco)" <920369182@qq.com> Date: Tue, 22 Nov 2022 21:40:50 -0500 Subject: [libc][musl] support arm-linux-musleabi toolchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 目前基本功能已经可以在QEMU上跑起来,但是pthread和内核signal选中会报冲突。先合并一版本,后续解决这些问题。 --- .../libc/compilers/common/include/sys/select.h | 2 +- .../libc/compilers/common/include/sys/signal.h | 15 ++++------ .../libc/compilers/common/include/sys/time.h | 31 ++++++++++---------- components/libc/compilers/musl/SConscript | 30 ++++++++++++++++++++ components/libc/compilers/musl/syscalls.c | 20 +++++++++++++ components/libc/compilers/newlib/SConscript | 33 +++++++++++----------- 6 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 components/libc/compilers/musl/SConscript create mode 100644 components/libc/compilers/musl/syscalls.c (limited to 'components/libc/compilers') diff --git a/components/libc/compilers/common/include/sys/select.h b/components/libc/compilers/common/include/sys/select.h index 9004658be9..32ce39c287 100644 --- a/components/libc/compilers/common/include/sys/select.h +++ b/components/libc/compilers/common/include/sys/select.h @@ -12,7 +12,7 @@ #ifndef __SYS_SELECT_H__ #define __SYS_SELECT_H__ -#include +#include #include #include diff --git a/components/libc/compilers/common/include/sys/signal.h b/components/libc/compilers/common/include/sys/signal.h index dbd947acb9..b92276ecb1 100644 --- a/components/libc/compilers/common/include/sys/signal.h +++ b/components/libc/compilers/common/include/sys/signal.h @@ -14,12 +14,11 @@ #ifdef __cplusplus extern "C" { -#endif +#endif /* __cplusplus */ #include #include - /* sigev_notify values NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */ @@ -54,7 +53,6 @@ struct siginfo { uint16_t si_signo; uint16_t si_code; - union sigval si_value; }; typedef struct siginfo siginfo_t; @@ -216,17 +214,16 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #define SIGUSR2 31 /* user defined signal 2 */ #define NSIG 32 /* signal 0 implied */ -#ifndef _SIGNAL_H_ +#if defined(RT_USING_NEWLIBC) /* Some applications take advantage of the fact that * and are equivalent in glibc. Allow for that here. */ #include -#endif - -#endif +#endif /* defined(RT_USING_NEWLIBC) */ +#endif /* __ARMCC_VERSION */ #ifdef __cplusplus } -#endif +#endif /* __cplusplus */ -#endif +#endif /* __SYS_SIGNAL_H__ */ diff --git a/components/libc/compilers/common/include/sys/time.h b/components/libc/compilers/common/include/sys/time.h index 346320bff0..e3bf3ee4ef 100644 --- a/components/libc/compilers/common/include/sys/time.h +++ b/components/libc/compilers/common/include/sys/time.h @@ -22,7 +22,7 @@ typedef __time64_t time_t; #ifdef __cplusplus extern "C" { -#endif +#endif /* __cplusplus */ #undef CLOCKS_PER_SEC #define CLOCKS_PER_SEC RT_TICK_PER_SECOND @@ -79,22 +79,21 @@ int stime(const time_t *t); time_t timegm(struct tm * const t); int gettimeofday(struct timeval *tv, struct timezone *tz); int settimeofday(const struct timeval *tv, const struct timezone *tz); -#if defined(__ARMCC_VERSION) || defined (__ICCARM__) + +#if defined(__ARMCC_VERSION) || defined (__ICCARM__) || defined(_WIN32) struct tm *gmtime_r(const time_t *timep, struct tm *r); -struct tm* localtime_r(const time_t* t, struct tm* r); char* asctime_r(const struct tm *t, char *buf); char *ctime_r(const time_t * tim_p, char * result); -#elif defined(_WIN32) -struct tm* gmtime_r(const time_t* timep, struct tm* r); -struct tm* gmtime(const time_t* t); struct tm* localtime_r(const time_t* t, struct tm* r); +#endif /* defined(__ARMCC_VERSION) || defined (__ICCARM__) || defined(_WIN32) */ + +#ifdef _WIN32 +struct tm* gmtime(const time_t* t); struct tm* localtime(const time_t* t); time_t mktime(struct tm* const t); -char* asctime_r(const struct tm* t, char* buf); -char* ctime_r(const time_t* tim_p, char* result); char* ctime(const time_t* tim_p); time_t time(time_t* t); -#endif +#endif /* _WIN32 */ #ifdef RT_USING_POSIX_DELAY int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); @@ -112,20 +111,21 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); #ifndef CLOCK_REALTIME #define CLOCK_REALTIME 1 -#endif +#endif /* CLOCK_REALTIME */ #define CLOCK_CPUTIME_ID 2 #ifndef CLOCK_PROCESS_CPUTIME_ID #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID -#endif +#endif /* CLOCK_PROCESS_CPUTIME_ID */ + #ifndef CLOCK_THREAD_CPUTIME_ID #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID -#endif +#endif /* CLOCK_THREAD_CPUTIME_ID */ #ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC 4 -#endif +#endif /* CLOCK_MONOTONIC */ #endif /* defined(RT_USING_POSIX_CLOCK) || defined (RT_USING_POSIX_TIMER) */ #ifdef RT_USING_POSIX_CLOCK @@ -142,8 +142,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid); int timer_delete(timer_t timerid); int timer_getoverrun(timer_t timerid); int timer_gettime(timer_t timerid, struct itimerspec *its); -int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, - struct itimerspec *ovalue); +int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue); #endif /* RT_USING_POSIX_TIMER */ /* timezone */ @@ -153,6 +152,6 @@ int8_t tz_is_dst(void); #ifdef __cplusplus } -#endif +#endif /* __cplusplus */ #endif /* _SYS_TIME_H_ */ diff --git a/components/libc/compilers/musl/SConscript b/components/libc/compilers/musl/SConscript new file mode 100644 index 0000000000..9bc5696157 --- /dev/null +++ b/components/libc/compilers/musl/SConscript @@ -0,0 +1,30 @@ +import os +from building import * +from gcc import * +Import('rtconfig') + +group = [] + +libc_name, libc_version = GetGCCLibcNameVersion(rtconfig) + +if libc_name == 'musl': + print('Musl version: ' + libc_version) + + cwd = GetCurrentDir() + src = Glob('*.c') + + CPPPATH = [cwd] + CPPDEFINES = ['RT_USING_MUSLLIBC', 'RT_USING_LIBC'] + LIBS = ['c', 'gcc'] + LINKFLAGS = ' --specs=kernel.specs' + AddDepend(['RT_USING_MUSLLIBC', 'RT_USING_LIBC']) + + group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, LINKFLAGS = LINKFLAGS, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + + list = os.listdir(cwd) + for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + group = group + SConscript(os.path.join(d, 'SConscript')) + +Return('group') diff --git a/components/libc/compilers/musl/syscalls.c b/components/libc/compilers/musl/syscalls.c new file mode 100644 index 0000000000..6d412cc0a1 --- /dev/null +++ b/components/libc/compilers/musl/syscalls.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-11-18 Meco Man first version + */ + +#include + +int *__errno_location(void) +{ + return _rt_errno(); +} +int *___errno_location(void) +{ + return _rt_errno(); +} diff --git a/components/libc/compilers/newlib/SConscript b/components/libc/compilers/newlib/SConscript index dd8966d5bd..14d3f737f5 100644 --- a/components/libc/compilers/newlib/SConscript +++ b/components/libc/compilers/newlib/SConscript @@ -3,28 +3,27 @@ from building import * from gcc import * Import('rtconfig') -src = [] -cwd = GetCurrentDir() group = [] -LIBS = [] -CPPPATH = [cwd] -if rtconfig.PLATFORM in ['gcc']: - LIBS += ['c', 'm'] # link libc and libm - src += Glob('*.c') +libc_name, libc_version = GetGCCLibcNameVersion(rtconfig) - #report newlib version - print('Newlib version:' + GetNewLibVersion(rtconfig)) +if libc_name == 'newlib': + print('Newlib version: ' + libc_version) - # identify this is Newlib, and only enable POSIX.1-1990 - CPPDEFINES = ['RT_USING_NEWLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1'] + cwd = GetCurrentDir() + src = Glob('*.c') + + CPPPATH = [cwd] + CPPDEFINES = ['RT_USING_NEWLIBC', 'RT_USING_LIBC', '_POSIX_C_SOURCE=1'] # identify this is Newlib, and only enable POSIX.1-1990 + LIBS = ['c', 'm'] # link libc and libm AddDepend(['RT_USING_NEWLIBC', 'RT_USING_LIBC']) - group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) -list = os.listdir(cwd) -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - group = group + SConscript(os.path.join(d, 'SConscript')) + group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + + list = os.listdir(cwd) + for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + group = group + SConscript(os.path.join(d, 'SConscript')) Return('group') -- cgit v1.3.1