aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc
AgeCommit message (Collapse)AuthorFilesLines
2023-01-19nvptx: Don't use global constructor for SSP setupThomas Schwinge1-2/+2
Given that nvptx newlib currently restricts itself to ELIX level 1, this is not already a problem. However, in the following we'd like to lift that restriction, and then run into: [...]/newlib/libc/ssp/stack_protector.c: In function ‘__stack_chk_init’: [...]/newlib/libc/ssp/stack_protector.c:31:1: sorry, unimplemented: global constructors not supported on this target 31 | } | ^ GCC patch "nvptx: Support global constructors/destructors via 'collect2'" has been posted, but not yet accepted. Until that is resolved, use the same manual SSP setup as for GCN.
2023-01-19nvptx: Provide stub 'gettimeofday'Thomas Schwinge1-0/+7
Instead of them FAILing due to 'unresolved symbol gettimeofday', this makes PASS a number of GCC 'gfortran.dg' test cases, for example.
2023-01-11libgloss: arm: break newlib dependencyMike Frysinger16-378/+14
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-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 Schwinge2-3/+4
... 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-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-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-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-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-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 Johnston3-1/+37
- 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
2022-08-31Restore _lock initialization in non-single threaded modeTorbjörn SVENSSON1-0/+4
When __SINGLE_THREAD__ is not defined, stdin, stdout and stderr needs to have their _lock instance initialized. The __sfp() method is not invoked for the 3 mentioned fds thus, the std() method needs to handle the initialization of the lock. This is more or less a revert of 382550072b49430f8c69adee937a0ba07bd385e6 Contributed by STMicroelectronics Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-08-15SH: Do not build syscalls if option providedYilin Sun via Newlib1-0/+2
This patch makes syscalls for SH architecture respecting the global option "--disable-newlib-supplied-syscalls". This is useful when a bare-metal toolchain is needed. Signed-off-by: Yilin Sun <imi415@imi.moe>
2022-08-12newlocale: fix crash when trying to write to __C_localeCorinna Vinschen1-1/+2
This simple testcase: locale_t st = newlocale(LC_ALL_MASK, "C", (locale_t)0); locale_t st2 = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", st); is sufficient to reproduce a crash in _newlocale_r. After the first call to newlocale, `st' points to __C_locale, which is const. When using `st' as locale base in the second call, _newlocale_r tries to set pointers inside base to NULL. This is bad if base is __C_locale, obviously. Add a test to avoid trying to overwrite pointer values inside base if base is __C_locale. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-03Cygwin: drop requirement to build newlib's stdio64Corinna Vinschen1-4/+0
Given that 64 bit Cygwin defines all file access types (off_t, fpos_t, and derived types) as 64 bit anyway, there's no reason left to rely on the stdio64 part of newlib. Use base functions and base types. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-07-13Add --enable-newlib-reent-thread-local optionMatt Joyce28-0/+215
By default, Newlib uses a huge object of type struct _reent to store thread-specific data. This object is returned by __getreent() if the __DYNAMIC_REENT__ Newlib configuration option is defined. The reentrancy structure contains for example errno and the standard input, output, and error file streams. This means that if an application only uses errno it has a dependency on the file stream support even if it does not use it. This is an issue for lower end targets and applications which need to qualify the software according to safety standards (for example ECSS-E-ST-40C, ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333). If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct _reent is replaced by dedicated thread-local objects for each struct _reent member. The thread-local objects are defined in translation units which use the corresponding object.
2022-07-13Add _REENT_IS_NULL()Matt Joyce4-3/+13
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-13Add _REENT_SIG_FUNC(ptr)Matt Joyce3-15/+16
Add a _REENT_SIG_FUNC() macro to encapsulate access to the _sig_func 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-13Add _REENT_CVTBUF(ptr)Matt Joyce3-8/+9
Add a _REENT_CVTBUF() macro to encapsulate access to the _cvtbuf 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-13Add _REENT_CVTLEN(ptr)Matt Joyce2-4/+5
Add a _REENT_CVTLEN() macro to encapsulate access to the _cvtlen member of struct reent. This will help to replace the struct member with a thread-local storage object in a follow-up patch.