From c318dfa964c8967325b945fe851e9554fdae0638 Mon Sep 17 00:00:00 2001 From: "Man, Jianting (Meco)" <920369182@qq.com> Date: Thu, 7 Apr 2022 02:24:11 -0400 Subject: [PATCH] improve libc time and MSVC simulator (#5775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [libc] 解决由于类unix操作系统发展历史原因fcntl.h定义的标志位在不同编译器中定义不同的问题 - [simulator] 部分宏定义转为全局宏定义以确保vs内置文件可以正确配置 - [simulator] 取消自欺欺人式的警告消除处理方式 - [libc][time] 优化time相关结构体在不同编译器下的包含 --- bsp/simulator/drivers/SConscript | 20 ++++++++++++++++++- bsp/simulator/rtconfig_project.h | 20 ++++--------------- .../compilers/common/extension/SConscript | 11 ++++++++-- .../common/extension/fcntl/README.md | 4 ++++ .../common/extension/fcntl/SConscript | 15 ++++++++++++++ .../common/extension/fcntl/octal/SConscript | 14 +++++++++++++ .../extension/{ => fcntl/octal}/fcntl.h | 0 components/libc/compilers/common/sys/time.h | 14 +++++++------ 8 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 components/libc/compilers/common/extension/fcntl/README.md create mode 100644 components/libc/compilers/common/extension/fcntl/SConscript create mode 100644 components/libc/compilers/common/extension/fcntl/octal/SConscript rename components/libc/compilers/common/extension/{ => fcntl/octal}/fcntl.h (100%) diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript index 8f0c9275ff..731b577fd3 100644 --- a/bsp/simulator/drivers/SConscript +++ b/bsp/simulator/drivers/SConscript @@ -1,12 +1,29 @@ import sys import os from building import * +Import('rtconfig') cwd = GetCurrentDir() src = Glob('*.c') LIBS = [] LIBPATH = [] CPPPATH = [cwd] +CPPDEFINES = [] + +if rtconfig.CROSS_TOOL == 'msvc': + CPPDEFINES += \ + [ + # avoid to conflict with the inherent STDC in VS + '_CRT_DECLARE_NONSTDC_NAMES=0', + # errno macro redefinition + '_CRT_ERRNO_DEFINED', + # time.h conflicts + '_CRT_NO_TIME_T', + # disable deprecation of unsafe functions, such as strncpy + '_CRT_SECURE_NO_WARNINGS', + # RT_VESRION conflicts in winuser.h + 'NORESOURCE', + ] # remove no need file. if GetDepend('PKG_USING_GUIENGINE') == False: @@ -30,7 +47,8 @@ if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MODULE') == False: if sys.platform[0:5]=="linux": #check whether under linux SrcRemove(src, ['module_win32.c', 'dfs_win32.c']) -group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH) +group = DefineGroup('Drivers', src, depend = [''], + CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH, CPPDEFINES=CPPDEFINES) list = os.listdir(cwd) for item in list: diff --git a/bsp/simulator/rtconfig_project.h b/bsp/simulator/rtconfig_project.h index 12892e9a98..0dc3bed0ee 100644 --- a/bsp/simulator/rtconfig_project.h +++ b/bsp/simulator/rtconfig_project.h @@ -12,21 +12,9 @@ #define RT_HEAP_SIZE (1024*1024*8) -#if defined(_MSC_VER) -#define NORESOURCE /* RT_VESRION in winuser.h */ -#define _CRT_ERRNO_DEFINED /* errno macro redefinition */ -#define _INC_WTIME_INL /* dfs_elm.c time.h conflicts with wtime.inl */ -#define _INC_TIME_INL /* dfs_elm.c time.h conflicts with wtime.inl */ -#define _CRT_DECLARE_NONSTDC_NAMES 0 /* avoid to conflict with the inherent STDC in VS */ - +#ifdef _MSC_VER /* disable some warning in MSC */ -#pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */ -#pragma warning(disable:4312) /* to ignore: warning C4312: 'type cast' : conversion from 'rt_uint32_t' to 'rt_uint32_t *' */ -#pragma warning(disable:4311) /* to ignore: warning C4311: 'type cast' : pointer truncation from 'short *__w64 ' to 'long' */ -#pragma warning(disable:4996) /* to ignore: warning C4996: The POSIX name for this item is deprecated. */ -#pragma warning(disable:4267) /* to ignore: warning C4267: conversion from 'size_t' to 'rt_size_t', possible loss of data */ -#pragma warning(disable:4244) /* to ignore: warning C4244: '=' : conversion from '__w64 int' to 'rt_size_t', possible loss of data */ +// #pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */ +#endif /* _MSC_VER */ -#endif /* end of _MSC_VER */ - -#endif +#endif /* RTCONFIG_PROJECT_H__ */ diff --git a/components/libc/compilers/common/extension/SConscript b/components/libc/compilers/common/extension/SConscript index dbc26ac177..ddd83c8234 100644 --- a/components/libc/compilers/common/extension/SConscript +++ b/components/libc/compilers/common/extension/SConscript @@ -1,5 +1,5 @@ +import os from building import * - Import('rtconfig') src = [] @@ -9,6 +9,13 @@ group = [] src += Glob('*.c') -if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': +if rtconfig.PLATFORM != 'gcc': group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) + +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/common/extension/fcntl/README.md b/components/libc/compilers/common/extension/fcntl/README.md new file mode 100644 index 0000000000..8866eace7c --- /dev/null +++ b/components/libc/compilers/common/extension/fcntl/README.md @@ -0,0 +1,4 @@ +Because of the history issue, flags in fcntl.h, such as O_CREAT, have difference types of value. Some OS use hex flags and others use octal flags. + +In terms of RT-Thread, Keil, IAR and MSVC use octal flags, which is located in the `tcntl/octal` folder; newlib uses hex flags; musl uses octal flags. + diff --git a/components/libc/compilers/common/extension/fcntl/SConscript b/components/libc/compilers/common/extension/fcntl/SConscript new file mode 100644 index 0000000000..4c815c49b8 --- /dev/null +++ b/components/libc/compilers/common/extension/fcntl/SConscript @@ -0,0 +1,15 @@ +# RT-Thread building script for bridge + +import os +from building import * + +cwd = GetCurrentDir() +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/components/libc/compilers/common/extension/fcntl/octal/SConscript b/components/libc/compilers/common/extension/fcntl/octal/SConscript new file mode 100644 index 0000000000..22d72dff05 --- /dev/null +++ b/components/libc/compilers/common/extension/fcntl/octal/SConscript @@ -0,0 +1,14 @@ +from building import * +Import('rtconfig') + +src = [] +cwd = GetCurrentDir() +CPPPATH = [cwd] +group = [] + +if rtconfig.PLATFORM == 'armcc' or\ + rtconfig.PLATFORM == 'armclang' or\ + rtconfig.PLATFORM == 'iar' or\ + rtconfig.CROSS_TOOL == 'msvc': + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) +Return('group') diff --git a/components/libc/compilers/common/extension/fcntl.h b/components/libc/compilers/common/extension/fcntl/octal/fcntl.h similarity index 100% rename from components/libc/compilers/common/extension/fcntl.h rename to components/libc/compilers/common/extension/fcntl/octal/fcntl.h diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index a3af31b20b..3fe6ae4a26 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -18,7 +18,9 @@ #include #ifdef _WIN32 #include /* for struct timeval */ -#endif +#include /* for __time64_t */ +typedef __time64_t time_t; +#endif /* _WIN32 */ #ifdef __cplusplus extern "C" { @@ -50,17 +52,17 @@ struct timeval time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* and microseconds */ }; -#endif +#endif /* !defined(_TIMEVAL_DEFINED) && !defined(_WIN32) */ -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \ - !(defined(__ICCARM__) && (__VER__ >= 8010001)) && \ - !defined(_WIN32) +#if defined(__ARMCC_VERSION) || defined(_WIN32) || (defined(__ICCARM__) && (__VER__ >= 8010001)) struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; +#endif /* defined(__ARMCC_VERSION) || defined(_WIN32) || (defined(__ICCARM__) && (__VER__ >= 8010001)) */ +#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) /* * Structure defined by POSIX.1b to be like a itimerval, but with * timespecs. Used in the timer_*() system calls. @@ -70,7 +72,7 @@ struct itimerspec struct timespec it_interval; struct timespec it_value; }; -#endif +#endif /* !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) */ int stime(const time_t *t); time_t timegm(struct tm * const t);