Commit Graph

2834 Commits

Author SHA1 Message Date
Giacomo Tesio ded03c70bf Merge branch 'upstream-master' into merge-upstream-20200829 2020-08-29 00:05:13 +02:00
Eshan dhawan via Newlib 39f057e2aa Enabled _CS* defines for RTEMS
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-08-25 20:54:33 +02:00
Keith Packard via Newlib 8a7ec55c53 libm/stdlib: Realloc when shrinking by 2* or more
This reduces memory usage when reallocating objects much smaller.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-17 11:43:55 +02:00
Keith Packard via Newlib ce4044adee libm/stdlib: don't read past source in nano_realloc
Save the computed block size and use it to avoid reading past
the end of the source block.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-17 11:43:55 +02:00
Craig Blackmore ab215e3dd1 libc/stdlib: Fix build failure in nano_calloc
commit 588a5e1dde added a non-reentrant
call to nano_malloc which causes a build failure if INTERNAL_NEWLIB is
defined.

Here is a snippet of the error:

In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38:
.../newlib/newlib/libc/include/malloc.h:42:25: note: expected 'struct _reent *' but argument is of type 'ptrdiff_t' {aka 'int'}
   42 | extern void *_malloc_r (struct _reent *, size_t);
      |                         ^~~~~~~~~~~~~~~
.../newlib/newlib/libc/stdlib/nano-mallocr.c:67:22: error: too few arguments to function '_malloc_r'
   67 | #define nano_malloc  _malloc_r
      |                      ^~~~~~~~~
.../newlib/newlib/libc/stdlib/nano-mallocr.c:456:11: note: in expansion of macro 'nano_malloc'
  456 |     mem = nano_malloc(bytes);
      |           ^~~~~~~~~~~
In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38:
.../newlib/newlib/libc/include/malloc.h:42:14: note: declared here
   42 | extern void *_malloc_r (struct _reent *, size_t);
      |              ^~~~~~~~~
.../newlib/newlib/libc/stdlib/nano-mallocr.c:43: warning: "assert" redefined
   43 | #define assert(x) ((void)0)
      |

This patch adds a missing RCALL to the args when calling nano_malloc
from nano_calloc, so that if the call is reentrant, reent_ptr is passed
as the first argument.

The variable `bytes` (also added in 588a5e1d) has been changed from a
`ptrdiff_t` to `malloc_size_t` as it does not need to be signed. It is
used to store the product of two unsigned malloc_size_t variables and
then iff there was no overflow is it passed to malloc and memset which
both expect size_t which is unsigned.

Signed-off-by: Craig Blackmore <craig.blackmore@embecosm.com>
2020-08-13 09:59:45 +02:00
Keith Packard via Newlib 588a5e1dde libc/stdlib: Use __builtin_mul_overflow for reallocarray and calloc
This built-in function (available in both gcc and clang) is more
efficient and generates shorter code than open-coding the test.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-12 10:09:56 +02:00
Keith Packard via Newlib c3ce8405c1 libm: Control errno support with _IEEE_LIBM configuration parameter
This removes the run-time configuration of errno support present in
portions of the math library and unifies all of the compile-time errno
configuration under a single parameter so that the whole library
is consistent.

The run-time support provided by _LIB_VERSION is no longer present in
the public API, although it is still used internally to disable errno
setting in some functions. Now that it is a constant, the compiler should
remove that code when errno is not supported.

This removes s_lib_ver.c as _LIB_VERSION is no longer variable.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-05 22:23:02 +02:00
Keith Packard via Newlib 45efe659b8 libm: Set math_errhandling to match library and hardware [v2]
math_errhandling is specified to contain two bits of information:

 1. MATH_ERRNO     -- Set when the library sets errno
 2. MATH_ERREXCEPT -- Set when math operations report exceptions

MATH_ERRNO should match whether the original math code is compiled in
_IEEE_LIBM mode and the new math code has WANT_ERRNO == 1.

MATH_ERREXCEPT should match whether the underlying hardware has
exception support. This patch adds configurations of this value for
RISC-V, ARM, Aarch64, x86 and x86_64 when using HW float.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-04 19:30:45 +02:00
Corinna Vinschen 5717262b8e select.h: update FD macros to latest FreeBSD, fix type conversion warning
Compiling

#include <sys/select.h>
void f(int X)
{
  fd_set set;
  FD_ZERO(&set);
  FD_SET(X,&set);
  FD_CLR(X+1,&set);
  (void)FD_ISSET(X+2,&set);
}

results in plenty of gcc warnings when compiled with
-Wconversion -Wsign-conversion:

  fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may
    FD_SET(X,&set);
    ^~~~~~
  [...]

The unsigned NFDBITS macro combined with the signed 1L constant
are causing lots of implicit signed/unsigned type conversions.

Fix this by updating the FD_* macro code to the latest from FreeBSD
and adding an (int) cast to _NFDBITS.

As a side-effect, this fixes the visibility of NFDBITS and
fds_bits (only if __BSD_VISIBLE).

This also eliminates the old, outdated fd_set workaround.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-03 12:41:45 +02:00
Corinna Vinschen 3fbfcd11fb Cygwin: posix_spawn: add Cygwin-specific code fixing process synchronisation
Newlib's posix_spawn has been taken from FreeBSD.  The code relies on
BSD-specific behaviour of vfork, namely the fact that vfork blocks
the parent until the child exits or calls execve as well as the fact
that the child shares parent memory in non-COW mode.

This behaviour can't be emulated by Cygwin.  Cygwin's vfork is
equivalent to fork.  This is POSIX-compliant, but it's lacking BSD's
vfork ingrained synchronization of the parent to wait for the child
calling execve, or the chance to just write a variable and the parent
will see the result.

So this requires a Cygwin-specific solution.  The core function of
posix_spawn, called do_posix_spawn is now implemented twice, once using
the BSD method, and once for Cygwin using Windows synchronization under
the hood waiting for the child to call execve and signalling errors
upstream.  The Windows specifics are hidden inside Cygwin, so newlib
only calls internal Cygwin functions.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-03 12:41:44 +02:00
Eshan dhawan b7a6e02dc6 arm: Fix fenv support
The previous fenv support for ARM used the soft-float implementation of
FreeBSD.  Newlib uses the one from libgcc by default.  They are not
compatible.  Having an GCC incompatible soft-float fenv support in
Newlib makes no sense.  A long-term solution could be to provide a
libgcc compatible soft-float support.  This likely requires changes in
the GCC configuration.  For now, provide a stub implementation for
soft-float multilibs similar to RISC-V.

Move implementation to one file and delete now unused files.  Hide
implementation details.  Remove function parameter names from header
file to avoid name conflicts.

Provide VFP support if __SOFTFP__ is not defined like glibc.

Reviewed-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-29 06:58:17 +02:00
PkmX via Newlib 123b806523 riscv: fix integer wraparound in memcpy
This patch fixes a bug in RISC-V's memcpy implementation where an
integer wraparound occurs when src + size < 8 * sizeof(long), causing
the word-sized copy loop to be incorrectly entered.

Signed-off-by: Chih-Mao Chen <cmchen@andestech.com>
2020-07-27 10:14:34 +02:00
Aschref Ben Thabet 0ee972d1b0 ctype.h: Fix unused variable warnings
If __HAVE_LOCALE_INFO__ is not defined, then the locale in the
locale-specific ctype functions is ignored.  In the previous
implementation this resulted in compiler warnings.  For example:

int main()
{
  locale_t locale;
  locale = duplocale(uselocale((locale_t)0));
  isspace_l('x', locale);
  return 0;
}

gcc -Wall main.c
main.c: In function 'main':
main.c:6:11: warning: variable 'locale' set but not used [-Wunused-but-set-variable]
    6 |  locale_t locale;
      |           ^~~~~~
2020-07-16 11:27:38 +02:00
Keith Packard via Newlib 24f3c61953 libc/iconv: find_alias was mis-computing remaining alias table length
This caused the strnstr to walk off the end of the alias array and
fetch invalid data. Instead of attempting to update 'len', just
re-compute it based on the table end pointer that is already known.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-07-10 10:51:43 +02:00
Keith Packard via Newlib 2c33d31fa8 libc/iconv: Remove unneeded pointer var for _iconv_aliases
The pointer value for the iconv alias data never changes, so get rid
of the pointer and make it an array instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-07-10 10:51:43 +02:00
Keith Packard via Newlib 6c772f4547 libc/iconv: Detect CES handler loading failure
Fix the code checking for character set loading failure so that
it checks the return value from the init function.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-07-10 10:51:43 +02:00
Eshan dhawan via Newlib 104caeb7b1 Removed #ifndef _ARM_PCS_VFP_ from sys/fenv.h for arm
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-06 13:18:28 +02:00
Eshan dhawan via Newlib 65918715a0 mips fenv support
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-03 10:41:45 +02:00
Eshan dhawan via Newlib 03bf9f431c SPARC fenv support
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-03 10:41:45 +02:00
Eshan dhawan via Newlib fd5e27d362 fenv aarch64 support
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-07-02 12:12:39 +02:00
Eshan dhawan via Newlib a97bdf100f fenv support arm
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-06-09 21:13:17 -04:00
Eshan dhawan via Newlib e6ce6f1430 hard float support for PowerPC taken from FreeBSD
Signed-off-by: Eshan dhawan <eshandhawan51@gmail.com>
2020-06-03 11:17:47 +02:00
Szabolcs Nagy 0f785536f3 Reimplement aligned_alloc
The original implementation had multiple issues:

- Only worked when posix_memalign was available (Linux, RTEMS).
- Violated C11 link namespace rules by calling posix_memalign.
- Failed to set errno on error.

These can be fixed by essentially using the same implementation
for aligned_alloc as for memalign, i.e. simply calling _memalign_r
(which is always available and a "more reserved name" although
technically still not in the reserved link namespace, at least
code written in c cannot define a colliding symbol, newlib has
plenty such namespace issues so this is fine).

It is not clear what the right policy is when MALLOC_PROVIDED is set,
currently that does not cover aligned_alloc so it is kept that way.

Tested on aarch64-none-elf
2020-05-19 15:19:33 +02:00
Sebastian Huber b37a3388cc RTEMS: Include missing header and fix stub
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2020-03-13 13:51:20 -05:00
Richard Earnshaw f973a7d8be arm: Finish moving newlib to unified syntax for Thumb1
Most code in newlib already uses unified syntax, but just a couple of
laggards remain.  This patch removes these and means the the entire
code base has now been converted.
2020-03-02 13:33:11 +00:00
Joel Sherrill 7dac41db18 newlib/libc/include/devctl.h: Add extern "C" wrapper
Adding this was necessary to allow posix_devctl() from C++.
2020-02-20 09:45:39 +01:00
Thomas Wolff c8204b1069 Locale modifier "@cjksingle" to enforce single-width CJK width.
This option follows a proposal in the Terminals Working Group Specifications
(https://gitlab.freedesktop.org/terminal-wg/specifications/issues/9#note_406682).
It makes locale width consistent with the corresponding mintty feature.
2020-02-18 11:35:42 +01:00
Keith Packard ff24ce9193 Typo in license for newlib/libc/stdio/flags.c
Fix spelling:

	MERCHANT I BILITY -> MERCHANT A BILITY

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-02-06 11:58:50 +01:00
Keith Packard 9042d0ce65 Use remove-advertising-clause script to edit BSD licenses
This edits licenses held by Berkeley and NetBSD, both of which
have removed the advertising requirement from their licenses.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-29 19:03:31 +01:00
Corinna Vinschen 2607f00423 Revert "newlib: fix fseek optimization with SEEK_CUR"
This reverts commit 59362c80e3.

This breaks gnulib's autoconf test for POSIX compatibility of
fflush/fseek.  After fflush/fseek, ftello and lseek are out of
sync, with lseek having the wrong offset.  This breaks backward
compatibility with Cygwin applications.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-01-29 18:53:44 +01:00
Jeff Johnston 4e78f8ea16 Bump up newlib release to 3.3.0 2020-01-21 15:17:43 -05:00
Keith Packard 5377a84776 riscv: Map between ieeefp.h exception bits and RISC-V FCSR bits
If we had architecture-specific exception bits, we could just set them
to match the processor, but instead ieeefp.h is shared by all targets
so we need to map between the public values and the register contents.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-21 10:28:35 +01:00
Keith Packard 8e74c7119f riscv: Add 'break' statements to fpsetround switch
This makes the fpsetround function actually do something rather than
just return -1 due to the default 'fall-through' behavior of the switch
statement.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-21 10:28:35 +01:00
Keith Packard 954504ea14 riscv: Use current pseudo-instructions to access the FCSR register
Use fscsr and frcsr to store and read the FCSR register instead of
fssr and frsr.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-21 10:28:35 +01:00
Jeff Johnston 1fdf871c9d Prevent more NULL ptr accesses due to Balloc out of memory
- fix gdtoa-gethex.c, ldtoa.c, and strtodg.c to use eBalloc
2020-01-09 15:18:14 -05:00
Giacomo Tesio d9c194a0b0 jehanne: call init_array and fini_array members 2020-01-07 22:24:56 +01:00
Giacomo Tesio 7e31b66efa jehanne: fix ioctl call to sys_create 2020-01-07 22:23:55 +01:00
Jeff Johnston 1afb22a120 Bump up release to 3.2.0 for yearly snapshot 2020-01-02 14:56:24 -05:00
Giacomo Tesio 99170a5919 jehanne: fix call to jehanne_tm2sec 2019-12-27 00:21:51 +01:00
Giacomo Tesio 7064f720bd jehanne: avoid standard C functions in libposix_conf.c 2019-12-27 16:06:55 +01:00
Giacomo Tesio 808d02b453 jehanne: protect sys/dirent.h functions 2019-12-27 16:03:04 +01:00
Anthony Green b481c11e5a Optimize setjmp/longjmp for moxie.
We don't need to save/restore every register -- just those
we don't expect to be trashed by function calls.
2019-12-20 09:00:26 -05:00
Keith Packard 76dcfd0c4d Don't display trailing '.' in _dcvt
In the two helper functions that _dcvt calls for 'f' and 'e' mode, if
there are no digits to display after the decimal point, don't add one.

Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-18 20:53:36 +01:00
Keith Packard 11f99384d2 Fix gcvt to always show 'ndigits' of precision
Leading zeros after the decimal point should not count
towards the 'ndigits' limit.

This makes gcvt match glibc and the posix gcvt man page.

Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-18 20:53:36 +01:00
Keith Packard abcc586ffe Fix fcvt to only show 'ndigit' past decimal
Even if the number is really small and this means showing *no* digits.
This makes newlib match glibc, and the fcvt posix man page.

Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-18 20:53:36 +01:00
Keith Packard ed2a469cdd Set __IEEE_LITTLE_ENDIAN for _XTENSA_EL__ (ESP32)
Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-17 10:09:36 +01:00
Keith Packard 2635b580ec Return EINVAL for illegal base in strtol
Signed-off-by: Keith Packard <keithp@keithp.com>
2019-12-17 10:07:44 +01:00
Giacomo Tesio 1642ff8510 jehanne: wrap sys/ioctl.h with `extern "C" { }` (to ease GCC cross compilation) 2019-12-17 00:24:15 +01:00
Bruno Haible c81a76b3b9 strtold: set errno to ERANGE on underflow per POSIX
https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtod.html
2019-12-16 15:18:52 +01:00
Anthony Green 31227ba53d Fix setjmp/longjmp for the moxie port.
These functions needs to save and restore the stack frame, because
that's where the return address is stored.
2019-12-13 13:08:06 -05:00