libc/string: prevent libc in the kernel/userspace optionally

Add the `LIBC_PREVENT_STRING_KERNEL` and `LIBC_PREVENT_STRING_USER`
that are meant to be selected by the chip if no libc implementation
is going to be built. If selected, neither NuttX's software version
of the libc nor any architecture-specific implementation will be
built in the kernel or in the userspace, respectively. In this
case, the linker may provide a ROM-defined version of the libc
functions instead.
This commit is contained in:
Tiago Medicci Serrano
2023-04-28 13:55:23 -03:00
committed by Xiang Xiao
parent 6be363ff35
commit 58e97e521c
73 changed files with 405 additions and 76 deletions
+3 -49
View File
@@ -32,61 +32,15 @@ CSRCS += lib_strsep.c lib_strerrorr.c lib_explicit_bzero.c lib_strsignal.c
CSRCS += lib_index.c lib_rindex.c lib_timingsafe_bcmp.c lib_strverscmp.c
CSRCS += lib_mempcpy.c lib_rawmemchr.c lib_bzero.c
ifneq ($(CONFIG_LIBC_ARCH_MEMCHR),y)
CSRCS += lib_memchr.c
endif
CSRCS += lib_memchr.c lib_memcmp.c lib_memmove.c lib_memset.c
CSRCS += lib_strchr.c lib_strcmp.c lib_strcpy.c lib_strlcat.c
CSRCS += lib_strlcpy.c lib_strlen.c lib_strncpy.c lib_strnlen.c
ifneq ($(CONFIG_LIBC_ARCH_MEMCMP),y)
CSRCS += lib_memcmp.c
endif
ifneq ($(CONFIG_LIBC_ARCH_MEMCPY),y)
ifeq ($(CONFIG_MEMCPY_VIK),y)
CSRCS += lib_vikmemcpy.c
else
CSRCS += lib_memcpy.c
endif
endif
ifneq ($(CONFIG_LIBC_ARCH_MEMMOVE),y)
CSRCS += lib_memmove.c
endif
ifneq ($(CONFIG_LIBC_ARCH_MEMSET),y)
CSRCS += lib_memset.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRCHR),y)
CSRCS += lib_strchr.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRCMP),y)
CSRCS += lib_strcmp.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRCPY),y)
CSRCS += lib_strcpy.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRLCAT),y)
CSRCS += lib_strlcat.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRLCPY),y)
CSRCS += lib_strlcpy.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRLEN),y)
CSRCS += lib_strlen.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRNCPY),y)
CSRCS += lib_strncpy.c
endif
ifneq ($(CONFIG_LIBC_ARCH_STRNLEN),y)
CSRCS += lib_strnlen.c
endif
ifeq ($(CONFIG_LIBC_LOCALE),y)
CSRCS += lib_strcoll.c lib_strxfrm.c
+4
View File
@@ -26,6 +26,8 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -44,6 +46,7 @@
*
****************************************************************************/
#if !defined(CONFIG_LIBC_ARCH_MEMCHR) && defined(LIBC_BUILD_STRING)
#undef memchr /* See mm/README.txt */
FAR void *memchr(FAR const void *s, int c, size_t n)
{
@@ -61,3 +64,4 @@ FAR void *memchr(FAR const void *s, int c, size_t n)
return NULL;
}
#endif
+3 -1
View File
@@ -26,11 +26,13 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_MEMCMP
#if !defined(CONFIG_LIBC_ARCH_MEMCMP) && defined(LIBC_BUILD_STRING)
#undef memcmp /* See mm/README.txt */
no_builtin("memcmp")
int memcmp(FAR const void *s1, FAR const void *s2, size_t n)
+3 -1
View File
@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -34,7 +36,7 @@
* Name: memcpy
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_MEMCPY
#if !defined(CONFIG_LIBC_ARCH_MEMCPY) && defined(LIBC_BUILD_STRING)
#undef memcpy /* See mm/README.txt */
no_builtin("memcpy")
FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n)
+3 -1
View File
@@ -26,11 +26,13 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_MEMMOVE
#if !defined(CONFIG_LIBC_ARCH_MEMMOVE) && defined(LIBC_BUILD_STRING)
#undef memmove /* See mm/README.txt */
no_builtin("memmove")
FAR void *memmove(FAR void *dest, FAR const void *src, size_t count)
+3 -1
View File
@@ -30,6 +30,8 @@
#include <string.h>
#include <assert.h>
#include "libc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -46,7 +48,7 @@
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_MEMSET
#if !defined(CONFIG_LIBC_ARCH_MEMSET) && defined(LIBC_BUILD_STRING)
#undef memset /* See mm/README.txt */
no_builtin("memset")
FAR void *memset(FAR void *s, int c, size_t n)
+3 -1
View File
@@ -27,11 +27,13 @@
#include <strings.h>
#include <ctype.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRCASECMP
#if !defined(CONFIG_LIBC_ARCH_STRCASECMP) && defined(LIBC_BUILD_STRING)
#undef strcasecmp /* See mm/README.txt */
int strcasecmp(FAR const char *cs, FAR const char *ct)
{
+3 -1
View File
@@ -26,11 +26,13 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRCAT
#if !defined(CONFIG_LIBC_ARCH_STRCAT) && defined(LIBC_BUILD_STRING)
#undef strcat /* See mm/README.txt */
FAR char *strcat(FAR char *dest, FAR const char *src)
{
+3 -1
View File
@@ -26,6 +26,8 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -44,7 +46,7 @@
*
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRCHR
#if !defined(CONFIG_LIBC_ARCH_STRCHR) && defined(LIBC_BUILD_STRING)
#undef strchr /* See mm/README.txt */
FAR char *strchr(FAR const char *s, int c)
{
+3 -1
View File
@@ -26,6 +26,8 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -44,7 +46,7 @@
*
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRCHRNUL
#if !defined(CONFIG_LIBC_ARCH_STRCHRNUL) && defined(LIBC_BUILD_STRING)
FAR char *strchrnul(FAR const char *s, int c)
{
if (s)
+3 -1
View File
@@ -26,11 +26,13 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRCMP
#if !defined(CONFIG_LIBC_ARCH_STRCMP) && defined(LIBC_BUILD_STRING)
#undef strcmp /* See mm/README.txt */
int strcmp(FAR const char *cs, FAR const char *ct)
{
+3 -1
View File
@@ -26,6 +26,8 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -42,7 +44,7 @@
*
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRCPY
#if !defined(CONFIG_LIBC_ARCH_STRCPY) && defined(LIBC_BUILD_STRING)
#undef strcpy /* See mm/README.txt */
FAR char *strcpy(FAR char *dest, FAR const char *src)
{
+3 -1
View File
@@ -27,6 +27,8 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -44,7 +46,7 @@
*
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRLCAT
#if !defined(CONFIG_LIBC_ARCH_STRLCAT) && defined(LIBC_BUILD_STRING)
size_t strlcat(FAR char *dst, FAR const char *src, size_t dsize)
{
FAR const char *odst = dst;
+3 -1
View File
@@ -27,6 +27,8 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -43,7 +45,7 @@
*
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRLCPY
#if !defined(CONFIG_LIBC_ARCH_STRLCPY) && defined(LIBC_BUILD_STRING)
size_t strlcpy(FAR char *dst, FAR const char *src, size_t dsize)
{
FAR const char *osrc = src;
+3 -1
View File
@@ -26,11 +26,13 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRLEN
#if !defined(CONFIG_LIBC_ARCH_STRLEN) && defined(LIBC_BUILD_STRING)
#undef strlen /* See mm/README.txt */
size_t strlen(const char *s)
{
+3 -1
View File
@@ -28,11 +28,13 @@
#include <strings.h>
#include <ctype.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRNCASECMP
#if !defined(CONFIG_LIBC_ARCH_STRNCASECMP) && defined(LIBC_BUILD_STRING)
#undef strncasecmp /* See mm/README.txt */
int strncasecmp(FAR const char *cs, FAR const char *ct, size_t nb)
{
+3 -1
View File
@@ -26,11 +26,13 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRNCAT
#if !defined(CONFIG_LIBC_ARCH_STRNCAT) && defined(LIBC_BUILD_STRING)
#undef strncat /* See mm/README.txt */
FAR char *strncat(FAR char *dest, FAR const char *src, size_t n)
{
+3 -1
View File
@@ -26,11 +26,13 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRNCMP
#if !defined(CONFIG_LIBC_ARCH_STRNCMP) && defined(LIBC_BUILD_STRING)
#undef strncmp /* See mm/README.txt */
int strncmp(FAR const char *cs, FAR const char *ct, size_t nb)
{
+3 -1
View File
@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -51,7 +53,7 @@
*
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRNCPY
#if !defined(CONFIG_LIBC_ARCH_STRNCPY) && defined(LIBC_BUILD_STRING)
#undef strncpy /* See mm/README.txt */
FAR char *strncpy(FAR char *dest, FAR const char *src, size_t n)
{
+3 -1
View File
@@ -26,11 +26,13 @@
#include <sys/types.h>
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef CONFIG_LIBC_ARCH_STRNLEN
#if !defined(CONFIG_LIBC_ARCH_STRNLEN) && defined(LIBC_BUILD_STRING)
size_t strnlen(const char *s, size_t maxlen)
{
const char *sc;
+3 -1
View File
@@ -26,6 +26,8 @@
#include <string.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -34,7 +36,7 @@
* occurrence of the character c in the string s.
*/
#ifndef CONFIG_LIBC_ARCH_STRRCHR
#if !defined(CONFIG_LIBC_ARCH_STRRCHR) && defined(LIBC_BUILD_STRING)
#undef strrchr /* See mm/README.txt */
FAR char *strrchr(FAR const char *s, int c)
{
+6
View File
@@ -62,6 +62,10 @@
#include <stdint.h>
#include <string.h>
#include "libc.h"
#if !defined(CONFIG_LIBC_ARCH_MEMCPY) && defined(LIBC_BUILD_STRING)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -342,3 +346,5 @@ FAR void *memcpy(FAR void *dest, FAR const void *src, size_t count)
return dest;
}
#endif