Commit Graph

568 Commits

Author SHA1 Message Date
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
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
Alexey Lapshin 7ba103eb1a newlib: add Xtensa port 2023-08-17 18:14:15 -04:00
Kito Cheng via Newlib d572c4482b RISC-V: Support Zfinx/Zdinx extension.
Zfinx/Zdinx are new extensions ratified in 2022, it similar to F/D extensions,
support hard float operation for single/double precision, but the difference
between Zfinx/Zdinx and F/D is Zfinx/Zdinx is operating under general purpose
registers rather than dedicated floating-point registers.

This patch improve the hard float support detection for RISC-V port, so
that Zfinx/Zdinx can have better/right performance.

Co-authored-by: Jesse Huang <jesse.huang@sifive.com>
2023-07-26 15:21:35 +02:00
Remy Bohmer e79304d7b4 m68k: disallow unaligned access for m68010 and m68020
Disable at least  m68010 and m68020. These processors certainly do not
like unaligned accesses.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Signed-off-by: Austin Morton <austinpmorton@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
2023-05-30 13:54:32 -04:00
Jennifer Averett 048ebea981 newlib: Add non LDBL_EQ_DBL math support for aarch64, i386, and x86_64
Rename s_nearbyint.c, s_fdim.c and s_scalbln.c to remove conflicts
    Remove functions that are not needed from above files
    Modify include paths
    Add includes missing in cygwin build
    Add missing types
    Create Makefiles
    Create header files to resolve dependencies between directories
    Modify some instances of unsigned long to uint64_t for 32 bit platforms
    Add HAVE_FPMATH_H
2023-05-16 09:05:36 -05:00
Jennifer Averett c630a6a837 newlib: Add FreeBSD files for non LDBL_EQ_DBL support
FreeBSD files to add long double support for i386,
aarch64 and x86_64.
2023-05-16 09:05:36 -05:00
Victor L. Do Nascimento c6e601de84 libc: arm: Implement setjmp GCC backwards compatibility.
When compiling Newlib for arm targets with GCC 12.1 onward, the
passing of architecture extension information to the assembler is
automatic, making the use of .fpu and .arch_extension directives
in assembly files redundant.

With older versions of GCC, however, these directives must be
hard-coded into the `arm/setjmp.S' file to allow the assembly of
instructions concerning the storage and subsequent reloading of the
floating point registers to/from the jump buffer, respectively.

This patch conditionally adds the `.fpu vfpxd' and `.arch_extension
mve' directives based on compile-time preprocessor macros concerning
GCC version and target architectural features, such that both the
assembly and linking of setjmp.S succeeds for older versions of
Newlib.
2023-02-03 13:07:08 +00:00
Maciej W. Rozycki 963d6c79ea RISC-V: Fix floating-point environment support for soft float
We don't have floating-point exception or non-default rounding mode
support for the RISC-V soft-float environment, `feraiseexcept' and
`fesetround' do nothing unless the `__riscv_flen' macro has been set.
Therefore following ISO C language requirements[1] only define macros
for soft float that correspond to actually supported floating-point
environment features, removing failures from GCC testing such as:

FAIL: gcc.dg/torture/fp-int-convert-timode-3.c   -O0  execution test
FAIL: gcc.dg/torture/fp-int-convert-timode-4.c   -O0  execution test

References:

[1] "Programming languages -- C", ISO/IEC 9899:2023, working draft --
    September 3, 2022, Section 7.6 "Floating-point environment <fenv.h>"

Fixes: 7040b2de08 ("Add RISC-V port for libm")
Signed-off-by: Maciej W. Rozycki <macro@embecosm.com>
2023-01-27 14:25:44 +01:00
Thomas Schwinge 05a2d7a8b3 nvptx: In offloading execution, map '_exit' to 'abort' [GCC PR85463]
This is still not properly resolving <https://gcc.gnu.org/PR85463>
'[nvptx] "exit" in offloaded region doesn't terminate process', but is
one step into that direction, and allows for simplifying some GCC code.
2023-01-19 21:53:02 +01:00
Thomas Schwinge 29b137af80 nvptx: Provide stub 'getpid', 'kill', 'stat'
... as implemented for GCN in 'newlib/libc/sys/amdgcn/*' files, but (for now)
still adding to the catch-all 'newlib/libc/machine/nvptx/misc.c' file.

This is necessary for the GCC/Fortran I/O system, for example.

Co-authored-by: Andrew Stubbs <ams@codesourcery.com>
2023-01-19 21:52:50 +01:00
Thomas Schwinge 52cb937004 nvptx: Provide stub 'gettimeofday'
Instead of them FAILing due to 'unresolved symbol gettimeofday', this
makes PASS a number of GCC 'gfortran.dg' test cases, for example.
2023-01-19 21:50:57 +01:00
Mike Frysinger 26f9cfd7a8 libgloss: arm: break newlib dependency
The libgloss port has been reaching back into newlib internals for a
single header whose contents have been frozen for almost a decade.
To break this backwards libgloss->newlib dependency, move the acle
header to the srcroot include/ so everyone can use the same copy.
2023-01-11 01:00:15 -05:00
Victor L. Do Nascimento 31e5ce10db newlib: libc: setjmp M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.  Save the PAC value in the jump buffer so that
longjmp can only return to the authenticated location.
2023-01-10 16:47:02 +00:00
Victor L. Do Nascimento adc36ede11 newlib: libc: aeabi_memset M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.
2023-01-10 14:16:05 +00:00
Victor L. Do Nascimento bddfd64ec2 newlib: libc: aeabi_memmove M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.
2023-01-10 14:16:05 +00:00
Victor L. Do Nascimento 60a50c2846 newlib: libc: memcpy M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.
2023-01-10 14:16:05 +00:00
Victor L. Do Nascimento db30cbee41 newlib: libc: memchr M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.
2023-01-10 14:16:05 +00:00
Victor L. Do Nascimento 5582536896 newlib: libc: strlen M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.

This patch enables PACBTI for all relevant variants of strlen:
     * Newlib for armv8.1-m.main+pacbti
     * Newlib for armv8.1-m.main+pacbti+mve
     * Newlib-nano
2023-01-10 14:16:05 +00:00
Victor L. Do Nascimento ebd922e77a newlib: libc: strcmp M-profile PACBTI-enablement
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags.

This patch enables PACBTI for all relevant variants of strcmp:
     * Newlib for armv8.1-m.main+pacbti
     * Newlib for armv8.1-m.main+pacbti+mve
     * Newlib-nano
2023-01-10 14:16:05 +00:00
Victor L. Do Nascimento 9d6b00511e newlib: libc: define M-profile PACBTI-enablement macros
Augment the arm_asm.h header file to simplify function prologues and
epilogues whilst adding support for PACBTI enablement via macros for
hand-written assembly functions.  For PACBTI, both prologues/epilogues
as well as cfi-related directives are automatically amended
accordingly, depending on the compile-time mbranch-protection argument
values.

It defines the following preprocessor macros:
   * HAVE_PAC_LEAF: Indicates whether pac-signing has been requested for
   leaf functions.
   * PAC_LEAF_PUSH_IP: Whether leaf functions should push the pac code
   to the stack irrespective of whether the ip register is clobbered in
   the function or not.
   * STACK_ALIGN_ENFORCE: Whether a dummy register should be added to
   the push list as necessary in the prologue to ensure stack
   alignment preservation at the start of assembly function.  The
   epilogue behavior is likewise affected by this flag, ensuring any
   pushed dummy registers also get popped on function return.

It also defines the following assembler macros:
   * prologue: In addition to pushing any callee-saved registers onto
   the stack, it generates any requested pacbti instructions.
   Pushed registers are specified via the optional `first', `last',
   `push_ip' and `push_lr' macro argument parameters.
   when a single register number is provided, it pushes that
   register.  When two register numbers are provided, they specify a
   rage to save.  If push_ip and/or push_lr are non-zero, the
   respective registers are also saved.  Stack alignment is requested
   via the `align` argument, which defaults to the value of
   STACK_ALIGN_ENFORCE, unless manually overridden.

   For example:

       prologue push_ip=1 -> push {ip}
       prologue push_ip=1, align8=1 -> push {r2, ip}
       prologue push_ip=1, push_lr=1 -> push {ip, lr}
       prologue 1 -> push {r1}
       prologue 1, align8=1 -> push {r0, r1}
       prologue 1 push_ip=1 -> push {r1, ip}
       prologue 1 4 -> push {r1-r4}
       prologue 1 4 push_ip=1 -> push {r1-r4, ip}

   * epilogue: pops registers off the stack and emits pac key signing
   instruction, if requested. The `first', `last', `push_ip',
   `push_lr' and `align' function as per the prologue macro,
   generating pop instead of push instructions.

   Stack alignment is enforced via the following helper macro
   call-chain:

	{prologue|epilogue} ->_align8 -> _preprocess_reglist ->
	  _preprocess_reglist1 -> {_prologue|_epilogue}

   Finally, the necessary cfi directives for adding debug information
   to prologue and epilogue are generated via the following macros:

   * cfisavelist - prologue macro helper function, generating
   necessary .cfi_offset directives associated with push instruction.
   Therefore, the net effect of calling `prologue 1 2 push_ip=1' is
   to generate the following:

       push {r1-r2, ip}
       .cfi_adjust_cfa_offset 12
       .cfi_offset 143, -4
       .cfi_offset 2, -8
       .cfi_offset 1, -12

   * cfirestorelist - epilogue macro helper function, emitting
   .cfi_restore instructions prior to resetting the cfa offset.  As
   such, calling `epilogue 1 2 push_ip=1' will produce:

        pop {r1-r2, ip}
	.cfi_register 143, 12
	.cfi_restore 2
	.cfi_restore 1
	.cfi_def_cfa_offset 0
2023-01-10 14:16:05 +00:00
Thomas Schwinge 5841b2f6a4 nvptx: Implement '_exit' instead of 'exit'
... so that all of 'exit', '_exit', '_Exit' work.  'exit' thus becomes the
standard 'newlib/libc/stdlib/exit.c' -- and functions registered via 'atexit'
are now called at return from 'main' or manual 'exit' invocation.
2022-12-22 12:52:15 +01:00
Mike Frysinger 0a7bf8fc4c remove +x bit on source files
These should never be marked executable as they have no shebang and
are pure source files.
2022-12-21 22:38:57 -05:00
Victor L. Do Nascimento 57a08d6b9a libc: arm: setjmp.S code cleanup
The code for setjmp and longjmp contains unconditionally-disabled
legacy FPA code.

Given the code is not used by any targets, remove the code.
2022-12-19 11:22:11 +00:00
Giovanni Bajo 9bba9c2bdd Fix a bug in setjmp for MIPS o32/o64 FPXX/FP64
It seems there is a swapped logic in one of the subcases of
setjmp.S for MIPS: when the FPU registers are 64-bit within
a 32-bit aligned jmp_buf, the code realigns the pointers
before doing 64-bit writes, but the branch logic is swapped:
we must avoid the address adjustement when bit 2 is zero
(that is, the address is already 8-byte aligned).

This always triggers an address error when run, as tested
on a MIPS VR4300 with O64 ABI.
2022-12-19 10:38:05 +01:00
Victor L. Do Nascimento 15ad816ddd libc: arm: fix setjmp abi non-conformance
As per the arm Procedure Call Standard for the Arm Architecture
section 6.1.2 [1], VFP registers s16-s31 (d8-d15, q4-q7) must be
preserved across subroutine calls.

The current setjmp/longjmp implementations preserve only the core
registers, with the jump buffer size too small to store the required
co-processor registers.

In accordance with the C Library ABI for the Arm Architecture
section 6.11 [2], this patch sets _JBTYPE to long long adjusting
_JBLEN to 20.

It also emits vfp load/store instructions depending on architectural
support, predicated at compile time on ACLE feature-test macros.

[1] https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst
[2] https://github.com/ARM-software/abi-aa/blob/main/clibabi32/clibabi32.rst
2022-12-13 15:50:35 +00:00
Tobias Burnus b7aca332ce amdgcn: Use __builtin_gcn_ in libc/machine/amdgcn/getreent.c
Call __builtin_gcn_get_stack_limit and __builtin_gcn_first_call_this_thread_p
to reduce dependency on some register/layout assumptions by using the new
GCC mainline (GCC 13) builtins, if they are available. If not, the existing
code is used.
2022-11-22 18:05:34 -05:00
Tobias Burnus b9898fc993 amdgcn: Replace asm("s8") by __builtin_gcn_kernarg_ptr if existing
Check whether __builtin_gcn_kernarg_ptr is available and, if it is,
call it instead using the hard-coded 'asm("s8")' in:
* newlib/libc/machine/amdgcn/exit-value.h (exit_with_int)
* newlib/libc/machine/amdgcn/mlock.c (sbrk)
* newlib/libc/sys/amdgcn/write.c (write)

 newlib/libc/machine/amdgcn/exit-value.h |  6 ++++++
 newlib/libc/machine/amdgcn/mlock.c      | 10 +++++++---
 newlib/libc/sys/amdgcn/write.c          |  4 ++++
 3 files changed, 17 insertions(+), 3 deletions(-)
2022-11-21 13:10:29 +01:00
Sebastian Huber 5c79aa4b22 powerpc/setjmp: Fix 64-bit buffer alignment
The rlwinm is a word-size instruction which clears the remaining 32 bits of a
64-bit register.  Use clrrdi in 64-bit configurations.
2022-11-10 16:05:17 +01:00
Sebastian Huber a89d3a89c3 powerpc/setjmp: Fix 64-bit support
The first attempt to support the 64-bit mode had two bugs:

1. The saved general-purpose register 31 value was overwritten with the saved
   link register value.

2. The link register was saved and restored using 32-bit instructions.

Use 64-bit store/load instructions to save/restore the link register.  Make
sure that the general-purpose register 31 and the link register storage areas
do not overlap.
2022-10-28 12:53:42 +02:00
Sebastian Huber d9dc88048a powerpc/setjmp: Add 64-bit support
Use 64-bit store/load instructions to save/restore the general-purpose
registers.
2022-09-24 08:39:29 +02:00
Matt Joyce 1a09082036 Add _REENT_IS_NULL()
In a follow up patch, struct _reent is optionally replaced by dedicated
thread-local objects.  In this case,_REENT is optionally defined to NULL.  Add
the _REENT_IS_NULL() macro to disable this check on demand.
2022-07-13 06:55:46 +02:00
Matt Joyce f89ce35d83 Add _REENT_CLEANUP(ptr)
Add a _REENT_CLEANUP() macro to encapsulate access to the
__cleanup member of struct reent. This will help to replace the
struct member with a thread-local storage object in a follow up
patch.
2022-07-13 06:55:46 +02:00
Matt Joyce e56801f34d Add _REENT_STDERR(ptr)
Add a _REENT_STDERR() macro to encapsulate access to the _stderr
member of struct reent. This will help to replace the struct
member with a thread-local storage object in a follow up patch.
2022-07-13 06:55:46 +02:00
Matt Joyce 3266a46327 Add _REENT_STDOUT(ptr)
Add a _REENT_STDOUT() macro to encapsulate access to the _stdout
member of struct reent. This will help to replace the struct
member with a thread-local storage object in a follow up patch.
2022-07-13 06:55:46 +02:00
Matt Joyce 627a5cb413 Add _REENT_STDIN(ptr)
Add a _REENT_STDIN() macro to encapsulate access to the _stdin
member of struct reent. This will help to replace the struct
member with a thread-local storage object in a follow up patch.
2022-07-13 06:55:46 +02:00
Matt Joyce f3b8138239 Add _REENT_ERRNO(ptr)
Add a _REENT_ERRNO() macro to encapsulate the access to the
_errno member of struct reent. This will help to replace the
structure member with a thread-local storage object in a follow
up patch.

Replace uses of __errno_r() with _REENT_ERRNO().  Keep __errno_r() macro for
potential users outside of Newlib.
2022-07-13 06:55:41 +02:00
Sebastian Huber ad51d0006a Remove _global_impure_ptr indirection
Remove the pointer indirection through the read-only _global_impure_ptr and
directly use a externally visible _impure_data object of type struct _reent.
This enables the static initialization of global data structures in a follow up
patch.  In addition, we get rid of a machine-specific file.
2022-05-04 17:31:04 +02:00
Sebastian Huber bd95aa4d33 newlib: Remove superfluous CHECK_STD_INIT() macro
This macro is unused or expands to nothing.
2022-04-01 18:17:59 +02:00
Andrew Stubbs 761ef3b434 amdgcn: Fix build failure
The recent makefile reorganization broke the amdgcn port by creating
duplicate __malloc_lock symbols.  This patch fixes the problem by renaming
the malloc_support.c file to mlock.c, thus overriding the default symbol
properly.  Actually, I'm not sure how this ever worked?
2022-03-22 21:45:16 -04:00
Mike Frysinger 96bc16f6b2 newlib: libc: merge build up a directory
Convert all the libc/ subdir makes into the top-level Makefile.  This
allows us to build all of libc from the top Makefile without using any
recursive make calls.  This is faster and avoids the funky lib.a logic
where we unpack subdir archives to repack into a single libc.a.  The
machine override logic is maintained though by way of Makefile include
ordering, and source file accumulation in libc_a_SOURCES.

There's a few dummy.c files that are no longer necessary since we aren't
doing the lib.a accumulating, so punt them.

The winsup code has been pulling the internal newlib ssp library out,
but that doesn't exist anymore, so change that to pull the objects.
2022-03-16 21:18:25 -04:00
Mike Frysinger b2d4dc167c newlib: xstormy16: move malloc multiplex logic from build to source files
Rather than define per-object rules in the Makefile, have small files
that define & include the right content.  This simplifies the build
rules, and makes understanding the source a little easier (imo) as it
makes all the subdirs behave the same: you have 1 source file and it
produces 1 object.  It's also about the same amount of boiler plate,
without having to define custom build rules that can fall out of sync.

We also realign the free & pvalloc definitions: common code puts these
in malloc.o & valloc.o respectively, not in free.o & pvalloc.o objects.

This will also be important as we merge the libc.a build into the top
dir since it relies on a single flat list of objects for overrides.
2022-03-13 17:12:03 -04:00
Mike Frysinger 8c383e9ae7 newlib: xstormy16: break up mallocr stubs
Move the multiplex logic out of the build and into source files to
make the build rules a lot simpler.
2022-03-13 17:12:03 -04:00
Mike Frysinger 5cd957ff66 newlib: xstormy16: fix mallopt definition & mstats handling
The mallopt symbol is defined in tiny-malloc.c, not mallocr.c, but
the Makefile in here tries to compile it out of the latter.  This
leads to mallopt never being defined.

The build also creates mallinfo.o & mallopt.o & mallstats.o objects
to override common ones, but the common dir doesn't use these names.
Instead, it places these all in mstats.o.

So move the build define logic to a dedicated file and compile it
directly to make things a bit simpler while fixing the missing func
and aligning objects with the cmomon code.
2022-03-13 17:12:03 -04:00
Jeff Johnston 5fca4e0f18 Fix Bug libc/28945
- apply fix from Tom de Vries <vries@gcc.gnu.org>
  to have calloc zero out storage for nvptx calloc function
2022-03-07 15:35:02 -05:00
Mike Frysinger 644e8bba07 newlib: xstormy16: add missing string.h include
Some of these functions are using memcpy & memset from string.h but
not including the header leading to implicit declaration warnings.
2022-03-01 01:14:33 -05:00
Mike Frysinger 8343db918f newlib: libc: move configure into top-level
This kills off the last configure script under libc/ and folds it
into the top newlib configure script.  The a lot of the logic was
already in the top configure script, so move what's left into a
libc/acinclude.m4 file.
2022-02-25 13:52:48 -05:00
Matt Joyce 44b60f0c4b Make __sdidinit unused
Remove dependency on __sdidinit member of struct _reent to check
object initialization. Like __sdidinit, the __cleanup member of
struct _reent is initialized in the __sinit() function. Checking
initialization against __cleanup serves the same purpose and will
reduce overhead in the __sfp() function in a follow up patch.
2022-02-22 12:38:46 +01:00
Mike Frysinger 416792d59a newlib: libc: delete crt0.o duplication
The crt0.o was handled in a subdir-by-subdir basis: it would be compiled
in one (e.g. libc/sys/$arch/), then copied up one level (libc/sys/), then
copied up another (libc/) before finally being copied & installed in the
top newlib dir.  The libc/sys/ copy was cleaned up, and then the top dir
was changed to copy it directly out of the libc/sys/$arch/ dir.  But the
libc/sys/ copy to libc/ was left behind.  Clean that up now too.
2022-02-18 21:25:32 -05:00