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
+1
View File
@@ -82,6 +82,7 @@ else
endif
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libc
AFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libc
# Rule for the symbol table generation
+20 -8
View File
@@ -27,15 +27,17 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <semaphore.h>
#ifndef __ASSEMBLY__
# include <sys/types.h>
# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>
# include <limits.h>
# include <semaphore.h>
#include <nuttx/lib/lib.h>
#include <nuttx/streams.h>
# include <nuttx/lib/lib.h>
# include <nuttx/streams.h>
#endif
/****************************************************************************
* Pre-processor Definitions
@@ -53,6 +55,12 @@
#define LIB_BUFLEN_UNKNOWN INT_MAX
#if defined(CONFIG_BUILD_FLAT) || \
((!defined(CONFIG_LIBC_PREVENT_STRING_USER) && !defined(__KERNEL__)) || \
(!defined(CONFIG_LIBC_PREVENT_STRING_KERNEL) && defined(__KERNEL__)))
# define LIBC_BUILD_STRING
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@@ -61,6 +69,8 @@
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
@@ -157,4 +167,6 @@ void lib_cxx_initialize(void);
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __LIBS_LIBC_LIBC_H */
+24
View File
@@ -137,6 +137,30 @@ config LIBC_ARCH_ELF_64BIT
default n
depends on LIBC_ARCH_ELF
config LIBC_PREVENT_STRING_KERNEL
bool
default n
---help---
Prevent any implementation of the libc from being built and linked
in the kernel, including NuttX's software-defined version of the libc
or any other architecture-specific version of it. The ROM-defined
version should be linked instead. This option is particularly useful
when it's required that the ROM-defined libc to be used by the kernel
(for accessing some driver resource, for instance) but the userspace
is forbidden to use the same ROM-defined versions. In this case,
NuttX's software-defined version of the libc or arch-specific
assembly version is built instead.
config LIBC_PREVENT_STRING_USER
bool
default n
---help---
Prevent any implementation of the libc from being built and linked
in the userspace, including NuttX's software-defined version of the
libc or any other architecture-specific version of it. A ROM-defined
version of the libc may be linked to the userspace by the linker.
# One or more the of above may be selected by architecture specific logic
if ARCH_ARM
@@ -66,6 +66,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
@ 2011-02-07 david.gilbert@linaro.org
@ Extracted from local git a5b438d861
@ 2011-07-14 david.gilbert@linaro.org
@@ -389,3 +393,5 @@ memchr:
#else
/* Defined in memchr-stub.c. */
#endif
#endif
@@ -33,6 +33,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/*
* This memcpy routine is optimised for Cortex-A15 cores and takes advantage
* of VFP or NEON when built with the appropriate flags.
@@ -624,3 +628,5 @@ def_fn memcpy p2align=6
bx lr
.size memcpy, . - memcpy
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
.thumb
.syntax unified
.global memmove
@@ -64,3 +68,5 @@ memmove:
pop {r4}
bx lr
.size memmove, . - memmove
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
.arm
.syntax unified
.global memset
@@ -144,3 +148,5 @@ memset:
strbcs r1, [r3], #1
bx lr
.size memset, . - memset
#endif
@@ -30,6 +30,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#ifdef __ARMEB__
#define SHFT2LSB lsl
#define SHFT2LSBEQ lsleq
@@ -301,3 +305,5 @@ strcmp:
ldr r5, [sp], #4
bx lr
.size strcmp, . - strcmp
#endif
@@ -62,6 +62,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "acle-compat.h"
.macro def_fn f p2align=0
@@ -182,3 +186,5 @@ def_fn strlen p2align=6
mov const_0, #0
b .Lstart_realigned
.size strlen, . - strlen
#endif
@@ -66,6 +66,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
@ 2011-02-07 david.gilbert@linaro.org
@ Extracted from local git a5b438d861
@ 2011-07-14 david.gilbert@linaro.org
@@ -427,3 +431,5 @@ memchr:
#else
/* Defined in memchr-stub.c. */
#endif
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* This memcpy routine is optimised for Cortex-M3/M4 cores with/without
unaligned access.
@@ -345,3 +349,5 @@ memcpy:
.cantunwind
.fnend
.size memcpy, .-memcpy
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "arm_asm.h"
.thumb
@@ -71,3 +75,5 @@ memmove:
.cantunwind
.fnend
.size memmove, . - memmove
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "arm_asm.h"
.thumb
@@ -114,3 +118,5 @@ memset:
.cantunwind
.fnend
.size memset, . - memset
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Very similar to the generic code, but uses Thumb2 as implemented
in ARMv7-M. */
@@ -419,3 +423,5 @@ def_fn strcmp
.cantunwind
.fnend
.size strcmp, . - strcmp
#endif
@@ -18,6 +18,10 @@
*
***************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* This strcpy borrowed some ideas from arch_strcmp.S(). */
/* Parameters and result. */
@@ -306,3 +310,4 @@ offset_3:
*dst++ = 0;
#endif /* Pseudo code end */
#endif
@@ -62,6 +62,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "arm-acle-compat.h"
#include "arm_asm.h"
@@ -193,3 +197,5 @@ def_fn strlen p2align=6
.cantunwind
.fnend
.size strlen, . - strlen
#endif
@@ -66,6 +66,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
@ 2011-02-07 david.gilbert@linaro.org
@ Extracted from local git a5b438d861
@ 2011-07-14 david.gilbert@linaro.org
@@ -389,3 +393,5 @@ memchr:
#else
/* Defined in memchr-stub.c. */
#endif
#endif
@@ -33,6 +33,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/*
* This memcpy routine is optimised for Cortex-A15 cores and takes advantage
* of VFP or NEON when built with the appropriate flags.
@@ -624,3 +628,5 @@ def_fn memcpy p2align=6
bx lr
.size memcpy, . - memcpy
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
.thumb
.syntax unified
.global memmove
@@ -64,3 +68,5 @@ memmove:
pop {r4}
bx lr
.size memmove, . - memmove
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
.arm
.syntax unified
.global memset
@@ -144,3 +148,5 @@ memset:
strbcs r1, [r3], #1
bx lr
.size memset, . - memset
#endif
@@ -30,6 +30,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#ifdef __ARMEB__
#define SHFT2LSB lsl
#define SHFT2LSBEQ lsleq
@@ -301,3 +305,5 @@ strcmp:
ldr r5, [sp], #4
bx lr
.size strcmp, . - strcmp
#endif
@@ -62,6 +62,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "acle-compat.h"
.macro def_fn f p2align=0
@@ -182,3 +186,5 @@ def_fn strlen p2align=6
mov const_0, #0
b .Lstart_realigned
.size strlen, . - strlen
#endif
@@ -66,6 +66,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
@ 2011-02-07 david.gilbert@linaro.org
@ Extracted from local git a5b438d861
@ 2011-07-14 david.gilbert@linaro.org
@@ -427,3 +431,5 @@ memchr:
#else
/* Defined in memchr-stub.c. */
#endif
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* This memcpy routine is optimised for Cortex-M3/M4 cores with/without
unaligned access.
@@ -367,3 +371,5 @@ memcpy:
.cantunwind
.fnend
.size memcpy, .-memcpy
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "arm_asm.h"
.thumb
@@ -71,3 +75,5 @@ memmove:
.cantunwind
.fnend
.size memmove, . - memmove
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "arm_asm.h"
.thumb
@@ -129,3 +133,5 @@ memset:
.cantunwind
.fnend
.size memset, . - memset
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Very similar to the generic code, but uses Thumb2 as implemented
in ARMv7-M. */
@@ -419,3 +423,5 @@ def_fn strcmp
.cantunwind
.fnend
.size strcmp, . - strcmp
#endif
@@ -62,6 +62,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "arm-acle-compat.h"
#include "arm_asm.h"
@@ -193,3 +197,5 @@ def_fn strlen p2align=6
.cantunwind
.fnend
.size strlen, . - strlen
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -171,3 +175,5 @@ def_fn memchr
ret
.size memchr, . - memchr
#endif
@@ -59,6 +59,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64, unaligned accesses.
@@ -194,3 +198,5 @@ L(byte_loop):
ret
.size memcmp, . - memcmp
#endif
@@ -59,6 +59,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64, unaligned accesses.
@@ -230,3 +234,5 @@ L(copy_long):
ret
.size memcpy, . - memcpy
#endif
@@ -59,6 +59,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64, unaligned accesses
@@ -155,3 +159,5 @@ def_fn memmove, 6
3: ret
.size memmove, . - memmove
#endif
@@ -59,6 +59,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64, unaligned accesses
@@ -240,3 +244,5 @@ L(zva_other):
b L(tail64)
.size memset, . - memset
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -159,3 +163,5 @@ def_fn strchr
ret
.size strchr, . - strchr
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -144,3 +148,5 @@ def_fn strchrnul
ret
.size strchrnul, . - strchrnul
#endif
@@ -33,6 +33,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -203,3 +207,5 @@ L(done):
sub result, data1, data2
ret
.size strcmp, .-strcmp
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64, unaligned accesses, min page size 4k.
@@ -336,3 +340,5 @@ def_fn STRCPY p2align=6
b .Lfp_gt8
.size STRCPY, . - STRCPY
#endif
@@ -33,6 +33,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64, unaligned accesses, min page size 4k.
@@ -240,3 +244,5 @@ L(page_cross):
b L(page_cross_entry)
.size strlen, . - strlen
#endif
@@ -33,6 +33,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -292,3 +296,5 @@ def_fn strncmp
mov result, #0
ret
.size strncmp, . - strncmp
#endif
@@ -33,6 +33,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -186,3 +190,5 @@ def_fn strnlen
csel data2, data2, data2a, le
b .Lrealigned
.size strnlen, . - .Lstart /* Include pre-padding in size. */
#endif
@@ -29,6 +29,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/* Assumptions:
*
* ARMv8-a, AArch64
@@ -177,3 +181,5 @@ def_fn strrchr
ret
.size strrchr, . - strrchr
#endif
@@ -18,6 +18,14 @@
*
****************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/************************************************************************************
* Public Symbols
************************************************************************************/
@@ -128,3 +136,5 @@ memcpy:
bltu a1, a3, 5b
6:
ret
#endif
@@ -13,6 +13,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
.text
.global memset
.type memset, @function
@@ -104,3 +108,5 @@ memset:
bleu a2, t1, .Ltiny
j .Laligned
.size memset, .-memset
#endif
@@ -13,6 +13,10 @@
*
****************************************************************************/
#include "libc.h"
#ifdef LIBC_BUILD_STRING
#include "asm.h"
.text
@@ -185,3 +189,5 @@ strcmp:
mask:
.dword 0x7f7f7f7f7f7f7f7f
#endif
#endif
+6
View File
@@ -27,6 +27,10 @@
#include <arch/chip/core-isa.h>
#include <arch/xtensa/xtensa_abi.h>
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/****************************************************************************
* Pre-processor Macros
****************************************************************************/
@@ -276,3 +280,5 @@ __memcpy_aux:
.end schedule
.size memcpy, . - memcpy
#endif
+6
View File
@@ -27,6 +27,10 @@
#include <arch/chip/core-isa.h>
#include <arch/xtensa/xtensa_abi.h>
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/****************************************************************************
* Pre-processor Macros
****************************************************************************/
@@ -479,3 +483,5 @@ memmove:
.end schedule
.size memmove, . - memmove
#endif
+6
View File
@@ -27,6 +27,10 @@
#include <arch/chip/core-isa.h>
#include <arch/xtensa/xtensa_abi.h>
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -175,3 +179,5 @@ __memset_aux:
.end schedule
.size memset, . - memset
#endif
+5
View File
@@ -27,6 +27,10 @@
#include <arch/chip/core-isa.h>
#include <arch/xtensa/xtensa_abi.h>
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/****************************************************************************
* Pre-processor Macros
****************************************************************************/
@@ -760,3 +764,4 @@ strcmp:
.end schedule
.size strcmp, . - strcmp
#endif
+6
View File
@@ -27,6 +27,10 @@
#include <arch/chip/core-isa.h>
#include <arch/xtensa/xtensa_abi.h>
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -240,3 +244,5 @@ strcpy:
.end schedule
.size strcpy, . - strcpy
#endif
+6
View File
@@ -27,6 +27,10 @@
#include <arch/chip/core-isa.h>
#include <arch/xtensa/xtensa_abi.h>
#include "libc.h"
#ifdef LIBC_BUILD_STRING
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -120,3 +124,5 @@ strlen:
.end schedule
.size strlen, . - strlen
#endif

Some files were not shown because too many files have changed in this diff Show More