Commit Graph

3246 Commits

Author SHA1 Message Date
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