aboutsummaryrefslogtreecommitdiff
path: root/newlib
AgeCommit message (Collapse)AuthorFilesLines
3 daysRISC-V: Size optimized versions: Replace add with addiHEADgithub/mastergithub/mainmastermainm fally4-8/+8
Replace add instructions with addi where applicable in the size optimized versions of memmove(), memset(), memcpy(), and strcmp(). This change does not affect the functions themselves and is only done to improve syntactic accuracy. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memset() size optimized version: Rename local labelsm fally1-4/+4
Rename local labels to improve readability. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memset() size optimized version: Use compressed registersEric Salem1-3/+3
Swap register t1 with a3, so that the affected instructions can be compressed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Reviewed-by: m fally <marlene.fally@gmail.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
3 daysRISC-V: memcpy() size optimized version: Use compressed registersMahmoud Abumandour1-4/+4
Replace registers t1 and t2 with registers a3 and a4 respectively, so that the affected instructions can be compressed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
3 daysRISC-V: memcpy() size optimized version: Replace lb with lbuMahmoud Abumandour1-1/+1
Replace lb with lbu to avoid unnecessary sign extension. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
3 daysRISC-V: memmove() size optimized version: Relax RAW dependencym fally1-2/+2
Move the instruction that increments the remaining number of bytes to be copied inbetween the load and store instructions. This is done in order to relax the RAW dependency between the load and store instructions. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memmove() size optimized version: Replace lb with lbum fally1-3/+3
Replace lb with lbu to avoid unnecessary sign extension. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memmove() size optimized version: Add commentsm fally1-8/+8
Since the algorithm in this version of memmove() is different from the original version, add comments to give a description. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Reviewed-by: Eric Salem <ericsalem@gmail.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memmove() size optimized version: Rename local labelsm fally1-6/+6
Rename local lables so that the structure of the function is clearer. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memmove() size optimized version: Use compressed registers onlym fally1-8/+8
Change register t1 to register a4, so that the affected instructions can be compressed. Since now we have less registers available, the following changes need to be made: In the previous version of this function, a4 was used to hold the offset that needs to be added to source and destination addresses before copying any data in the case of source address > destination address. Since a4 now holds the destination address, this offset is not calculated anymore. Instead, the value in a2 (the number of bytes to be copied) is added to the source and destination addresses. Therefore, in the case of source address > destination adress, a value of 1 needs to be subtracted from both addresses before starting the copying process. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysRISC-V: memmove() size optimized version: Use compressed registerm fally1-2/+2
Replace register t2 with register a5, so that lb/sb instructions can be compressed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
3 daysnewlib: sys/unistd.h: Change inline to __inlineTakashi Yano1-1/+1
Addresses: https://sourceware.org/pipermail/cygwin-patches/2025q2/013644.html Fixes: 3e8a7eb1a868 ("sys/unistd.h: fix definition of setproctitle_init") Reported-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> Co-authored-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
13 daysnewlib: riscv: Fix build and reorganize header filesEric Salem6-11/+21
The sys/asm.h header file is included for certain assembly files, so move the typedef to a separate header file due to the build breaking on some systems. Also include the port's string header file (and move and rename) instead of the system's version. Addresses: https://sourceware.org/pipermail/newlib/2025/021591.html Fixes: c3b9bb173c8c ("newlib: riscv: Add XLEN typedef and clean up types") Reported-by: Jeff Law <jlaw@ventanamicro.com> Suggested-by: Kito Cheng <kito.cheng@gmail.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
13 daysRISC-V: Fix the asm code for large code modelKito Cheng1-1/+8
The large code model assume the data may far away from the code, so we must put the address of the target data wihin the `.text` section, normally we will just put within the function or nearby the function to prevent it out-of-range. Report from riscv-gnu-toolchain: https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1699 Verified with riscv-gnu-toolchain with rv64gc.
2025-03-25Fix GCN SIMD libm bugAndrew Stubbs1-2/+15
Since January, GCC has been miscompiling Newlib libm on AMD GCN due to undefined behaviour in the RESIZE_VECTOR macro. It was "working" but expanding the size of a vector would no longer zero the additional lanes, as it expected. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119325
2025-03-24getlocalename_l: allow LC_ALL categoryCorinna Vinschen2-3/+17
Following the changes from Austin Group bug https://www.austingroupbugs.net/view.php?id=1741, getlocalename_l() now allows to specify LC_ALL and returns a setlocale-conmpatible LC_ALL locale string. Consequentially we have to raise the size of _reent::_getlocalename_l_buf so there's enough space for the LC_ALL locale string. Guard all different definitions and usages of _getlocalename_l_buf in reent.h with _MB_CAPABLE. Link: https://www.austingroupbugs.net/view.php?id=1741 Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24locale: drop global_locale_string, add locale_string to locale_tCorinna Vinschen2-22/+29
After 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") the Austin Group changed the definition of getlocalename_l() to return setlocale-compatible strings if LC_ALL has been specified. In contrast to the former definition which disallowed LC_ALL as category. In preparation, add a locale_string to every locale_t, and drop the static global_locale_string. This in turn requires to change currentlocale() to work locale-agnostic. Rename to __currentlocale and take two parameters, the locale object and a target string to store the locale string. The latter is required to allow specifiying a target string not in the current locale. Link: https://www.austingroupbugs.net/view.php?id=1741 Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24getlocalename_l: fix commentCorinna Vinschen1-1/+1
Fix name of the defining POSIX standard. Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24getlocalename_l: fix return value in LC_GLOBAL_LOCALE caseCorinna Vinschen1-2/+2
The data was written to the per-reent getlocalename buffer, but the value wasn't returned. Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-24newlib: regenerate Makefile.inCorinna Vinschen1-1/+20
A new C file was added to the RISC-V build
2025-03-24newlib: riscv: Add stpcpy() portEric Salem4-45/+75
Add implementation of stpcpy() to the RISC-V port. Also refactor shared code between strcpy() and stpcpy() to a common function. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-03-24newlib: riscv: Optimize strlen()Eric Salem2-12/+57
The RISC-V Zbb extension provides instructions optimized for bit operations. Use them when available for the RISC-V port. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-03-24newlib: riscv: Add XLEN typedef and clean up typesEric Salem4-44/+45
The size of the long data type isn't precisely defined in the C standard, so create a new typedef that uses either uint32_t or uint64_t based on XLEN. The fixed width types are more robust against any ABI changes and fit the data types of the intrinsic functions. Use the new uintxlen_t type instead of long and uintptr_t. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: Eric Salem <ericsalem@gmail.com>
2025-03-14newlib: fix uninitialized character count being used when printing float ↵Igor Petrov2-0/+2
without "_printf_float" being linked Patch fixes wrong number of written characters being returend from 'printf' family of functionsx when '_printf_float' is not linked (nano.specs). If user tries to print a floating point number anyway, returned number of written characters is not correct. For example in printf("%d%f", 1, 1.0); should return 1, but actaully returns 2.
2025-03-12posix_spawn: skip SIGKILL & SIGSTOPYuyi Wang1-0/+2
sigaction() returns EINVAL on SIGKILL & SIGSTOP. We need to skip them. Fixes: c7c1a1ca1b33 ("* libc/posix/posix_spawn.c: New file.")
2025-03-05sys/unistd.h: fix definition of setproctitle_initCorinna Vinschen1-1/+1
setproctitle_init is defined in c2x manner, omitting names for the unused parameters. This can result in warnings or errors on certain compiler versions: clang 8: error: parameter name omitted clang 15: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions] gcc -Wsystem-headers -pedantic -std=c17: warning: ISO C does not support omitting parameter names in function definitions before C2X [-Wpedantic] Add parameters to avoid above warning and errors. Fixes: 2e7f7b96e5f1 ("Cygwin: implement setproctitle") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-03-03Silence -Woverflow warning in arc4random.cJan Dubiec1-3/+3
This patch fixes "integer overflow" warning in arc4random.c. It explicitly casts REKEY_BASE macro to size_t. The existing code relies on an implicit conversion to int and assumes that sizeof(int)=sizeof(size_t), which is not always true. 2025-03-02 Jan Dubiec <jdx@o2.pl> newlib/ChangeLog: * libc/stdlib/arc4random.c (REKEY_BASE): Explicitly cast the macro to size_t. newlib/libc/stdlib/arc4random.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
2025-03-03Silence -Wshift-count-overflow warningsJan Dubiec3-5/+6
This patch fixes a few "left shift count >= width of type [-Wshift-count-overflow]" warnings. Before shifting a char 16 (or more) bits left first it explicitly casts the char to uint32_t. The existing code relies on implicit casts to int and assumes that ints are 32-bit. This is not always true because the C standard does not require int to be 32-bit and there are targets (e.g. H8/300) where by default int is indeed 16-bit. 2025-03-02 Jan Dubiec <jdx@o2.pl> newlib/ChangeLog: * libc/stdlib/gdtoa-gdtoa.c (gdtoa): Cast to __ULong before left shift. * libc/string/memmem.c (memmem): Cast to uint32_t before left shift. * libc/string/strstr.c (strstr2): Ditto. (strstr3): Ditto. (strstr4): Ditto. newlib/libc/stdlib/gdtoa-gdtoa.c | 2 +- newlib/libc/string/memmem.c | 3 ++- newlib/libc/string/strstr.c | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-)
2025-03-03H8/300: Silence -Wold-style-definition warningsJan Dubiec2-6/+3
2025-03-02 Jan Dubiec <jdx@o2.pl> newlib/ChangeLog: * libc/sys/h8300hms/sbrk.c: Replace the K&R definition with the standard one. * libc/sys/h8300hms/syscalls.c (_isatty): Ditto. (_unlink): Ditto. newlib/libc/sys/h8300hms/sbrk.c | 3 +-- newlib/libc/sys/h8300hms/syscalls.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-)
2025-02-21Add check for clang to avoid unnecessary FPU directivesVolodymyr Turanskyy1-2/+2
This improves compatibility with clang that does not support vfpxd and does not need these extra directives. Change-Id: Id2027e622aef8457ac9c7e1d6715a9240ce8e3f0
2025-02-21Use .p2align 2 instead of .align 0Volodymyr Turanskyy2-2/+2
This is to improve compatibility with LLVM clang: .align 0 is a special case for GCC that is not handled by clang. Change-Id: I855939a32294c74813ecce7275a362265dbc3b1a
2025-02-17strcasecmp family: cast character to unsigned when calling tolowerCorinna Vinschen4-10/+10
The strcasecmp family of functions (strcasecmp, strncasecmp, strcasecmp_l, strncasecmp_l) call tolower on the incoming character before comparison. tolower takes an int as parameter. All four strcasecmp functions neglect to cast the character to unsigned before using it as parameter to tolower. This tolower is called with negative values if the incoming character is not in the ASCII range. This breaks case-insensitive comparison in other singlebyte codesets like ISO-8859-1 with native characters. Adding casts to unsigned char when calling tolower fixes it. Reported-by: Bruno Haible <bruno@clisp.org> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14unistd.h: enable SEEK_DATA and SEEK_HOLE also for POSIX-1.2024Christian Franke1-1/+1
https://pubs.opengroup.org/onlinepubs/9799919799/functions/lseek.html Signed-off-by: Christian Franke <christian.franke@t-online.de>
2025-02-12Protect strcat from accessing an unaligend long pointerAlexey Lapshin1-9/+12
- related to Bug libc/32679
2025-02-11Protect strncat from accessing an unaligend long pointerJeff Johnston1-9/+12
- fixes Bug libc/32679
2025-02-10newlib: Regenerate autotools filesCorinna Vinschen3-6/+74
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-10newlib: introduce --enable-newlib-hw-misaligned-access optionAlexey Lapshin7-2/+67
Some hardware may perform better when copying unaligned word-sized memory compared to byte-by-byte copying. In case not defined explicitly by --enable-newlib-hw-misaligned-access config option or variable $default_newlib_hw_misaligned_access in configure.host file the compiler check will be performed to detect if __riscv_misaligned_fast or __riscv_misaligned_slow is defined. This commit introduces autodetection for RISC-V. Additionally, checking for __ARM_FEATURE_UNALIGNED could be checked for ARM architecture. However, this was not implemented in the commit, as changes in newlib/libc/machine/[arm|aarch64] need to be performed.
2025-02-10newlib: str[n]cat: optimize skipping of the destination stringAlexey Lapshin2-17/+18
Prepare pointer to be aligned and than use word-size iterator on aligned memory.
2025-02-10newlib: memmove: improve performance for overlapping buffersAlexey Lapshin1-3/+21
This change provides word-sized copy for overlapping buffers, that could increase performance significantly. Performance measurement for RISCV: uint8_t buf[1024]; memmove (buf + 4, buf, sizeof(buf) - 4); CPU cycles: 12255 -> 2076
2025-02-10newlib: mem[p]cpy/memmove improve performance for optimized versionsAlexey Lapshin3-3/+3
This change improves performance on memory blocks with sizes in range [4..15]. Performance measurements made for RISCV machine (memset): size 4, CPU cycles change: 50 -> 37 size 5, CPU cycles change: 57 -> 40 size 6, CPU cycles change: 64 -> 47 size 7, CPU cycles change: 71 -> 54 size 8, CPU cycles change: 78 -> 44 size 9, CPU cycles change: 85 -> 47 size 10, CPU cycles change: 92 -> 54 size 11, CPU cycles change: 99 -> 61 size 12, CPU cycles change: 106 -> 51 size 13, CPU cycles change: 113 -> 54 size 14, CPU cycles change: 120 -> 61 size 15, CPU cycles change: 127 -> 68
2025-02-10newlib: memccpy: unify mask filling with other memory functionsAlexey Lapshin1-4/+5
This change made just to have memccpy like others mem-functions
2025-02-10newlib: string: refactor str/mem-family functionsAlexey Lapshin20-433/+124
Move common macros to local.h header
2025-02-03Lift 256 arg limit in execl, execle and execlpTerraneo Federico7-6/+140
add --enable-newlib-use-malloc-in-execl option The previous version of these functions allocated a 256 entry array and copied arguments in that array with no bound checking. That implementation always occupied 1024 bytes of stack for the array even in the common case in which the number of passed arguments is far less than 256, risking stack overflows in environments with small stacks, and caused a stack buffer overflow if called with more than 256 arguments. The improved implementation counts the actual number of passed arguments and allocates a suitable buffer. The default implementation uses alloca to allocate the buffer to satisfy the POSIX.1-2008 requirement that execl and execle should be callable from signal handlers, but it is possible to override this behavior and use malloc for targets where the risk of stack overflow due to unbounded stack allocations is a more pressing requirement than the corner case of allowing execl calls from signal handlers.
2025-02-03newlib: update Makefile.inTerraneo Federico1-339/+276
The libc/sys/xtensa directory was removed in commit 48f1655c955c154b3165692e02aa66699212453c, but the change to Makefile.in wasn't committed.
2025-01-28unistd.h: declare posix_closeCorinna Vinschen1-0/+10
Declare posix_close, a new function defined by POSIX-1.2024, per https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_close.html Define POSIX_CLOSE_RESTART. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-23devctl.h: update for POSIX-1.2024Corinna Vinschen1-16/+0
posix_devctl is now part of POSIX-1.2024, thus the requirement to define _POSIX_26_C_SOURCE has been dropped. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-17Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and ↵Markus Eisenmann3-5/+2
MISSING_SYSCALL_NAMES defined If the macros REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES are defined some _reent_*-functions are replaced by the system-call and this leads to compile-warning or a runtime-failure. * newlib/libc/stdio/fopen.c _open_r is replaces by open(), declared in <fcntl.h> * newlib/libc/stdio64/fopen64.c ditto * newlib/libc/stdio/rename.c _rename_r is rename() itself; i.e, fix recursion
2025-01-16Add posix_spawn_file_actions_add{f}chdirCorinna Vinschen1-2/+7
POSIX®.1-2024 now defines posix_spawn_file_actions_addchdir and posix_spawn_file_actions_addfchdir. Add these interfaces to spawn.h, guarded as POSIX 202405 symbols. Cygwin-only: Export them as aliases of the *_np counterparts. Bump API minor. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-13Add missing getlocalename_l to LIBC_CHEWOUT_FILESCorinna Vinschen2-15/+16
Regenerate Makefile.in. Fixes: 71511d4ac8686 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Reported-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-31Changes for 4.5.0 snapshotnewlib-4.5.0Jeff Johnston6-26/+42
- bump up release to 4.5.0