aboutsummaryrefslogtreecommitdiff
path: root/newlib
AgeCommit message (Collapse)AuthorFilesLines
2023-01-10newlib: libc: setjmp M-profile PACBTI-enablementVictor L. Do Nascimento1-0/+43
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-10newlib: libc: aeabi_memset M-profile PACBTI-enablementVictor L. Do Nascimento1-3/+11
Add function prologue/epilogue to conditionally add BTI landing pads and/or PAC code generation & authentication instructions depending on compilation flags.
2023-01-10newlib: libc: aeabi_memmove M-profile PACBTI-enablementVictor L. Do Nascimento1-5/+12
Add function prologue/epilogue to conditionally add BTI landing pads and/or PAC code generation & authentication instructions depending on compilation flags.
2023-01-10newlib: libc: memcpy M-profile PACBTI-enablementVictor L. Do Nascimento1-9/+24
Add function prologue/epilogue to conditionally add BTI landing pads and/or PAC code generation & authentication instructions depending on compilation flags.
2023-01-10newlib: libc: memchr M-profile PACBTI-enablementVictor L. Do Nascimento1-6/+44
Add function prologue/epilogue to conditionally add BTI landing pads and/or PAC code generation & authentication instructions depending on compilation flags.
2023-01-10newlib: libc: strlen M-profile PACBTI-enablementVictor L. Do Nascimento2-6/+25
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-10newlib: libc: strcmp M-profile PACBTI-enablementVictor L. Do Nascimento3-31/+60
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-10newlib: libc: define M-profile PACBTI-enablement macrosVictor L. Do Nascimento1-0/+441
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-03Fix memccpy to handle end char >= x80CompilerAI Research Group1-3/+3
- use unsigned char variables for optimized version of memccpy
2022-12-22nvptx: Implement '_exit' instead of 'exit'Thomas Schwinge3-24/+26
... 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-21remove +x bit on source filesMike Frysinger14-0/+0
These should never be marked executable as they have no shebang and are pure source files.
2022-12-19libc: arm: setjmp.S code cleanupVictor L. Do Nascimento1-12/+0
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-19Fix a bug in setjmp for MIPS o32/o64 FPXX/FP64Giovanni Bajo1-1/+1
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-16Fix 3 other instances of Reme typo (should be Remez)Jeff Johnston3-3/+3
2022-12-16Revert "amdgcn: Add vectorized math routines"Jeff Johnston95-8074/+46
This reverts commit 125e39bfea1a39341a60348c93a65cf4894e0f2a.
2022-12-16Fix a typo in the comment.Nadav Rotem1-1/+1
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-16amdgcn: Add vectorized math routinesKwok Cheung Yeung95-46/+8074
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-13libc: arm: fix setjmp abi non-conformanceVictor L. Do Nascimento2-37/+45
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-13newlib: info: tweak iconv node to avoid collisionsMike Frysinger2-2/+2
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-08Cygwin: define FILE as struct __sFILE64, not as __sFILECorinna Vinschen1-1/+17
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 2902b3a09e0a ("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 0f376ae22036 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: 0f376ae22036 ("Cygwin: rename __sFILE to __sFILE64 for backward compatibility") Fixes: 2902b3a09e0a ("Cygwin: drop requirement to build newlib's stdio64") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-12-07libc: fix fropen/fwopen compile warningsAlexey Lapshin1-4/+2
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-03Cygwin: fix LC_CTYPE in global locale to be a real C.UTF-8 localeCorinna Vinschen3-1/+21
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: a6a477fa8190 ("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-11-22amdgcn: Use __builtin_gcn_ in libc/machine/amdgcn/getreent.cTobias Burnus1-9/+29
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-21amdgcn: Replace asm("s8") by __builtin_gcn_kernarg_ptr if existingTobias Burnus3-3/+17
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-12makedocbook: Fix false report of unhandled texinfo commandJon Turney1-7/+8
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-12makedocbook: Adjust inline whitespace to fix flake8 warningsJon Turney2-69/+68
2022-11-12makedocbook: Drop stray semicolonsJon Turney1-2/+2
This isn't written in C :)
2022-11-12makedocbook: Use sys.exit()Jon Turney1-10/+6
Use sys.exit() to write a message to stderr and terminate with a non-zero exit code.
2022-11-12makedocbook: Use raw strings for regexesJon Turney1-11/+11
Use raw strings for regexes. This is best practice, and fixes a number of "W605 invalid escape sequence" flakes.
2022-11-10powerpc/setjmp: Fix 64-bit buffer alignmentSebastian Huber1-0/+16
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-08Generally make all 'long double complex' methods available in <complex.h>Thomas Schwinge1-19/+16
..., not just '#if defined(__CYGWIN__)'. (Exception: 'clog10l' which currently indeed is for Cygwin only.) This completes 2017-07-05 commit be3ca3947402827aa52709e677369bc7ad30aa1d "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-10-29strftime/wcsftime: use STRLEN, not strlenCorinna Vinschen1-1/+1
Commit 737e2004a3bb accidentally introduced a call to strlen in code used with wide character strings in case of wcsftime. Use STRLEN instead. Fixes: 737e2004a3bb ("strftime.c(__strftime): add %q, %v, tests; tweak %Z doc") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-10-29makedocbook: Add explicit locking for PLY parser table generationJon Turney3-229/+227
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-28powerpc/setjmp: Fix 64-bit supportSebastian Huber1-57/+72
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-28Fix warning during manpage generatonJon Turney1-2/+12
> 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-25strftime.c(__strftime): add %q, %v, tests; tweak %Z docBrian Inglis1-3/+55
%q GNU quarter year 1-4 %v BSD/OSX/Ruby VMS/Oracle %e-%b-%Y %Z change time zone *name* to *abbreviation*
2022-10-24strptime.c(strptime_l): add %q GNU quarterBrian Inglis1-1/+9
2022-09-28Rerun automake in newlib/Szabolcs Nagy1-2/+20
newlib/libc/sys/arm/Makefile.inc was modified but automake was not rerun in commit 5230eb7f8c6b43c71d7e38d138935c48de930b76 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-26Fix missing extern C statementMarkus B. Moessner1-0/+7
2022-09-24powerpc/setjmp: Add 64-bit supportSebastian Huber2-9/+78
Use 64-bit store/load instructions to save/restore the general-purpose registers.
2022-09-19Implement sysconf for ArmJeff Johnston4-1/+39
- 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-10upstream OpenBSD: arc4random: fix indenttb1-2/+2
2022-09-10upstream OpenBSD: arc4random: Randomise the rekey interval a little.djm1-3/+14
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-10upstream OpenBSD: arc4random: Remove unused ivbits argument from chacha_keysetupdtucker2-4/+4
to match other instances in the tree. ok deraadt@
2022-09-10upstream OpenBSD: arc4random: replace abort() with _exit()deraadt1-2/+2
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-10upstream OpenBSD: arc4random: bump file versionsCorinna Vinschen2-2/+2
This hides a patch not required in newlib
2022-09-10upstream OpenBSD: arc4random: Add support for building arc4random with MSVC.bcook1-7/+8
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-01Don't allocate another header when merging chunksTorbjörn SVENSSON1-4/+0
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-01Used chunk needs to be removed from free_listTorbjörn SVENSSON1-0/+9
When using nano malloc and the remaning heap space is not big enough to fullfill the allocation, malloc will attempt to merge the last chunk in the free list with a new allocation in order to create a bigger chunk. This is successful, but the chunk still remains in the free_list, so any later call to malloc can give out the same region without it first being freed. Possible sequence to verify: void *p1 = malloc(3000); void *p2 = malloc(4000); void *p3 = malloc(5000); void *p4 = malloc(6000); void *p5 = malloc(7000); free(p2); free(p4); void *p6 = malloc(35000); free(p6); void *p7 = malloc(42000); void *p8 = malloc(32000); Without the change, p7 and p8 points to the same address. Requirement, after malloc(35000), there is less than 42000 bytes available on the heap. Contributed by STMicroelectronics Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-08-31Fix some Coverity Scan errors.Jeff Johnston6-2/+10