aboutsummaryrefslogtreecommitdiff
path: root/newlib
AgeCommit message (Collapse)AuthorFilesLines
2025-12-04features.h: Fix -Wundef problemsStefan Tauner1-21/+28
-Wundef warns if an undefined identifier is evaluated in an #if directive. This would be valid as they are replaced with 0. However, it is often an early warning sign and not intentional. To allow for enabling -Wundef even outside system directories (where compilers ignore such problems unless -Wsystem-headers is enabled) this patch adds the required defined() checks. glibc also has been supporting this for 10 years now: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=f248238cf43bd751db29e6f151d6da7645337ff5 I have not exhaustively tested this but you can see the effect with something like the following (+ using -stdc= and/or -D...): echo | gcc -include newlib/libc/include/sys/features.h -Inewlib/libc/include/ -E - -Wundef Signed-off-by: Stefan Tauner <stefan.tauner@gmx.at>
2025-12-03newlib: copy args for atexit()'ed function before unlock the mutexTakashi Yano1-4/+10
The commit a2a8bc771f2f has a problem that __atexit which includes args for atexit()'ed function may be touched by another thread since the mutex is unlocked while calling the function. With this path, the args, etc. are copyed to local variable to prevent this problem. Fixes: a2a8bc771f2f ("newlib: Unlock the mutex while calling atexit()'ed functions") Suggested-by: Sebastian Huber <sebastian.huber@embedded-brains.de> Reviewed-by: Corinna Vinschen <corinna@vinschen.de>, Sebastian Huber <sebastian.huber@embedded-brains.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-11-21newlib: Unlock the mutex while calling atexit()'ed functionsTakashi Yano1-0/+8
The atexit()'ed function may deadlock if it waits for another thread which calls atexit() in the current __call_atexit.c code. This patch unlock __atexit_recursive_mutex while calling atexit()'ed functions to avoid the deadlock mentioned above. glibc and Darwin do the same, so it sounds reasonable. Addresses: https://cygwin.com/pipermail/cygwin/2025-October/258930.html Reported-by: Tomohiro Kashiwada <tomohiro-kashiwada@ezweb.ne.jp> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-11-19libc/features.h: Make code match documentationSimon Barth1-2/+2
The documentation states that _GNU_SOURCE enables "all of the above plus GNU extensions.". Furthermore the documentation states that _DEFAULT_SOURCE would enable POSIX-1.2008 with BSD and SVr4 extensions. The code did different things though: * For _GNU_SOURCE it only enabled POSIX.1-2008 but it should have been the highest available one, POSIX.1-2024. * For _DEFAULT_SOURCE it enabled POSIX.1-2024. Let's use the highest available POSIX standard possible and fix documentation where necessary.
2025-11-19libc: Make string.h POSIX.1-2024 compliantSimon Barth1-2/+4
POSIX.1-2024 added strlcpy, strlcat, and memmem to strings.h. Previously these functions were only available as parts of BSD or GNU extensions. Fix the header so that the symbol are visible for either the right extensions, or for POSIX.1-2024.
2025-11-19Fix missing declaration in systemJean-Paul Mari1-0/+2
This patch adds a missing function declaration in system.c file. This helps avoid declaration compiler warning or error. Tested by building newlib for m68k-elf with GCC.
2025-11-04newlib/libc/include/sys/features.h: Update RTEMS sectionJoel Sherrill1-6/+9
The RTEMS section defined macros for features RTEMS does not have.
2025-11-04newlib/libc/include/setjmp.h: Add returns_twice attribute to setjmp()Joel Sherrill1-7/+3
The setjmp() function needs this attribute to help GCC avoid false positives for the -Wclobbered warning. The -Wclobbered warning is part of -Wextra.
2025-11-03newlib/ChangeLog:Jan Dubiec1-48/+32
* libc/sys/h8300hms/crt0.S: General cleanup: declare stack section in a proper way, merge H8/300H and H8/300S/SX parts of code into one, add support for normal mode.
2025-11-03newlib/ChangeLog:Jan Dubiec1-18/+21
* libc/machine/h8300/strcmp.S (_strcmp): First extend 8 bit character codes to 16 bit integers and then compare them.
2025-11-03strtodg: Make increment staticZakaria Fadli1-1/+1
This helper is only used within strtodg.c; keep it internal to avoid exporting a generic symbol name and reduce namespace pollution. * libc/stdlib/strtodg.c (increment): Make static.
2025-10-17Fix ARM fegetexceptflag.cMatt Reynolds1-3/+1
The ARM fegetexceptflag() implementation was accidentally replaced with fesetexceptflag() during refactoring in b7a6e02dc6a5289bfa489c0e7b6539abd281e2c6. Restore the original implementation. Tested on Cortex-M7.
2025-09-22newlib: strtold: Import strtorQ for 128-bit long double supportZakaria Fadli5-29/+178
The implementation of strtorQ is imported from FreeBSD's gdtoa library (By David M. Gay) with some adaptations to fit with newlib. `strtorQ.c` enables `strtold` to perform correct parsing on targets where long double uses the IEEE754 binary128 format (113-bit mantissa), such as AArch64. Without this patch, strtold would wrongly fallback to `strtorx` which will parse into a 80-bit long double and give invalid result. * libc/stdlib/strtorQ.c: New file, adapted from FreeBSD gdtoa. * libc/stdlib/strtold.c (_strtold_impl): New helper selecting strtorx for 80-bit and strtorQ for 128-bit long double. (_strtold_r, strtold_l, strtold): Use _strtold_impl. * libc/stdlib/mprec.h (_strtorQ_l): Declare. * libc/stdlib/Makefile.inc (libc_a_SOURCES): Add strtorQ.c. * newlib/Makefile.in: Regenerate with automake Signed-off-by: Zakaria Fadli <fadli@adacore.com>
2025-08-27amdgcn, libm: fix vector ilogb bugs (bug 33272)Andrew Stubbs5-97/+99
The vector ilogb routines, including the ones inlined into fmod, had a bug in which the conditional masks were not properly applied, causing the value of one lane to be affected by conditional choices of another lane. The problem was not immediately obviously because all values were calculated correctly when no lane contained a subnormal input. The problem is fixed by proper use of VECTOR_COND_MOVE and VECTOR_WHILE.
2025-08-14rtems: No-return _arc4random_getentropy_fail()Sebastian Huber1-1/+1
The _arc4random_getentropy_fail() function does not return. Mark it as such.
2025-08-08amdgcn, libm: fix infinite loopAndrew Stubbs1-2/+5
The end condition on this loop, unlike all the other similar loops, is "i >= 0", which is a problem because "i <<= 1" can go negative and then zero if you continue shifting, and so back to true, again. This isn't a problem for the loop in the scalar implementation, but it means we need to mask the shift in the vector implementation. This fixes GCC PR#121392.
2025-08-07Added target m68k-atari-elf supporting Atari 16/32bit TOS systems.Mikael Hildenborg1-1/+4
2025-08-04sys/_default_fcntl.h: Define OFD lock operationsCorinna Vinschen1-0/+5
Linux and POSIX-1.2024 define operations to create OFD (Open File Description) locks. OFD locks are like POSIX record locks, but bound to the file descriptor, not bound to the process. As such, they are also inherited via fork(2) and dup(2), just like BSD flock(2) locks. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-08-04sys/_default_fcntl.h: fix whitespaceCorinna Vinschen1-11/+11
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-07-25newlib: libc: return back support for AArch64 ILP32Radek Bartoň14-10/+64
This patch is returning back support for AArch64 ILP32 ABI that was removed in de479a54e22e8fcb6262639a8e67fe8b00a27c37 commit but is needed to ensure source code compatibility with GCC 14. The change in newlib/libc/machine/aarch64/asmdefs.h makes it out-of-the-sync with the current upstream implementation in https://github.com/ARM-software/optimized-routines repository. Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2025-07-25Revert Joel's working ilp32 patchJoel Sherrill16-108/+54
This was what I was using locally before Radek Bartoň <radek.barton@microsoft.com> had his version of the patch. Revert in favor of his final version. Revert 70c5505766ad4ae62e4d045835ed2a6b928d5760
2025-07-25ilp32: Revert patch removing ilp32 supportJoel Sherrill16-54/+108
ilp32 support was removed prematurely. It is still in GCC 15 which is the latest GCC release. From: <radek.barton@microsoft.com> Date: Thu, 5 Jun 2025 11:32:08 +0200 Subject: [PATCH] newlib: libc: update asmdefs.h compatible with Cygwin AArch64 This patch synchronizes newlib/libc/machine/aarch64/asmdefs.h header with version from https://github.com/ARM-software/optimized-routines/commit/4352245388a55a836f3ac9ac5907022c24ab8e4c commit that added support for AArch64 Cygwin. This version of the header removed PTR_ARG and SIZE_ARG macros as ILP32 was deprecated which introduced changes in many .S files so the patch contains removal of usages of those macros. On top of that, setjmp.S and rawmemchr.S were refactored to use ENTRY/ENTRY_ALIGN and END macros. ` Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2025-07-24Revert "mbrtowc: fix handling invalid UTF-8 4 byte sequences if wchar_t == ↵Corinna Vinschen1-16/+9
UTF-16" This reverts commit b374973d14ac7969b10ba719feedc709f6971c0d. Turns out this patch breaks mbrtowc. Example: --- SNIP --- void mb(unsigned char c) {   wchar_t wc;   int ret = mbrtowc(&wc, &c, 1, 0);   printf("%02X -> %04X : %d\n", c, wc, ret); } void main () {   setlocale (LC_CTYPE, "");   mb(0xF0);   mb(0x9F);   mb(0x98);   mb(0x8E); } --- SNAP --- Output before commit b374973d14ac: F0 -> 0000 : -2 9F -> 0000 : -2 98 -> D83D : 1 8E -> DE0E : 1 Output after commit b374973d14ac: F0 -> 0000 : -2 9F -> 0000 : -2 98 -> 0000 : -2 8E -> D83D : 3 By using mbrtowc(), the high surrogate is only emitted after byte 4, and there's no way to recover the low surrogate. The byte count is also incorrect. Conclusion: We have to emit the high surrogate already after byte 3 to be able to emit the low surrogate after byte 4. Reported-by: Thomas Wolff <towo@towo.net> Addresses: https://cygwin.com/pipermail/cygwin/2025-July/258513.html Fixes: b374973d14ac ("mbrtowc: fix handling invalid UTF-8 4 byte sequences if wchar_t == UTF-16") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-07-23sys/cdefs.h: Protect parameters to __builtin_is_aligned()Paul Cercueil1-1/+1
The macro was not protecting properly its first parameter, which caused it to silently return an invalid value when passing a composed parameter, ie. __builtin_is_aligned(src | dst | len, 32); Signed-off-by: Paul Cercueil <paul@crapouillou.net>
2025-07-23Reapply "libc/stdio: Remove wchar_t functions from NEWLIB_NANO_FORMATTED_IO"Corinna Vinschen2-471/+471
This reverts commit bb2c338520b9da9fd3ac067438e9aeeffc0b122a. Accidental push.
2025-07-23Revert "libc/stdio: Remove wchar_t functions from NEWLIB_NANO_FORMATTED_IO"Hau Hsu2-471/+471
This reverts commit 3b97a5ec67a5a52c130158bb143949cd842de305.
2025-07-21newlib: add dummy implementations of fe{get,set}prec for Aarch64 CygwinRadek Bartoň5-0/+96
This patch introduces dummy implementation of fegetprec and fsetprec for Cygwin build as those symbols are being exported by cygwin1.dll and AArch64 do not support changing floating point precision at runtime. Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2025-07-17libc/include/sys/stat.h: Adjust for RTEMS MIPSJoel Sherrill1-2/+3
The commit cited below introduced changes which included conditionals strictly on __mips__. This ignored tailoring for any environment on MIPS except that targeted by the author of the change. This patch just fixes this code for RTEMS. commit 467a2bdf17ad376dafada9f1734784f4611fa6fd Author: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com> Date: Wed Jun 11 10:11:33 2025 +0200 mips: Implement MIPS HAL and UHI Implement abstract interface for MIPS, including unified hosting interface (UHI). Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
2025-07-17nvptx: Change 'read' and 'write' to 'ssize_t' return typeArijit Kumar Das3-2/+8
This commit changes the return type of the read() and write() syscalls for nvptx to ssize_t. This would allow large files to be handled properly by these syscalls in situations where the read/write buffer length exceeds INT_MAX, for example. This also makes the syscall signatures fully complaint with their current POSIX specifications. We additionally define two macros: '_READ_WRITE_RETURN_TYPE' as _ssize_t and '_READ_WRITE_BUFSIZE_TYPE' as __size_t in libc/include/sys/config.h under __nvptx__ for consistency. Signed-off-by: Arijit Kumar Das <arijitkdgit.official@gmail.com>
2025-07-17newlib: libc: update asmdefs.h compatible with Cygwin AArch64Radek Bartoň16-108/+54
This patch synchronizes newlib/libc/machine/aarch64/asmdefs.h header with version from https://github.com/ARM-software/optimized-routines/commit/4352245388a55a836f3ac9ac5907022c24ab8e4c commit that added support for AArch64 Cygwin. This version of the header removed PTR_ARG and SIZE_ARG macros as ILP32 was deprecated which introduced changes in many .S files so the patch contains removal of usages of those macros. On top of that, setjmp.S and rawmemchr.S were refactored to use ENTRY/ENTRY_ALIGN and END macros. ` Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2025-07-17newlib: fclose: Use sfp lock while fp lock is activeTakashi Yano1-1/+2
With the commit 656df313e08a, if a thread acquires sfp lock after another thread calls fclose() and fp lock is acquired, the first thread falls into deadlock if it tries to acquire fp lock. This can happen if the first thread calls __sfp_lock_all() while the second thread calls fclose(). This patch reverts the changes for newlib/libc/stdio/fclose.c in the commit 656df313e08a. Addresses: https://cygwin.com/pipermail/cygwin/2025-June/258323.html Fixes: 656df313e08a ("* libc/stdio/fclose.c: Only use sfp lock to guard non-atomic changes of flags and fp lock.") Reported-by: Takashi Yano <takashi.yano@nifty.ne.jp> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-07-16libc/time: Add CLOCK_TAISebastian Huber1-0/+6
For _GNU_VISIBLE, provide the CLOCK_TAI clock identifier for the International Atomic Time. Use the value specified by glibc and Linux. Add _BSD_VISIBLE given FreeBSD also provides this clock identifier.
2025-07-10newlib: Regenerate configuration filesm fally1-26/+26
Regenerate the configuration files since a file was replaced in the RISC-V port, and one other file was renamed. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-07-10RISC-V: memmove() speed optimized: Call memcpy()m fally1-67/+93
Redirect to memcpy() if the memory areas of source and destination do not overlap. Only redirect if length is > SZREG in order to reduce overhead on very short copies. Signed-off-by: m fally <marlene.fally@gmail.com>
2025-07-10RISC-V: memmove() speed optimized: Align source addressm fally1-50/+135
If misaligned accesses are slow or prohibited, either source or destination address are unaligned and the number of bytes to be copied is > SZREG*2, align the source address to xlen. This speeds up the function in the case where at least one address is unaligned, since now one word (or doubleword for rv64) is loaded at a time, therefore reducing the amount of memory accesses necessary. We still need to store back individual bytes since the destination address might (still) be unaligned after aligning the source. The threshold of SZREG*2 was chosen to keep the negative effect on shorter copies caused by the additional overhead from aligning the source low. This change also affects the case where both adresses are xlen- aligned, the memory areas overlap destructively, and length is not a multiple of SZREG. In the destructive-overlap case, the copying needs to be done in reversed order. Therefore the length is added to the addresses first, which causes them to become unaligned. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-07-10RISC-V: memmove() speed optimized: Add loop-unrollingm fally1-9/+48
Add loop-unrolling for the case where both source and destination address are aligned in the case of a destructive overlap, and increase the unroll factor from 4 to 9 for the word-by-word copy loop in the non-destructive case. This matches the loop-unrolling done in memcpy() and increases performance for lenghts >= SZREG*9 while almost not at all degrading performance for shorter lengths. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-07-10RISC-V: memmove() speed optimized: Replace macros and use fixed-width typesm fally1-25/+35
Replace macros with static inline functions or RISC-V specifc macros in order to keep consistency between all functions in the port. Change data types to fixed-width and/or RISC-V specific types. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-07-10RISC-V: memmove() speed optimized: Add implementationm fally4-15/+100
Copy the common implementation of memmove() to the RISC-V port. Rename memmove.S to memmove-asm.S to keep naming of files consistent between functions. Update Makefile.inc with the changed filenames. Reviewed-by: Christian Herber <christian.herber@oss.nxp.com> Signed-off-by: m fally <marlene.fally@gmail.com>
2025-07-09posix_spawn: preserve FD flags when processing FAE_OPENJeremy Drake1-3/+11
According to the POSIX documentation, "when the new process image is executed, any file descriptor (from this new set) which has its FD_CLOEXEC flag set shall be closed (see posix_spawn())." The "new set" is after processing the file actions, so if addopen had the O_CLOEXEC flag set the descriptor should be closed after the exec. The adddup2 docs, by contrast, specify that the flag should be cleared, even if dup2 wouldn't have done so due to the specified file descriptors being equal. Add a comment to that effect. Addresses: https://sourceware.org/pipermail/newlib/2025/021968.html Fixes: c7c1a1ca1b ("2013-10-01 Petr Hosek <phosek@chromium.org>") Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-07-04libc: mips: fix strcmp bug for little endian targetsFaraz Shahbazker1-2/+5
strcmp gives incorrect result for little endian targets under the following conditions: 1. Length of 1st string is 1 less than a multiple of 4 (i.e len%4=3) 2. First string is a prefix of the second string 3. The first differing character in the second string is extended ASCII (that is > 127) Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
2025-07-04libc: mips: Improve performance of strcmp implementationFaraz Shahbazker1-79/+123
Improve `strcmp` by using `ext` instruction, if available. Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
2025-07-04libc: mips: memcpy prefetches beyond copied memoryFaraz Shahbazker1-53/+97
Fix prefetching in core loop to avoid exceeding the operated upon memory region. Revert accidentally changed prefetch-hint back to streaming mode. Refactor various bits and provide pre-processor checks to allow parameters to be overridden from compiler command line. Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
2025-07-04libc: mips: Add improved C implementation of memcpy/memsetFaraz Shahbazker4-5/+586
Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
2025-07-04mips: Implement MIPS HAL and UHIJovan Dmitrović8-121/+158
Implement abstract interface for MIPS, including unified hosting interface (UHI). Signed-off-by: Jovan Dmitrović <jovan.dmitrovic@htecgroup.com>
2025-07-04aarch64: Export fe{enable,disable,get}except on CygwinRadek Bartoň1-4/+12
For aarch64 on ELF targets, the library does not export fe{enable,disable,get}except as symbols from the library, relying on static inline functions to provide suitable definitions if required. But for Cygwin we need to create real definitions to satisfy the DLL export script. So arrange for real definitions of these functions when building on Cygwin. Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2025-07-02wcstombs: also call __WCTOMB on terminating NUL if output buffer is NULLChristian Franke1-3/+4
A __WCTOMB call on the terminating NUL may emit more than a NUL byte. This is the case if the string ends with a lone UTF-16 high surrogate. Fixes: 2a3a02a68764 ("Add SUSV2 support for calculating size if output buffer is NULL") Signed-off-by: Christian Franke <christian.franke@t-online.de>
2025-07-02newlib: increase jump buffer length to 25 to fit all non-volatile registers ↵Radek Bartoň1-1/+10
for aarch64-pc-cygwin Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
2025-07-02RISC-V: Fix memcpy() for GCC 13Sebastian Huber1-2/+2
GCC 13 does not define the __riscv_misaligned_* builtin defines. They are supported by GCC 14 or later. Test for __riscv_misaligned_fast to select an always correct memcpy() implementation for GCC 13. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2025-06-29wcrtomb: fix CESU-8 value of leftover lone high surrogateChristian Franke1-2/+2
Addresses: https://cygwin.com/pipermail/cygwin/2025-June/258378.html Fixes: 6ff28fc3b121 ("Allow CESU-8 surrogate value encoding") Signed-off-by: Christian Franke <christian.franke@t-online.de>
2025-06-27mbrtowc: fix handling invalid UTF-8 4 byte sequences if wchar_t == UTF-16Corinna Vinschen1-9/+16
When commit 28186e81d947 split _mbtowc_r into per-codeset functions, the code generating wchar_t from UTF-8 input was slightly rearranged. Unfortunately the new code introduced a bug: On systems with wchar_t being UTF-16, 4 byte sequences have to be converted to surrogate pairs. The low surrogate pair can be fully created from the first 3 bytes of the sequence. However, the surrogates should only be created if it's clear that the 4th byte is valid, and the entire 4 byte string represents a valid UTF-8 sequence. The code change in 28186e81d947 neglected just that: In contrast to the original code, it now created the low surrogate after having read the first 3 bytes of the sequence, without checking validity of the 4th byte. This patch moves the test sequence to check the 4th byte in front of the code generating the low surrogate. Make sure to return the value 3 (3 bytes digested) rather than the content of the local variable i, which is already set to 4 at this point. Reported-by: Christian Franke <Christian.Franke@t-online.de> Addresses: https://cygwin.com/pipermail/cygwin/2025-June/258358.html Fixes: 28186e81d947 ("* libc/ctype/iswalpha.c: Handle all wchar_t as unicode on _MB_CAPABLE systems.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>