Commit Graph

3792 Commits

Author SHA1 Message Date
Corinna Vinschen 422c4f0451 memccpy: fix pointer assignment
The local vars dst and src are unsigned pointers, but two assignments
cast their value to signed explicitely.  This results in the warning
"pointer targets in assignment from ‘char *’ to ‘unsigned char *’
differ in signedness [-Wpointer-sign]" in case of -Wall.

Fix the cast.

Fixes: d254189b38 ("2002-07-23  Jeff Johnston  <jjohnstn@redhat.com>")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-19 11:51:01 +01:00
Corinna Vinschen 29ec33360d ORIENT: avoid "expression has no effect" warning
The warning "right-hand operand of comma expression has no effect
[-Wunused-value]" crops up with -Wall in cases where ORIENT is called
without checking or assigning its value.

Explicitely void the expression in these cases to avoid the warning.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-19 11:51:01 +01:00
Corinna Vinschen d13d9220bf _fputwc_r: actually return result of __fputwc
Compiling with -Wall uncovered a bug in _fputwc_r introduced in
commit 09119463a1 ("stdio: split byte- and wide-char-oriented
low-level output functions").  The underlying function __fputwc
has been accidentally called without fetching its return value.
So the return value of _fputwc_r (and thus fputwc) was undefined.

Fixes: 09119463a1 ("stdio: split byte- and wide-char-oriented low-level output functions"
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-19 11:13:39 +01:00
Christian Franke d8c0fb090c Cygwin: introduce close_range(2)
This function closes or sets the close-on-exec flag for a specified
range of file descriptors.  It is available on FreeBSD and Linux.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-01-15 12:52:56 +01:00
Brian Inglis 9a863f713a fix strverscmp comparison of digit sequence with non-digits
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 7 Nov 2022 22:17:55 -0500

the rule that longest digit sequence not beginning with a zero is
greater only applies when both sequences being compared are
non-degenerate. this is spelled out explicitly in the man page, which
may be deemed authoritative for this nonstandard function: "If one or
both of these is empty, then return what strcmp(3) would have
returned..."

we were wrongly treating any sequence of digits not beginning with a
zero as greater than a non-digit in the other string.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2024-01-08 17:01:25 +01:00
Xiao Zeng 99f3898dfc newlib: libc: Improved the readability of strspn with minor optimization
Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
2024-01-02 14:11:07 -05:00
Jeff Johnston 26f7004bf7 Changes for newlib 4.4.0 snapshot
- bump up version to 4.4.0
2023-12-31 12:00:18 -05:00
Jeff Law ec119e1084 Minor improvement to H8 startup code
Basically the startup code needs to clear memory from _edata to _end. In the
past it's been done with a fairly naive copy loop.  This changes the code to
just call memset and let memset figure out a sensible way to handle the
operation given the size and alignment requirements.

I don't have performance data on this.  I cobbled it together some time ago in
response to seeing some of the GCC tests with larger .bss sections taking an
insane amount of time to just get from _start to main.  With the fixes to the
H8 decoder in the simulator it may not matter nearly as much anymore.

This has been in my tester for months.  Naturally it does not cause any
regressions in the H8 port.
2023-12-31 09:08:21 -07:00
Hans-Peter Nilsson ddb614993a newlib MMIX: Fix compilation warnings that recent gcc treats as errors
Without this, when building with recent gcc, we'll see errors when
compiling for --target mmix the first being:
  CC       libc/sys/mmixware/libc_a-chmod.o
In file included from /x/newlib/libc/sys/mmixware/chmod.c:17:
/x/newlib/libc/sys/mmixware/chmod.c: In function 'chmod':
/x/newlib/libc/sys/mmixware/sys/syscall.h:139:6: error: implicit declaration \
of function 'sprintf' [-Wimplicit-function-declaration]
  139 |      sprintf (buf, "UNIMPLEMENTED %s in %s\n", __FUNCTION__,
 __FILE__); \

Other warnings also quelled.

	* libc/sys/mmixware/sys/syscall.h: Include stdio.h, string.h
	and unistd.h.
	* libc/sys/mmixware/_exit.c: Call __unreachable after simulator exit.
	* libc/sys/mmixware/chown.c (chown): Match declaration in unistd.h.
	* libc/sys/mmixware/getpid.c (_getpid): Ditto.
	* libc/sys/mmixware/kill.c (_kill): Ditto.
	* libc/sys/mmixware/link.c (_link): Ditto.
	* libc/sys/mmixware/read.c (_read): Ditto.
	* libc/sys/mmixware/sbrk.c (_sbrk): Ditto.
	* libc/sys/mmixware/unlink.c (_unlink): Ditto.
	* libc/sys/mmixware/write.c (_write): Ditto.
2023-12-29 19:29:20 +01:00
Thomas Schwinge 1a177610d8 GCN: Implement '_exit' instead of 'exit'
... so that all of 'exit', '_exit', '_Exit' work.  'exit' thus becomes the
standard 'newlib/libc/stdlib/exit.c'.  (Getting 'atexit' functional needs
further work elsewhere.)

See also commit 5841b2f6a4
"nvptx: Implement '_exit' instead of 'exit'".
2023-12-23 10:26:58 +01:00
Jeff Law dc7ee58132 Fix newlib H8/300 bits for C99/gcc-14
Similar to other patches.  This adds a missing prototype and #include to some
H8/300 specific code in newlib.  Pushed to the trunk given Jeff J's
pre-approval for these kinds of changes.
2023-12-22 20:25:10 -07:00
Jeff Johnston 188ca64934 Optimize strpbrk.c 2023-12-21 14:04:49 -05:00
Craig Blackmore 73bce6597c newlib: Fix long double for unsupported rounding modes and exceptions
RISC-V newlib fails to build for soft float multilibs since long double
support was enabled in:

  commit 04798b7bb6
  Author: Kito Cheng <kito.cheng@sifive.com>
  Date:   Mon Dec 4 15:41:39 2023 +0800

      RISC-V: Support long double math

      Long double for RISC-V is using 128 bit IEEE 754 format like Aarch64,
      so we reference AArch64 to support that.

The RISC-V soft floating point environment only supports the
FE_TONEAREST rounding mode and does not support exceptions.  Guard long
double rounding and exception support with ifdefs based on the presence
of the relevant rounding modes and exceptions.

Tested on gcc/g++ testsuite using RISC-V GNU Newlib Toolchain built by
riscv-gnu-toolchain with multilibs:

    riscv-sim/-march=rv32i/-mabi=ilp32/-mcmodel=medlow
    riscv-sim/-march=rv32iac/-mabi=ilp32/-mcmodel=medlow
    riscv-sim/-march=rv32im/-mabi=ilp32/-mcmodel=medlow
    riscv-sim/-march=rv32imac/-mabi=ilp32/-mcmodel=medlow
    riscv-sim/-march=rv32imafc/-mabi=ilp32f/-mcmodel=medlow
    riscv-sim/-march=rv64imac/-mabi=lp64/-mcmodel=medlow

Co-authored-by: Simon Cook <simon.cook@embecosm.com>
2023-12-20 16:54:22 -05:00
Xiao Zeng b639245932 newlib: libc: Improved the readability of strcspn with minor optimization
Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
2023-12-19 23:23:31 -05:00
Jeff Law c1a61029fe Fix various v850 problems
These fixes fall into a few different buckets.  First c99 doesn't allow a
parameter without a type.  So in cases where the type had previously been an
implicit int, make it an explicit int.  Second, for return values, don't allow
them to be implicit ints either, make them explicit. In a few cases change c89
function definitions to c99 function definitions.   Lastly include <stdlib.h>
in sbrk.c to get the prototype for abort () which we call when we detect a
heap/stack collision.
2023-12-19 20:56:04 -07:00
Jeff Johnston f81bf08f7c Add generated files for Revert patch 2023-12-19 13:58:12 -05:00
Mike Frysinger b67114d7d8 Revert "Fix libgloss/newlib build to conditionally use top include dir"
This reverts commit 17ac400c11.

The build failures were due to incorrectly using $(INCLUDES) when
running $(AS).  Let's roll this back and drop $(INCLUDES) from the
$(AS) invocations.
2023-12-19 13:37:02 -05:00
Freddie Chopin 60c6397133 Remove curly braces in `@author` tag in .texi files
Curly braces cause documentation build failure with texinfo 7.1 (works fine
up to 7.0.3):
2023-12-19 13:28:18 -05:00
Hans-Peter Nilsson 3bafe2fae7 newlib cris: Fix compilation warnings that recent gcc treats as errors
For the newlib part, warnings are all from lack of sync between
libc/machine/cris/sys/signal.h and libc/include/sys/signal.h.  This
commit gets them sufficiently in sync again, functionality-wise and
declaration-wise.  Still, nothing is declared that isn't supported at
the system level (i.e. in libgloss system calls and handled by the
CRIS simulator in the gdb project).
2023-12-06 18:46:49 +01:00
Dimitar Dimitrov 14d786873c pru: libm: Fix incorrect function name
Upstream GCC changed -Wimplicit-function-declaration warning into an
error. The build break about missing fpclassifyf function prototype
exposed a bug in the PRU port of libm.

The fix is to use the fpclassify macro for both double and float types.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2023-12-04 17:01:05 +01:00
Kito Cheng 04798b7bb6 RISC-V: Support long double math
Long double for RISC-V is using 128 bit IEEE 754 format like Aarch64,
so we reference AArch64 to support that.
2023-12-04 10:26:41 +01:00
Kuan-Wei Chiu b64d0d53af newlib: libc: Fix indentation
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
2023-12-02 22:22:26 -05:00
Kuan-Wei Chiu 65f7ab0bb9 newlib: libc: Fix memory leak in computematchjumps()
In cases where malloc fails for the 'g->matchjump' allocation, the code
path does not handle the failure gracefully, potentially leading to a
memory leak. This fix ensures proper cleanup by freeing the allocated
memory for 'pmatches' before returning.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
2023-12-01 19:28:55 +01:00
Mike Frysinger dab15f6740 newlib: filter out versions from newlib.h to simplify autoreconf
We've been manually editing newlib.hin after generating it with
autoheader to drop the version defines that we keep in the separate
_newlib_version.h header.  This is confusing for people, and is an
easy source of mistakes/errors.

Since we're already running sed on newlib.h during configure to
filter out defines we don't want to expose, add the version macros
there too.  This way we don't have to manually edit newlib.hin.

This simplifies the autoreconf step in exchange for a slightly more
complicated configure+sed step, but seems worth the trade-off.
2023-11-28 12:50:44 -05:00
Takashi Yano 0e961f582a newlib: nl_langinfo: Fix a bug of time stuff.
Previously, e.g. nl_langinfo(_NL_TIME_WMONTH_1) returns "February"
due to the bug. Similarly, nl_langinfo(_NL_TIME_WWDAY_1) returns
"Mon". This occurs because wide char month and weekday arrays are
pointed off-by-one (e.g. the array wmon[12] is reffered as wmon[1-12]
rather than wmon[0-11]). This patch fixes that.

Fixes: d47d5b850b ("Extend locale support to maintain wide char values of native strings")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-11-24 09:53:11 +09:00
Sebastian Huber 3cacedbbac aarch64: Remove duplicated optimized memmove()
The optimized aarch64/memcpy.S already provides a memmove() implementation.
2023-11-21 10:48:43 +01:00
Corinna Vinschen 61e52c4d60 stdio: drop unnecessary calls to ORIENT
Now that the low-level functions set and test stream orientation,
a few calls in API functions are redundant.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-20 20:59:47 +01:00
Corinna Vinschen c190063f96 stdio: set and test stream orientation in low-level input function __srget_r
This allows to set and test orientation correctly if input is only
using macros from stdio.h.  Wide-char-oriented functions must call
__srefill_r directly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-20 20:59:13 +01:00
Corinna Vinschen 09119463a1 stdio: split byte- and wide-char-oriented low-level output functions
Introduce function __swbufw_r and macros/inline-functions called
__swputc_r.  Call these functions/macros exclusively from wide-char
functions.

This allows to set and test the stream orientation correctly even if
output is only performed using byte-oriented macros from stdio.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-20 20:59:13 +01:00
Takashi Yano bc986b7ff6 stdio: Fix bugs in commit 3d94e07c49
The commit 3d94e07c49 has a few bugs which cause testsuite failure
in libstdc++. This is due to excess orientation check in __srefill_r()
and _ungetc_r(). Further, sscanf() family also calls ssvfscanf() family
with fp->_file == -1. This causes undesired orientation set/check for
sscanf() family. This patch fixes these problems.

Also, as in GLibC, do not set orientation in ungetc, and only set, but
do not check orientation in ungetwc.

Fixes: 3d94e07c49 ("newlib: libc: Fix crash on fprintf to a wide-oriented stream.")
Reported-by: Christophe Lyon <christophe.lyon@linaro.org>
Reported-by: Joel Sherrill <joel@rtems.org>
Co-developed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-20 20:59:12 +01:00
Chris Johns 37e67d1595 Reclaim _REENT_MP_P5S in _reclaim_reent
The _REENT_MP_P5S blocks are allocated using Balloc via i2b and linked in the
pow5mult call. As a result these blocks are not on the freelist managed by the
Bfree call. This change fixes a memory leak in threads that clean up using
_reclaim_reent.

RTEMS: Closes #4967
2023-11-20 10:49:39 +01:00
Corinna Vinschen 6ccbfe6a3d __sfvwrite_r: call __sputc_r rather than putc in __SCLE case
__sfvwrite_r is called under lock.  There's no reason to call
putc, locking the file recursively.  Add a comment that locking
is required when calling __sfvwrite_r.

Fixes: 49d64538cd ("* libc/include/stdio.h (FILE): define __SCLE for "convert line endings" for Cygwin.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-17 17:09:42 +01:00
Corinna Vinschen 61ccd3f94f v{fs}printf/v{fs}wprintf: create external output helpers
So far, the printf family of functions has two output helper functions
called __sprint_r and __sfputs_r.  Both are called from all variants of
vfprintf as well as vfwprintf.  There are also analogue helper functions
 for the string-creating functions vsprintf/vswprintf called __ssprint_r
and __ssputs_r.

However, the helpers are built once when building vfprintf/vsprintf with
the INTEGER_ONLY flag, and then they are part of the vfiprintf.c and
vsiprintf.c files.

The problem is this:

Even if a process only calls vfwprintf or the non-INTEGER_ONLY vfprintf
it will always have to include the INTEGER_ONLY vfiprintf. Otherwise the
helper functions are undefined.  Analogue for the string-creating
functions.

That's a useless waste of space by including one (or two) big, unused
function, if newlib is linked in statically.

Create new files to define the printf output helpers separately and
split them into byte-oriented and wide-char-oriented functions.  This
allows to link only the required functions.

Also, simplify the string output helpers and fix a potential (but
unlikely) buffer overflow in __ssprint_r.

Fixes: 8a0efa53e4 ("import newlib-2000-02-17 snapshot")
Fixes: 6121968b19 ("* libc/include/stdio.h (__VALIST): Guard against multiple definition.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-17 13:10:20 +01:00
Corinna Vinschen 7e4840bc45 newlib.hin: regenerate
The last two patches to configure.ac missed regeneration of newlib.hin.

Fixes: 64a11fded1 ("Fix problem with _newlib_version.h not being filled in correctly")
Fixes: 39f734a857 ("newlib: fix AC_DEFINE quoting style with version macros")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-11-17 13:10:20 +01:00
Takashi Yano 3d94e07c49 newlib: libc: Fix crash on fprintf to a wide-oriented stream.
Previously, fprintf() on a wide-oriented stream crashes or outputs
garbage. This is because a narrow char string which can be odd bytes
in length is cast into a wide char string which should be even
bytes in length in __sprint_r/__sfputs_r based on the __SWID flag.
As a result, if the length is odd bytes, the reading buffer runs over
the buffer length, which causes a crash. If the length is even bytes,
garbage is printed.

With this patch, any output to the stream which is set to different
orientation fails with error just like glibc. Note that it behaves
differently from other libc implementations such as BSD, musl and
Solaris.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-11-10 00:36:41 +09:00
Andrew Stubbs 12e3bac3ce amdgcn: remove unnecessary scalar cache flush
The exit code isn't actually written via the scalar cache so the cache flush
is not actually needed.
2023-10-31 13:36:45 +01:00
Mike Frysinger 39f734a857 newlib: fix AC_DEFINE quoting style with version macros
configure.ac files use [] for quoting by default, not "", which
means the "" are passed through as literals.  We don't want that
for these comments, so change the "..." to [...].
2023-10-15 15:10:52 +05:45
Sebastian Huber fbc5496e40 sparc: Improve setjmp()
Flush the windows in setjmp().  This helps if the stack is changed after
the setjmp() and we want to jump back to the original stack using
longjmp().
2023-10-12 17:04:38 +02:00
Sebastian Huber 696c282cf3 riscv: Fix fenv.h support
Use the same C preprocessor expressions to define FE_RMODE_MASK and
__RISCV_HARD_FLOAT.

The problem was noticed on GCC 10 which does not define __riscv_f.
2023-10-12 16:46:21 +02:00
Joseph Faulls dcb2b7d7b8 Delete check in catan, catanf, and catanl functions.
The check incorrectly results in catan returning nan + inf i when real part is +/- 1 and
imaginary part is 0.  The same occurs for real 0.8 and imaginary 0.6.

The change ends up matching glibc behaviour.
2023-10-10 15:18:54 -04:00
Sebastian Huber fe5886a500 aarch64: Import memrchr.S
Import memrchr.S for AArch64 from:

https://github.com/ARM-software/optimized-routines

commit 0cf84f26b6b8dcad8287fe30a4dcc1fdabd06560
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Thu Jul 27 17:14:57 2023 +0200

    string: Fix corrupt GNU_PROPERTY_TYPE (5) size

    For ELF32 the notes alignment is 4 and not 8.
2023-10-05 14:16:59 +02:00
Sebastian Huber 96ec8f868e aarch64: Sync with ARM-software/optimized-routines
Update AArch64 assembly string routines from:

https://github.com/ARM-software/optimized-routines

commit 0cf84f26b6b8dcad8287fe30a4dcc1fdabd06560
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Thu Jul 27 17:14:57 2023 +0200

    string: Fix corrupt GNU_PROPERTY_TYPE (5) size

    For ELF32 the notes alignment is 4 and not 8.

Add license and copyright information to COPYING.NEWLIB as entry (56).
2023-10-05 14:16:57 +02:00
Torbjörn SVENSSON a9e8e3d1cb newlib: Add missing prototype for _getentropy 2023-09-25 18:20:25 -04:00
Alexey Lapshin 6e5676a915 newlib: Fix header install 2023-09-18 18:45:34 +02:00
Pekka Seppänen c2d2bf34e6 Reentrancy, attempt to always provide _Thread_local in <sys/reent.h>
Attempt to always provide _Thread_local in <sys/reent.h> by including
<sys/cdefs.h>.  The C specific keyword _Thread_local is not available
unless targetting a suitable C version.
2023-09-11 09:23:05 +02:00
Pekka Seppänen 7a1c717c8b Reentrancy, conditionally provide default __getreent() implementation
Conditionally provide default __getreent() implementation only if
_REENT_THREAD_LOCAL is not defined.  If struct _reent is replaced by
dedicated thread-local objects neither the structure nor _impure_ptr is
available.
2023-09-11 09:23:05 +02:00
Pekka Seppänen 766f1beb4d Reentrancy, use _REENT_ERRNO()
Use _REENT_ERRNO() macro to access errno.  This encapsulation is
required, as errno might be either _errno member of struct _reent,
_tls_errno or any such implementation detail.
2023-09-11 09:23:05 +02:00
Pekka Seppänen 31eb43efa7 libc/stdlib/nano-mallocr.c, typo in variable name
Nano malloc uses `size' in assertation whereas the correct variable would be
`s'.  Given this has existed ever since nano malloc support was added, based
on the context ("returned payload area of desired size does not exceed the
actual allocated chunk") I presume that indeed `s' (user input) and not
`r->size' (computed) shall be used.
2023-08-29 14:33:27 +02:00
Alexey Lapshin 42eb6e5ddf newlib: fix 'sed' for sys headers path prefix
Precisely remove the prefix from the filepath.
2023-08-29 13:42:27 +02:00
Alexey Lapshin 7ba103eb1a newlib: add Xtensa port 2023-08-17 18:14:15 -04:00