mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-26 23:04:31 +08:00
[libc][musl] support arm-linux-musleabi toolchain
目前基本功能已经可以在QEMU上跑起来,但是pthread和内核signal选中会报冲突。先合并一版本,后续解决这些问题。
This commit is contained in:
@@ -762,7 +762,7 @@ RTM_EXPORT(telldir);
|
||||
* @param d the directory stream.
|
||||
* @param offset the offset in directory stream.
|
||||
*/
|
||||
void seekdir(DIR *d, off_t offset)
|
||||
void seekdir(DIR *d, long offset)
|
||||
{
|
||||
struct dfs_fd *fd;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef __SYS_SELECT_H__
|
||||
#define __SYS_SELECT_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtconfig.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
/* 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 <sys/signal.h>
|
||||
* and <signal.h> are equivalent in glibc. Allow for that here. */
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* defined(RT_USING_NEWLIBC) */
|
||||
#endif /* __ARMCC_VERSION */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
#endif /* __SYS_SIGNAL_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_ */
|
||||
|
||||
@@ -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')
|
||||
@@ -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 <rtthread.h>
|
||||
|
||||
int *__errno_location(void)
|
||||
{
|
||||
return _rt_errno();
|
||||
}
|
||||
int *___errno_location(void)
|
||||
{
|
||||
return _rt_errno();
|
||||
}
|
||||
@@ -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')
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <sys/errno.h>
|
||||
#include "libc.h"
|
||||
|
||||
#define STDIO_DEVICE_NAME_MAX 32
|
||||
|
||||
int libc_system_init(void)
|
||||
{
|
||||
#ifdef RT_USING_POSIX_STDIO
|
||||
@@ -34,7 +36,7 @@ int libc_system_init(void)
|
||||
INIT_COMPONENT_EXPORT(libc_system_init);
|
||||
|
||||
#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIBC)
|
||||
#define STDIO_DEVICE_NAME_MAX 32
|
||||
|
||||
static FILE* std_console = NULL;
|
||||
int libc_stdio_set_console(const char* device_name, int mode)
|
||||
{
|
||||
@@ -42,7 +44,7 @@ int libc_stdio_set_console(const char* device_name, int mode)
|
||||
char name[STDIO_DEVICE_NAME_MAX];
|
||||
char *file_mode;
|
||||
|
||||
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
rt_snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||
|
||||
if (mode == O_RDWR)
|
||||
@@ -107,15 +109,71 @@ int libc_stdio_get_console(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#elif defined(RT_USING_POSIX_STDIO) && defined(RT_USING_MUSLLIBC)
|
||||
|
||||
static FILE* std_console = NULL;
|
||||
int sys_dup2(int oldfd, int new);
|
||||
|
||||
int libc_stdio_set_console(const char* device_name, int mode)
|
||||
{
|
||||
FILE *fp;
|
||||
char name[STDIO_DEVICE_NAME_MAX];
|
||||
char *file_mode;
|
||||
|
||||
rt_snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||
|
||||
if (mode == O_RDWR) file_mode = "r+";
|
||||
else if (mode == O_WRONLY) file_mode = "wb";
|
||||
else file_mode = "rb";
|
||||
|
||||
fp = fopen(name, file_mode);
|
||||
if (fp)
|
||||
{
|
||||
setvbuf(fp, NULL, _IONBF, 0);
|
||||
|
||||
if (std_console)
|
||||
{
|
||||
fclose(std_console);
|
||||
std_console = NULL;
|
||||
}
|
||||
std_console = fp;
|
||||
}
|
||||
|
||||
if (std_console)
|
||||
{
|
||||
int fd = fileno(std_console);
|
||||
|
||||
// /* set fd (0, 1, 2) */
|
||||
// sys_dup2(fd, 0);
|
||||
// sys_dup2(fd, 1);
|
||||
// sys_dup2(fd, 2);
|
||||
return fd;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int libc_stdio_get_console(void)
|
||||
{
|
||||
int ret = -1;
|
||||
if (std_console)
|
||||
{
|
||||
ret = fileno(std_console);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined(RT_USING_POSIX_STDIO)
|
||||
#define STDIO_DEVICE_NAME_MAX 32
|
||||
|
||||
static int std_fd = -1;
|
||||
int libc_stdio_set_console(const char* device_name, int mode)
|
||||
{
|
||||
int fd;
|
||||
char name[STDIO_DEVICE_NAME_MAX];
|
||||
|
||||
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
rt_snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||
|
||||
fd = open(name, mode, 0);
|
||||
|
||||
Reference in New Issue
Block a user