Commit Graph

3681 Commits

Author SHA1 Message Date
Kwok Cheung Yeung e18743072b amdgcn: Add vectorized math routines
This implements a set of vectorized math routines to be used by the
compiler auto-vectorizer.  Versions for vectors with 2 lanes up to
64 lanes (in powers of 2) are provided.

These routines are based on the scalar versions of the math routines in
libm/common, libm/math and libm/mathfp.  They make extensive use of the GCC
C vector extensions and GCN-specific builtins in GCC.
2023-01-18 13:22:58 -05: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
CompilerAI Research Group ad3f9820b1 Fix memccpy to handle end char >= x80
- use unsigned char variables for optimized version of memccpy
2023-01-03 14:52:47 -05: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
Jeff Johnston c8130c3fe8 Fix 3 other instances of Reme typo (should be Remez) 2022-12-16 14:18:56 -05:00
Jeff Johnston c04c01524d Revert "amdgcn: Add vectorized math routines"
This reverts commit 125e39bfea.
2022-12-16 12:28:48 -05:00
Nadav Rotem abf672604b Fix a typo in the comment.
The implementation of expf() explains how approximation in the range [0 - 0.34] is done. The comment describes the "Reme" algorithm for constructing the polynomial. This is a typo and should be the "Remez" algorithm. The remez algorithm (or minimax) is used to calculate the coefficients of polynomials in other implementations of exp(0 and log().

See more:
https://en.wikipedia.org/wiki/Remez_algorithm
2022-12-16 12:18:28 -05:00
Kwok Cheung Yeung 125e39bfea amdgcn: Add vectorized math routines
This implements a set of vectorized math routines to be used by the
compiler auto-vectorizer.  Versions for vectors with 2 lanes up to
64 lanes (in powers of 2) are provided.

These routines are based on the scalar versions of the math routines in
libm/common, libm/math and libm/mathfp.  They make extensive use of the GCC
C vector extensions and GCN-specific builtins in GCC.
2022-12-16 12:18:14 -05: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
Mike Frysinger c8d5210337 newlib: info: tweak iconv node to avoid collisions
We have "Iconv" and "iconv" nodes which generates Iconv.html and
iconv.html files.  On a case-insensitive filesystem, these collide.
Rename the "Iconv" node to match the chapter name that it's already
using to avoid the issue.
2022-12-13 05:22:09 -05:00
Corinna Vinschen 55de3fdd0e Cygwin: define FILE as struct __sFILE64, not as __sFILE
Until Cygwin 3.3.6, we define __LARGE64_FILES unconditionally, so we
were using the type __sFILE64 even for 64 bit.  That was lazy and wrong.
so commit 2902b3a09e ("Cygwin: drop requirement to build newlib's
stdio64") tried to fix that.

Unfortunately this patch forgot to take the exposure of the typename
__sFILE64 in userspace into account.  This leads to trouble in C++ due
to name mangling.

Commit 0f376ae220 tried to fix this by just renaming __sFILE to
__sFILE64 by using a macro.  While __sFILE and __sFILE64 are the same
size, they are not exactly congruent.

To avoid backward compatibility problems, make sure to define FILE
as the  real __sFILE64, and make sure that __sFILE is not defined at
all on Cygwin.

Fixes: 0f376ae220 ("Cygwin: rename __sFILE to __sFILE64 for backward
compatibility")
Fixes: 2902b3a09e ("Cygwin: drop requirement to build newlib's stdio64")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-08 17:16:20 +01:00
Alexey Lapshin 0b09753a3f libc: fix fropen/fwopen compile warnings
This patch fixes warnings that appears when compiling:

#define fwopen(__cookie,__fn) funopen(__cookie, (int (*)())0, __fn,
(fpos_t (*)())0, (int (*)())0)
Expands to:

funopen(__null, (int (*)())0, &app_printf, (fpos_t (*)())0, (int
(*)())0)
argument of type "int (*)()" is incompatible with parameter of type
"int (*)(void *__cookie, char *__buf, int __n)"C/C++(167)
invalid conversion from 'fpos_t (*)()' {aka 'long int (*)()'} to
'fpos_t (*)(void*, fpos_t, int)' {aka 'long int (*)(void*,

Discussion is here:
https://github.com/espressif/arduino-esp32/issues/7407
2022-12-07 13:10:24 +01:00
Corinna Vinschen 8d138c3f66 Cygwin: fix LC_CTYPE in global locale to be a real C.UTF-8 locale
https://cygwin.com/pipermail/cygwin/2022-December/252571.html

Cygwin's default locale is "C.UTF-8" as far as LC_CTYPE settings
are concerned.  However, while __global_locale contains fixed
mbtowc and wctomb pointers, the lc_ctype_T pointer is still pointing
to _C_ctype_locale, representing the standard "C" locale.

The problem with this is that the codeset name as well as MB_CUR_MAX
is wrong.

Fix this by introducing a new lc_ctype_T structure called
_C_utf8_ctype_locale, setting the default codeset to "UTF-8" and
MB_CUR_MAX to 6.  Use this as lc_ctype_T pointer in __global_locale
by default on Cygwin.

Fixes: a6a477fa81 ("POSIX-1.2008 per-thread locales, groundwork part 1")
Co-Authored-By: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-03 16:16:30 +01: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
Jon Turney c03f0c3062
makedocbook: Fix false report of unhandled texinfo command
During 'make man', makedocbook falsely reports "texinfo command
'@modifier' remains in output" while processing the setlocal(3) manpage,
which contains that literal string.

Move the check for unrecognized texinfo commands to before processing
'@@' (an escaped '@') in the texinfo source, and teach it to ignore
them.

Improve that check slightly, so it catches non-alphabetic texinfo
commands, of which there are few.

Now we don't have false positives, we can make unrecognized texinfo
commands fatal to manpage generation, rather than leaving them verbatim
in the generated manpage.
2022-11-12 14:09:11 +00:00
Jon Turney 999925b253
makedocbook: Adjust inline whitespace to fix flake8 warnings 2022-11-12 14:09:10 +00:00
Jon Turney 2521dd48d8
makedocbook: Drop stray semicolons
This isn't written in C :)
2022-11-12 14:09:08 +00:00
Jon Turney 8b6c4249e2
makedocbook: Use sys.exit()
Use sys.exit() to write a message to stderr and terminate with a
non-zero exit code.
2022-11-12 14:09:07 +00:00
Jon Turney 2432d77099
makedocbook: Use raw strings for regexes
Use raw strings for regexes. This is best practice, and fixes a number
of "W605 invalid escape sequence" flakes.
2022-11-12 14:09:05 +00: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
Thomas Schwinge 67459ce679 Generally make all 'long double complex' methods available in <complex.h>
..., not just '#if defined(__CYGWIN__)'.  (Exception: 'clog10l' which currently
indeed is for Cygwin only.)

This completes 2017-07-05 commit be3ca39474
"Fixed warnings for some long double complex methods" after Aditya Upadhyay's
work on importing "Long double complex methods" from NetBSD.

For example, this changes GCC/nvptx libgfortran 'configure' output as follows:

    [...]
    checking for ccosf... yes
    checking for ccos... yes
    checking for ccosl... [-no-]{+yes+}
    [...]

..., and correspondingly GCC/nvptx 'nvptx-none/libgfortran/config.h' as
follows:

    [...]
     /* Define to 1 if you have the `ccosl' function. */
    -/* #undef HAVE_CCOSL */
    +#define HAVE_CCOSL 1
    [...]

Similarly for 'ccoshl', 'cexpl', 'cpowl', 'csinl', 'csinhl', 'ctanl', 'ctanhl',
'cacoshl', 'cacosl', 'casinhl', 'catanhl'.  ('conjl', 'cprojl' are not
currently being used in libgfortran.)

This in turn simplifies GCC/nvptx 'libgfortran/intrinsics/c99_functions.c'
compilation such that this files doesn't have to provide its own
"Implementation of various C99 functions" for those, when in fact they're
available in newlib libm.
2022-11-08 21:38:08 +01:00
Corinna Vinschen a8526cb52b strftime/wcsftime: use STRLEN, not strlen
Commit 737e2004a3 accidentally introduced a call to strlen in
code used with wide character strings in case of wcsftime.  Use
STRLEN instead.

Fixes: 737e2004a3 ("strftime.c(__strftime): add %q, %v, tests; tweak %Z doc")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-29 20:15:58 +02:00
Jon Turney d3d63cecbb
makedocbook: Add explicit locking for PLY parser table generation
Drop 'makedocbook --cache' (any dependency on the man-cache rule which
invokes that was dropped by the non-recursive make changes)

Instead, add some explicit locking which prevents processes colliding
over the file containing generated python code for the parser table.
2022-10-29 18:34:05 +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
Jon Turney 85148c43c4
Fix warning during manpage generaton
> ERROR: xref linking to Stubs has no generated link text.
> Error: no ID for constraint linkend: Stubs.

(Despite saying "ERROR", this is actually a warning, and manpages are
still generated)

Improve chapter-texi2docbook so it generates elements for texinfo
sections as well, so that a cross-reference to the "Stubs" section
contains a valid element ID.
2022-10-28 11:33:43 +01:00
Brian Inglis 737e2004a3 strftime.c(__strftime): add %q, %v, tests; tweak %Z doc
%q GNU quarter year 1-4
%v BSD/OSX/Ruby VMS/Oracle %e-%b-%Y
%Z change time zone *name* to *abbreviation*
2022-10-25 12:15:40 +02:00
Brian Inglis d6a26e542d strptime.c(strptime_l): add %q GNU quarter 2022-10-24 14:07:23 +02:00
Szabolcs Nagy 0b6342c97f Rerun automake in newlib/
newlib/libc/sys/arm/Makefile.inc was modified but automake was not rerun in

  commit 5230eb7f8c
  Implement sysconf for Arm

on arm-none-eabi target this caused

  ld: B/arm-none-eabi/lib/libg.a(libc_a-mallocr.o): in function `malloc_extend_top':
  S/newlib-cygwin/newlib/libc/stdlib/_mallocr.c:2161: undefined reference to `sysconf'
2022-09-28 10:49:53 -04:00
Markus B. Moessner 01f6251c09 Fix missing extern C statement 2022-09-26 13:44:21 -04: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
Jeff Johnston 5230eb7f8c Implement sysconf for Arm
- add support for using sysconf to get page size in _mallocr.c via
  HAVE_SYSCONF_PAGESIZE flag set in configure.host
- set flag in configure.host for arm and add a default sysconf implementation
  in libc/sys/arm that returns the page size
- the default implementation can be overridden outside newlib to allow a
  different page size to improve malloc on devices with a small footprint
  without needing to rebuild newlib
- this patch is based on a contribution from Torbjorn Svensson and
  Niklas Dahlquist (https://ecos.sourceware.org/ml/newlib/current/017616.html)
2022-09-19 15:35:55 -04:00
tb eb5c631ead upstream OpenBSD: arc4random: fix indent 2022-09-10 21:00:38 +02:00
djm 52a410f9bd upstream OpenBSD: arc4random: Randomise the rekey interval a little.
Previously, the chacha20 instance would be rekeyed every 1.6MB. This
makes it happen at a random point somewhere in the 1-2MB range.

Feedback deraadt@ visa@, ok tb@ visa@

newlib port: Make REKEY_BASE depend on SIZE_MAX
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-09-10 20:59:01 +02:00
dtucker f5fece2838 upstream OpenBSD: arc4random: Remove unused ivbits argument from chacha_keysetup
to match other instances in the tree. ok deraadt@
2022-09-10 20:58:03 +02:00
deraadt db5e07368c upstream OpenBSD: arc4random: replace abort() with _exit()
In the incredibly unbelievable circumstance where _rs_init() fails to
allocate pages, don't call abort() because of corefile data leakage
concerns, but simply _exit(). The reasoning is _rs_init() will only fail
if someone finds a way to apply specific pressure against this failure
point, for the purpose of leaking information into a core which they can
read. We don't need a corefile in this instance to debug that. So take
this "lever" away from whoever in the future wants to do that.
2022-09-10 20:58:03 +02:00
Corinna Vinschen dd22053fee upstream OpenBSD: arc4random: bump file versions
This hides a patch not required in newlib
2022-09-10 20:58:01 +02:00
bcook ef76759d7f upstream OpenBSD: arc4random: Add support for building arc4random with MSVC.
By default, MSVC's stdlib.h defines min(), so we need to spell out something
less common to avoid picking it up.

ok deraadt@ beck@ miod@
2022-09-10 20:56:25 +02:00
Torbjörn SVENSSON a68e99f883 Don't allocate another header when merging chunks
In the nano version of malloc, when the last chunk is to be extended,
there is no need to acount for the header again as it's already taken
into account in the overall "alloc_size" at the beginning of the
function.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-09-01 15:39:10 -04:00