Commit Graph

3305 Commits

Author SHA1 Message Date
Joel Sherrill 90a72f27d5 newlib/doc/makedoc.c: if realloc() fails, exit with an error message. 2021-06-17 16:48:47 -05:00
Joel Sherrill 609f5a51c6 newlib/doc/makedoc.c: Fix memory leak identified by Coverity. 2021-06-17 16:27:49 -05:00
Joel Sherrill 59584ff16b libc/sys/rtems/crt0.c: Fix two warnings.
__assert_func() is marked as noreturn and stub should not.
	__tls_get_addr() needed to return a value..
2021-06-17 12:58:36 -05:00
Dimitar Dimitrov b585151016 pru: Enable -ffunction-sections and -fdata-sections
Recent binutils support --gc-sections for pru, so let's make use of
them.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2021-06-09 14:07:14 -04:00
Jeff Johnston a9165ea07c Fix rounding issues with sqrt/sqrtf
- compiler is sometimes optimizing out the rounding check in
  e_sqrt.c and ef_sqrt.c which uses two constants to create
  an inexact operation
- there is a similar constant operation in s_tanh.c/sf_tanh.c
- make the one and tiny constants volatile to stop this
2021-06-04 14:42:58 -04:00
Richard Earnshaw 2a3a03972b aarch64: support binary mode for opening files
Newlib for aarch64 uses libgloss for the backend.  One common libgloss
implementation is the 'rdimon' implementation, which uses the Arm
Semihosting protocol.  In order to support a remote host that runs on
Windows we need to know whether a file is to be opened in binary or
text mode.  That means that we need to preserve this information via
O_BINARY until we know what the libgloss binding will be.

This patch simply copies the arm implementation from sys/arm/sys and
puts it in machine/aarch64/sys, because we don't have a 'sys' subtree
on aarch64.
2021-05-26 15:17:11 +01:00
Joel Sherrill 0c0f3df224 sys/stat.h: Enable UTIME_NOW and UTIME_OMIT for RTEMS 2021-05-20 10:04:07 +02:00
Ola Olsson 84d068971d Nano-malloc: Fix for unwanted external heap fragmentation
The only reason why it is tough for us to use nano malloc
is because of the small shortcoming where nano_malloc()
splits a bigger chunk from the free list into two pieces
while handing back the second one (the tail) to the user.
This is error prone and especially bad for smaller heaps,
where nano malloc is supposed to be superior. The normal
malloc doesn't have this issue and we need to use it even
though it costs us ~2k bytes compared to nano-malloc.

The problem arise especially after giving back _every_
malloced memory to the heap and then starting to exercise
the heap again by allocating something small. This small
item might split the whole heap in two equally big parts
depending on how the heap has been exercised before.

I have uploaded the smallest possible application
(only tested on ST and Nordic devices) to show the issue
while the real customer applications are far more complicated:
https://drive.google.com/file/d/1kfSC2KOm3Os3mI7EBd-U0j63qVs8xMbt/view?usp=sharing

The application works like the following pseudo code,
where we assume a heap of 100 bytes
(I haven't taken padding and other nitty and gritty
details into account. Everything to simplify understanding):

void *ptr = malloc(52); // We get 52 bytes and we have
                        // 48 bytes to use.
free(ptr); // Hand back the 52 bytes to nano_malloc
           // This is the magic line that shows the issue of
           // nano_malloc
ptr = malloc(1); // Nano malloc will split the 52 bytes
                 // in the free list and hand you a pointer
                 // somewhere in the
                 // middle of the heap.
ptr2 = malloc(52); // Out of memory...

I have done a fix which hands back the first part of the
splitted chunk. Once this is fixed we obviously
have the 1 byte placed in position 0 of the heap instead
of somewhere in the middle.

However, this won't let us malloc 52 new bytes even though
we potentially have 99 bytes left to use in the heap. The
reason is that when we try to do the allocation,
nano-malloc looks into the free list and sees a 51 byte
chunk to be used.
This is not big enough so nano-malloc decides to call
sbrk for _another_ 52 bytes which is not possible since
there is only 48 bytes left to ask for.

The solution for this problem is to check if the last
item in the free list is adjacent to sbrk(0). If it is,
as it is in this case, we can just ask sbrk for the
remainder of what is needed. In this case 1 byte.

NB! I have only tested the solution on our ST device.
2021-05-03 13:00:33 +02:00
Mike Frysinger ae6e6c3526 bfin: add myself as maintainer 2021-04-26 11:38:35 +02:00
Ties Stuij 282445a10e fix some Arm FP routines not checking if floating point is enabled
A lot of the Arm FP routines check for the availability of floating point by way
of `(__ARM_FP & 0x4)`. However some do not. This patch remedies this.
2021-04-21 16:18:09 +01:00
Corinna Vinschen 9c6c2fb0f6 scanf: allow hex float input per POSIX
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-19 22:00:10 +02:00
David Macek 7078248485 fenv: fix up stub file comment, drop symlinks from description
also slightly fixed up formatting
2021-04-13 12:55:34 +02:00
Corinna Vinschen cc19109af9 Cygwin: don't export _feinitialise from newlib
Use the more official fesetenv(FE_DFL_ENV) from _dll_crt0, thus
allowing to drop the _feinitialise declaration from fenv.h.

Provide a no-op _feinitialise in Cygwin as exportable symbol for really
old applications when _feinitialise was called from mainCRTStartup in
crt0.o.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:34 +02:00
Corinna Vinschen 3b22d72255 fenv: drop Cygwin-specific implementation in favor of newlib code
Drop the Cygwin-specific fenv.cc and fenv.h file and use the equivalent
newlib functionality now, so we have at least one example of a user for
this new mechanism.

fenv.c: allow _feinitialise to be called from Cygwin startup code

fenv.h: add declarations for fegetprec and fesetprec for Cygwin only.
        Fix a comment.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:34 +02:00
Corinna Vinschen 642be00cdb fenv: move shared x86 fenv.c to libm/machine/shared_x86
Include this file from both sharing architectures, i386 and x86_64.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:33 +02:00
Corinna Vinschen 05753071c0 fenv: Move shared x86 sys/fenv.h from x86_64 to shared_x86
drop matching symlink in i386

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:33 +02:00
Corinna Vinschen 79ac4237dc fenv: add missing declarations to x86 fenv.h
feenableexcept, fedisableexcept and fegetexcept were
accidentally missing in the x86 fenv.h

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:33 +02:00
Corinna Vinschen c326ca1615 configure.host: define shared ix86 and x86_64 directory
Add a directory libc/machine/shared_x86 to share header files
between ix86 and x86_64 architectures.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:33 +02:00
Corinna Vinschen 80bd01ef83 Add build mechanism to share common header files between machines
So far the build mechanism in newlib only allowed to either define
machine-specific headers, or headers shared between all machines.
In some cases, architectures are sufficiently alike to share header
files between them, but not with other architectures.  A good example
is ix86 vs. x86_64, which share certain traits with each other, but
not with other architectures.

Introduce a new configure variable called "shared_machine_dir".  This
dir can then be used for headers shared between architectures.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:33 +02:00
Jeff Johnston 1debd4d635 Regenerate lib/posix/Makefile.in 2021-03-05 15:23:24 -05:00
Marcus Comstedt 26478769a6 RISC-V: Fix optimized strcmp on big endian 2021-02-25 12:14:18 +01:00
Marcus Comstedt 1a6fd3f05f Set __IEEE_BIG_ENDIAN for big endian RISC-V 2021-02-25 12:14:18 +01:00
Hans-Peter Nilsson c1a565c396 Include malloc.h in libc/stdlib/aligned_alloc.c
Without this, for a bare-iron/simulator target such as cris-elf,
you'll see, at newlib build time:

/x/gccobj/./gcc/xgcc -B/x/gccobj/./gcc/ <many options elided> -c -o lib_a-aligned_alloc.o \
 `test -f 'aligned_alloc.c' || echo '/y/newlib/libc/stdlib/'`aligned_alloc.c
/y/newlib/libc/stdlib/aligned_alloc.c: In function 'aligned_alloc':
/y/newlib/libc/stdlib/aligned_alloc.c:35:10: warning: implicit declaration of function \
 '_memalign_r' [-Wimplicit-function-declaration]
   35 |   return _memalign_r (_REENT, align, size);
      |          ^~~~~~~~~~~
2021-02-18 02:05:47 +01:00
Hans-Peter Nilsson 571e730678 Complete revert of 2019-08-19, st_atime in libc/include/sys/stat.h
The revert-part of the revert-and-fix commit, b99887c428 a.k.a.
"Revert previous change to sys/stat.h and fix cris libgloss",
apparently intending to revert f75aa67851 a.k.a. "Fix regression in
cris-elf caused by sys/stat.h change" and fix it in another way,
wasn't complete.  Although the fix-part added the prerequisite "#undef
st_atime" (et al) to gensyscalls, the revert-part didn't revert the
"&& !defined(__cris__)" in sys/stat.h, stopping st_atime (et al) from
being defined.

The effect of the unreverted change is that accessing the struct stat
compatibility member names "st_atime" (et al) as in "struct stat
mystat; mystat.st_atime;" yields errors, observable for example when
building libgfortran in gcc:

/x/gcc/libgfortran/intrinsics/stat.c:114:42: error: 'struct stat' has \
no member named 'st_atime'; did you mean 'st_atim'?
  114 |       sarray->base_addr[8 * stride] = sb.st_atime;
      |                                          ^~~~~~~~
      |                                          st_atim
(etc.)

Trivially fixed by completing the reversion, removing the "&&
!defined(__cris__)" in sys/stat.h.

Beware: the net effect of the earlier related change to struct stat in
sys/stat.h, leading up to the fix, *does* change its definition as a
type.  Thankfully, replacing members like "time_t st_atime; long
st_spare1;" by "struct timespec st_atim;", ditto st_mtim and st_ctim,
is layout-compatible.  To wit, that change is "binary compatible".

Incidentally, related to the simulator / Linux ABI, there's a
transitional stage (see gensyscalls), reloading between "struct stat"
(sys/stat.h) and "struct new_stat" (kernel/simulator) as necessary.

Tested by a cris-elf gcc build (including libgfortran).
2021-02-16 13:57:11 +01:00
Eshan dhawan d8ee634506 FTW Port for Newlib
Signed-off-by: Eshan Dhawan <eshandhawan51@gmail.com>
2021-02-09 11:07:59 +01:00
Eshan dhawan 55a6e49a08 Removed Soft float from MIPS
This Patch removes Soft Float code from MIPS.
Instead It adds the soft float code from RISCV

The code came from FreeBSD and assumes the FreeBSD softfp
implementation not the one with GCC. That was an overlooked and
fixed in the other fenv code already.

Signed-off-by: Eshan Dhawan <eshandhawan51@gmail.com>
2021-02-05 10:32:16 +01:00
Sebastian Huber 3388a5a429 Align *utime*() with POSIX/glibc
Change the prototypes to be in line with POSIX/glibc.  This may fix
issues with new warnings produced by GCC 11.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2021-01-26 17:27:35 +01:00
Sebastian Huber a485393aea RTEMS: Add <poll.h> and <sys/poll.h>
Add the POSIX header file <poll.h> which is used by the GCC 11 Ada
runtime support.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2021-01-05 13:41:34 -05:00
Jeff Johnston 415fdd4279 Bump up newlib version to 4.1.0 2020-12-18 18:50:49 -05:00
Paul Zimmermann 4bb6581aa8 fixes to make compilation succeeds 2020-12-18 10:06:31 +01:00
Jeff Johnston b2f3d593ff Update gamma functions from code in picolibc
- fixes issue with inf sign when x is -0
2020-12-17 16:23:43 -05:00
Jeff Johnston d634f26653 Add declarations for __ieee754_tgamma functions to fdlibm.h 2020-12-16 15:28:09 -05:00
Sebastian Huber 6cc47c4c33 arm: Fix memchr() for Armv8-R
The Cortex-R52 processor is an Armv8-R processor with a NEON unit.  This
fix prevents conflicting architecture profiles A/R errors issued by the
linker.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2020-12-14 16:10:30 -05:00
Fabian Schriever cf1ef2dc5b Fix error in powf for x close to 1 and large y
This patch fixes the error found by Paul Zimmermann (see
https://homepages.loria.fr/PZimmermann/papers/#accuracy) regarding x
close to 1 and rather large y (specifically he found the case
powf(0x1.ffffeep-1,-0x1.000002p+27) which returns +Inf instead of the
correct value). We found 2 more values for x which show the same faulty
behaviour, and all 3 are fixed with this patch. We have tested all
combinations for x in [+1.fffdfp-1, +1.00020p+0] and y in
[-1.000007p+27, -1.000002p+27] and [1.000002p+27,1.000007p+27].
2020-12-11 14:38:19 -05:00
Jeff Johnston 14123c991b Bump newlib release to 4.0.0 2020-12-11 14:37:12 -05:00
Kito Cheng 57635f8581 RISC-V: Add machine-specific implementation for lrint[f], lround[f], llrint[f] and llround[f]. 2020-11-18 09:35:28 +01:00
Kito Cheng 5cf5a2e4c0 RISC-V: Add machine-specific implementation for isnan[f] and copysign[f] 2020-11-18 09:35:28 +01:00
Kito Cheng a7f82939d8 RISC-V: Add missing compile rule for s_finite.c, sf_finite.c, s_isinf.c and sf_isinf.c 2020-11-18 09:35:28 +01:00
Corinna Vinschen aa106b29a6 malloc/nano-malloc: correctly check for out-of-bounds allocation reqs
The overflow check in mEMALIGn erroneously checks for INT_MAX,
albeit the input parameter is size_t.  Fix this to check for
__SIZE_MAX__ instead.  Also, it misses to check the req against
adding the alignment before calling mALLOc.

While at it, add out-of-bounds checks to pvALLOc, nano_memalign,
nano_valloc, and Cygwin's (unused) dlpvalloc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-11-17 10:52:34 +01:00
Sebastian Huber 14a1e7ce42 Fix return type of __locale_ctype_ptr_l()
This prevents warnings like this:

ctype.h:118:9: warning: return discards 'const' qualifier from pointer
  target type
2020-11-16 19:34:30 +01:00
Joel Sherrill 302b82afee libc/include/newlib.h: Fix C++ compilation issue 2020-11-16 08:15:18 -06:00
Ivan Grokhotov b7a357e92e Fix 32-bit integer overflow when calculating TZ rules 2020-11-04 13:33:36 -05:00
Kito Cheng ff2c8fcfc7 RISC-V: Fix wrong including file in s_isinf.c 2020-10-29 09:39:35 +01:00
Kito Cheng 0020d2dd7c RISC-V: NaN should return 0 for finite[f] 2020-10-29 09:39:35 +01:00
Joel Sherrill fcaaf40c9d libc/sys/rtems/include/machine/_types.h: Define daddr_t to be 64 bits for RTEMS
This type needs to be able to represent a position on a disk or
file system.
2020-10-28 09:45:21 -05:00
Kito Cheng b847c83294 RISC-V: Implment finite and fpclassify 2020-10-27 08:56:30 +01:00
Kito Cheng b5f03509d1 RISC-V: Add fabs[f], fmax[f] and fmin[f]. 2020-10-27 08:56:30 +01:00
dougm 17b7dfc0b5 Define RB_SET_PARENT to do all assignments
to rb parent pointers. Define RB_SWAP_CHILD to replace the child of a parent
with its twin, and use it in 4 places. Use RB_SET in rb_link_node to remove the
only linuxkpi reference to color, and then drop color- and parent-related
definitions that are defined and used only in rbtree.h.

This is intended to be entirely cosmetic, with no impact on program
behavior, and leave RB_PARENT and RB_SET_PARENT as the only ways to
read and write rb parent pointers.

Reviewed by:	markj, kib
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25264
2020-10-26 14:18:46 +01:00
dougm d03eaf36dc In concluding RB_REMOVE_COLOR, in the case when
the sibling of the root of the too-short tree is black and at least one of the
children of that sibling is red, either one or two rotations finish the
rebalancing. In the case when both of the children are red, the current
implementation uses two rotations where only one is necessary. This change
removes that extra rotation, and in that case also removes a needless
black-to-red-to-black recoloring.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25335
2020-10-26 14:18:46 +01:00
dougm 977a827d29 Linuxkpi uses the rb-tree structures
without using their interfaces, making them break when the representation
changes. Revert changes that eliminated the color field from rb-trees, leaving
everything as it was before.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25250
2020-10-26 14:18:46 +01:00
dougm 87b42171dc Fixup r361997 by balancing parens. Duh. 2020-10-26 14:18:46 +01:00
dougm e83aad1851 Restore an RB_COLOR macro, for the benefit of
a bit of DIAGNOSTIC code that depends on it.

Reported by:	rpokala, mjguzik
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25204
2020-10-26 14:18:46 +01:00
dougm 5b29be92e3 To reduce the size of an rb_node, drop the color
field. Set the least significant bit in the pointer to the node from its parent
to indicate that the node is red. Have the tree rotation macros leave the
old-parent/new-child node red and the new-parent/old-child node black.

This change makes RB_LEFT and RB_RIGHT no longer assignable, and
RB_COLOR no longer defined. Any code that modifies the tree or
examines a node color would have to be modified after this change.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25105
2020-10-26 14:18:46 +01:00
dougm 123df813ee Remove from RB_REMOVE_COLOR some null checks
where the pointer checked is provably never null. Restructure the surrounding
code just enough to make the non-nullness obvious.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25089
2020-10-26 14:18:46 +01:00
dougm 640a96a231 RB_REMOVE invokes RB_REMOVE_COLOR either when
child is red or child is null. In the first case, RB_REMOVE_COLOR just changes
the child to black and returns. With this change, RB_REMOVE handles that case,
and drops the child argument to RB_REMOVE_COLOR, since that value is always
null.

RB_REMOVE_COLOR is changed to remove a couple of unneeded tests, and
to eliminate some deep indentation.

RB_ISRED is defined to combine a null check with a test for redness,
to replace that combination in several places.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25032
2020-10-26 14:18:46 +01:00
dougm 9db2b54571 For the case when RB_REMOVE requires a nontrivial
search to find the node to replace the one being removed, restructure to first
remove the replacement node and correct the parent pointers around it, and then
let the all-cases code at the end deal with the parent of the deleted node,
making it point to the replacement node. This removes one or two conditional
branches.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D24845
2020-10-26 14:18:46 +01:00
dougm 1256d090ad Correct the use of RB_AUGMENT in the RB_TREE
macros so that is invoked at the root of every subtree that changes in an
insert or delete, and only once, and ordered from the bottom of the tree to the
top. For intel_gas.c, the only user of RB_AUGMENT I can find, change the
augmenting routine so that it does not climb from entry to tree root on every
call, and remove a 'tree correcting' function that can be supplanted by proper
tree augmentation.

Reviewed by:	kib
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D23189
2020-10-26 14:18:46 +01:00
trasz fd4cbaba7a Add RB_REINSERT(3), a low overhead alternative to
removing a node and reinserting it back with an updated key.

This is one of dependencies for the upcoming stats(3) code.

Reviewed by:	cem
Obtained from:	Netflix
MFC after:	2 weeks
Sponsored by:	Klara Inc, Netflix
Differential Revision:	https://reviews.freebsd.org/D21786
2020-10-26 14:18:46 +01:00
jah 303c61925d amd64: prevent KCSan false positives on LAPIC mapping
For configurations without x2APIC support (guests, older hardware), the global
LAPIC MMIO mapping will trigger false-positive KCSan reports as it will appear
that multiple CPUs are concurrently reading and writing the same address.
This isn't actually true, as the underlying physical access will be performed
on the local CPU's APIC. Additionally, because LAPIC access can happen during
event timer configuration, the resulting KCSan printf can produce a panic due
to attempted recursion on event timer resources.

Add a __nosanitizethread preprocessor define to prevent the compiler from
inserting TSan hooks, and apply it to the x86 LAPIC accessors.

PR:		249149
Reported by:	gbe
Reviewed by:	andrew, kib
Tested by:	gbe
Differential Revision:	https://reviews.freebsd.org/D26354
2020-10-26 14:18:46 +01:00
mjg 47efca5ac3 sys: clean up empty lines in .c and .h files 2020-10-26 14:18:46 +01:00
rlibby b9af5041bd gcc: quiet Wattribute for no_sanitize("address")
This is an unfortunate instance where the __has_attribute check does
not function usefully.  Gcc does have the attribute, but for gcc it only
applies to functions, not variables, and trying to apply it to a
variable generates Wattribute.  So far we only apply the attribute to
variables.  Only enable the attribute for clang, for now.

Reviewed by:	Anton Rang <rang at acm.org>
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22875
2020-10-26 14:18:46 +01:00
dab b9967c3f90 Don't sanitize linker_set
The assumptions of linker_set don't play nicely with
AddressSanitizer. AddressSanitizer adds a 'redzone' of zeros around
globals (including those in named sections), whereas linker_set
assumes they are all packed consecutively like a pointer array. So:
let's annotate linker_set so that AddressSanitizer ignores it.

Submitted by:	Matthew Bryan <matthew.bryan@isilon.com>
Reviewed by:	kib, rang_acm.org
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22239
2020-10-26 14:18:46 +01:00
jhb c25de3a3c5 Make the system C11 atomics headers fully compatible with external GCC.
The <sys/cdefs.h> and <stdatomic.h> headers already included support for
C11 atomics via intrinsincs in modern versions of GCC, but these versions
tried to "hide" atomic variables inside a wrapper structure.  This wrapper
is not compatible with GCC's internal <stdatomic.h> header, so that if
GCC's <stdatomic.h> was used together with <sys/cdefs.h>, use of C11
atomics would fail to compile.  Fix this by not hiding atomic variables
in a structure for modern versions of GCC.  The headers already avoid
using a wrapper structure on clang.

Note that this wrapper was only used if C11 was not enabled (e.g.
via -std=c99), so this also fixes compile failures if a modern version
of GCC was used with -std=c11 but with FreeBSD's <stdatomic.h> instead
of GCC's <stdatomic.h> and this change fixes that case as well.

Reported by:	Mark Millard
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D16585
2020-10-26 14:18:45 +01:00
Torbjörn SVENSSON via Newlib 7ed952000c libc/time: Move internal newlib tz-structs into own header
As discussed in GCC bug 97088
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in
prototypes of library functions should use reserved names, or no name
at all.

This patch moves the internal struct __tzrule_struct to its own
internal header sys/_tz_structs.h.  This is included from newlib's
time code as well as from Cygwin's localtime wrapper.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-15 16:59:51 +02:00
Thomas Wolff 1ed2fe0f03 drop ambiguous-wide behaviour from Unicode CJK locales 2020-10-13 13:52:07 +02:00
Torbjörn SVENSSON ea275093c1 libc/include/wchar.h: Remove parameter name
As discussed in GCC bug 97088
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in
prototypes of library functions should use reserved names, or no name
at all.

This patch removes the 'ptr' parameter name from
wint_t _getwchar_r (struct _reent *);
wint_t _getwchar_unlocked_r (struct _reent *);

to avoid possible clashes with user code in case someone uses
before including Newlib's wchar.h (or uses some other conflicting
definition)

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
2020-10-02 17:02:28 -04:00
Torbjörn SVENSSON 615cf4bdce libc/include/inttypes.h: Remove parameter name
As discussed in GCC bug 97088
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in
prototypes of library functions should use reserved names, or no name
at all.

This patch removes the 'j' parameter name from
extern intmax_t  imaxabs(intmax_t);

to avoid possible clashes with user code in case someone uses
before including Newlib's inttypes.h (or uses some other conflicting
definition)

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
2020-10-02 17:00:43 -04:00
Christophe Lyon 4c49accf89 libc/include/math.h: Remove parameter name
As discussed in GCC bug 97088
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in
prototypes of library functions should use reserved names, or no name
at all.

This patch removes the 'x' parameter name from
extern int __isinff (float);
extern int __isinfd (double);
extern int __isnanf (float);
extern int __isnand (double);
extern int __fpclassifyf (float);
extern int __fpclassifyd (double);
extern int __signbitf (float);
extern int __signbitd (double);

to avoid possible clashes with user code in case someone uses
before including Newlib's math.h (or uses some other conflicting
definition)
2020-09-25 22:53:43 -04:00
Jojo R 8315a90822 Port of C-SKY for newlib
Contributor list:  

  - Lifang Xia <lifang_xia@c-sky.com>  
  - Jojo R <jiejie_rong@c-sky.com>
  - Xianmiao Qu <xianmiao_qu@c-sky.com>
  - Yunhai Shang <yunhai_shang@c-sky.com>
2020-09-23 15:08:59 -04:00
Keith Packard 4641693796 libm: Make tgamma(-small) = -INFINITY
Need to copy the argument sign to the output for tgamma(finite)
overflow case.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-09-18 17:20:27 -04:00
Keith Packard via Newlib 1f8e5847df libm: Fix 'gamma' and 'gammaf' functions. Clean up other gamma code. [v2]
The current gamma, gamma_r, gammaf and gammaf_r functions return
|gamma(x)| instead of ln(|gamma(x)|) due to a change made back in 2002
to the __ieee754_gamma_r implementation. This patch fixes that, making
all of these functions map too their lgamma equivalents.

To fix the underlying bug, the __ieee754_gamma functions have been
changed to return gamma(x), removing the _r variants as those are no
longer necessary. Their names have been changed to __ieee754_tgamma to
avoid potential confusion from users.

Now that the __ieee754_tgamma functions return the correctly signed
value, the tgamma functions have been modified to use them.

libm.a now exposes the following gamma functions:

    ln(|gamma(x)|):

	__ieee754_lgamma_r
	__ieee754_lgammaf_r

	lgamma
	lgamma_r
	gamma
	gamma_r

	lgammaf
	lgammaf_r
	gammaf
	gammaf_r

	lgammal	(on machines where long double is double)

    gamma(x):

	__ieee754_tgamma
	__ieee754_tgammaf
	tgamma
	tgammaf
	tgammal (on machines where long double is double)

Additional aliases for any of the above functions can be added if
necessary; in particular, I'm not sure if we need to include
__ieee754_gamma*_r functions (which would return ln(|(gamma(x)|).

Signed-off-by: Keith Packard <keithp@keithp.com>

----

v2:
	Switch commit message to ASCII
2020-09-04 21:27:11 +02:00
Keith Packard via Newlib a0d7982ff4 libm/riscv: Use common fma code when necessary
For RISC-V targets without hardware FMA support, include the
common fma implementation to provide that API.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-09-04 15:11:31 +02:00
Keith Packard via Newlib 373f628d04 libm/riscv: Fix machine-specific sqrt build process
Like ARM, some RISC-V implementations have hardware sqrt. Support for
that can be detected at compile time, which the code did. However, the
filenames were incorrect so that both the risc-v specific and general
code were getting included in the resulting library.

Fix this by following the ARM model and #include'ing the general code
when the architecture-specific support is not available.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-09-04 15:11:31 +02:00
Corinna Vinschen 12a94daf5f loadlocale: don't casecmp digits
strcmp is sufficient here

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-09-04 14:21:10 +02:00
Jozef Lawrynowicz 754386c7f5 Fix warnings when building for msp430-elf
The MSP430 target supports both 16-bit and 20-bit size_t and intptr_t.
Some implicit casts in Newlib expect these types to be
"long", (a 32-bit type on MSP430) which causes warnings during
compilation such as:
  "cast from pointer to integer of different size"
2020-09-03 12:55:32 +02:00
Keith Packard via Newlib a634adda5a libm/machine/arm: Rename s*_fma.c -> s*_fma_arm.c
This is required to avoid colliding with files built from libm/common
that would end up with the same object name.

When libm.a was constructed from the individual sub-libraries, the
contents of the libm/common files would be replaced by that from
libm/machine/arm with the same name.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-09-02 10:04:30 +02:00
Jon Turney ed1573fc17
doc: Also update shebang for chapter-texi2docbook.py 2020-08-26 16:12:52 +01: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
Jon Turney c2d6e6f7f6
doc: Various fixes to makedocbook for python3.8
Also update shebang to explicitly use python3, since python2 is EOL and
(per PEP 0394) 'python' may not exist at all.
2020-08-24 17:36:10 +01: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 bafd65f2fb libm/machine/riscv: Add custom fma/sqrt functions when supported [v2]
Check for HW FMA and SQRT support and use those instructions in place
of software implementations.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-12 09:52:19 +02:00
Keith Packard via Newlib a44bc679a4 libm/machine/arm: Add optimized fmaf and fma when available
When HAVE_FAST_FMAF is set, use the vfma.f32 instruction, when
HAVE_FAST_FMA is set, use the vfma.f64 instruction.

Usually the compiler built-ins will already have inlined these
instructions, but provide these symbols for cases where that doesn't
work instead of falling back to the (inaccurate) common code versions.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-10 21:04:12 +02:00
Keith Packard via Newlib 0c1989070e libm: Detect fast fmaf support
Anything with fast FMA is assumed to have fast FMAF, along with
32-bit arms that advertise 32-bit FP support and __ARM_FEATURE_FMA

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-10 21:01:46 +02:00
Keith Packard via Newlib 432b331c79 libm: ARM without HW double does not have fast FMA
32-bit ARM processors with HW float (but not HW double) may define
__ARM_FEATURE_FMA, but that only means they have fast FMA for 32-bit
floats.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-10 21:01:46 +02:00
Keith Packard via Newlib 73b02710ec libm/math: ensure that expf(-huge) sets FE_UNDERFLOW exception
It was calling __math_uflow(0) instead of __math_uflowf(0), which
resulted in no exception being set on machines with exception support
for float but not double.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-10 10:31:36 +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 e108d04432 libm/math: Don't modify __ieee754_pow return values in pow
The __ieee754 functions already return the right value in exception
cases, so don't modify those. Setting the library to _POSIX_/_IEEE_
mode now only affects whether errno is modified.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-05 22:16:31 +02:00
Keith Packard via Newlib 98a4f8de47 libm/math: Set errno to ERANGE for pow(0, -y)
POSIX says that the errno for pow(0, -y) should be ERANGE instead of
EDOM.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/pow.html

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-05 22:16:31 +02:00
Keith Packard via Newlib 2eafcc78df libm/math: Make yx functions set errno=ERANGE for x=0
The y0, y1 and yn functions need separate conditions when x is zero as
that returns ERANGE instead of EDOM.

Also stop adjusting the return value from the __ieee754_y* functions
as that is already correct and we were just breaking it.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-05 22:16:31 +02:00
Keith Packard via Newlib 905aa4c013 libm/math: set errno to ERANGE at gamma poles
For POSIX, gamma(i) (i non-positive integer) should set errno to
ERANGE instead of EDOM.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-05 22:16:31 +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
Keith Packard via Newlib bb166cfc3e libm/common: Set WANT_ERRNO based on _IEEE_LIBM value
_IEEE_LIBM is the configuration value which controls whether the
original libm functions modify errno. Use that in the new math code as
well so that the resulting library is internally consistent.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-08-04 19:30:45 +02:00
Keith Packard 12ad9a46df libm/math: Use __math_xflow in obsolete math code [v2]
C compilers may fold const values at compile time, so expressions
which try to elicit underflow/overflow by performing simple
arithemetic on suitable values will not generate the required
exceptions.

Work around this by replacing code which does these arithmetic
operations with calls to the existing __math_xflow functions that are
designed to do this correctly.

Signed-off-by: Keith Packard <keithp@keithp.com>

----

v2:
	libm/math: Pass sign to __math_xflow instead of muliplying result
2020-08-03 13:29:27 +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
Sebastian Huber ba283d8777 arm: Fix include to avoid undefined reference
ld: libm.a(lib_a-fesetenv.o): in function `fesetenv':
newlib/libm/machine/arm/fesetenv.c:38: undefined reference to `vmsr_fpscr'

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2020-07-29 16:24:13 +02:00
Eshan dhawan 3ca4325968 arm: Split fenv.c into multiple files
Use the already existing stub files if possible.  These files are
necessary to override the stub implementation with the machine-specific
implementation through the build system.

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