summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* newlib: regenerate libc/stdlib/Makefile.amCorinna Vinschen2017-08-111-9/+36
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Importing wcstoumax inttypes method from FreeBSD.Aditya Upadhyay2017-08-022-0/+158
|
* Importing wcstoimax inttypes method from FreeBSD.Aditya Upadhyay2017-08-022-0/+159
|
* Importing strtoumax inttypes method from FreeBSD.Aditya Upadhyay2017-08-022-0/+152
|
* Importing strtoimax inttypes method from FreeBSD.Aditya Upadhyay2017-08-022-0/+170
|
* newlib: regenerate stdlib/Makefile.inCorinna Vinschen2017-07-281-33/+62
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Importing imaxdiv inttypes method from FreeBSD.Aditya Upadhyay2017-07-282-0/+49
|
* Importing imaxabs inttypes method from FreeBSD.Aditya Upadhyay2017-07-282-0/+37
|
* Add BSD-specific reallocarray()Sebastian Huber2017-04-043-17/+66
| | | | | It is available in FreeBSD, NetBSD and OpenBSD, but not in glibc. It is used for example by OpenSSH.
* Use enum __packed in favour of -fshort-enumsSebastian Huber2017-04-033-7/+3
| | | | | | | | | | | | Some architectures like ARM encode the short enum option state in the object file and the linker checks that this option is consistent for all objects of an executable. In case applications use -fno-short-enums, then this leads to linker warnings. Use the enum __packed attribute for the relevent enums to avoid the -fshort-enums compiler option. This attribute is at least available on GCC, LLVM/clang and the Intel compiler. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
* Only define static locks in multithreaded modeThomas Preud'homme2017-02-134-0/+18
| | | | | | | | | | | | | Newlib build system defines __SINGLE_THREAD__ to allow concurrency code to be only compiled when newlib is configured for multithread. One such example are locks which become useless in single thread mode. Although most static locks are indeed guarded by !defined(__SINGLE_THREAD__), some are not. This commit adds these missing guards to __dd_hash_mutex, __atexit_recursive_mutex, __at_quick_exit_mutex and __arc4random_mutex. It also makes sure locking macros in lock.h are noop in single thread mode.
* Unify names of all lock objectsFreddie Chopin2017-02-066-23/+23
| | | | | | | | | | | | | | | | | | In preparation for the patch that would allow retargeting of locking routines, rename all lock objects to follow this pattern: "__<name>_[recursive_]mutex". Following locks were renamed: __dd_hash_lock -> __dd_hash_mutex __sfp_lock -> __sfp_recursive_mutex __sinit_lock -> __sinit_recursive_mutex __atexit_lock -> __atexit_recursive_mutex _arc4random_mutex -> __arc4random_mutex __env_lock_object -> __env_recursive_mutex __malloc_lock_object -> __malloc_recursive_mutex __atexit_mutex -> __at_quick_exit_mutex __tz_lock_object -> __tz_mutex
* Prefix consistenly target-independent locks with __Thomas Preudhomme2017-01-251-3/+3
| | | | | | | | | | | | | | | | | | | Hi, With the patch to allow newlib's locking routine to be retargeted currently under discussion, we need to start thinking of locks as part of newlib's ABI since newlib depends on specific names being provided by the OS. This patch renames 2 locks so that they follow the same naming convention as other locks. It needs to be applied before the retargeting patch, while locks are still an internal consideration. Newlib builds successfully with this change. Ok for master branch? Best regards, Thomas
* Expand comments on padding used by nano_mallocJoe Seymour2017-01-131-14/+37
| | | | | | | | | | | | | | This patch adds further comments to nano-mallocr.c, to more comprehensively explain how padding works in the malloc_chunk structure. It was originally discussed in the following thread: https://sourceware.org/ml/newlib/2017/msg00031.html 2017-01-13 Joe Seymour <joe.s@somniumtech.com> newlib/ * libc/stdlib/nano-mallocr.c (malloc_chunk, get_chunk_from_ptr) (nano_malloc): Add comments.
* Fix incorrect cast in nano mallocJoe Seymour2017-01-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As described in nano-mallocr.c, chunks of heap are represented in memory as a size (of type long), followed by some optional padding containing a negative offset to size, followed by the data area. get_chunk_from_ptr is responsible for taking a pointer to the data area (as returned by malloc) and finding the start of the chunk. It does this by assuming there is no padding and trying to read the size, if the size is negative then it uses that as an offset to find the true size. Crucially, it reads the padding area as a long. nano_malloc is responsible for populating the optional padding area. It does so by casting a pointer to an (int *) and writing the negative offset into it. This means that padding is being written as an int but read as a long. On msp430 an int is 2 bytes, while a long is 4 bytes. This means that 2 bytes are written to the padding, but 4 bytes are read from it: it has only been partially initialised. nano_malloc is the default malloc implementation for msp430. This patch changes the cast from (int *) to (long *). The change to nano_malloc has has been observed to fix a TI Energia project that had been malfunctioning because malloc was returning invalid addresses. The change to nano_memalign is based entirely on code inspection. I've built and tested as follows: Configured (gcc+newlib) with: --target=msp430-elf --enable-languages=c gcc testsuite variations: msp430-sim/-mcpu=msp430 msp430-sim/-mcpu=msp430x msp430-sim/-mcpu=msp430x/-mlarge/-mdata-region=either/-mcode-region=either msp430-sim/-mhwmult=none msp430-sim/-mhwmult=f5series My testing has shown no regressions, however I don't know if the gcc testsuite provides sufficient coverage for this patch? I don't have write access, so if this patch is acceptable after review, I would appreciate it if someone would commit it for me. Thanks, 2017-01-XX Joe Seymour <joe.s@somniumtech.com> newlib/ * libc/stdlib/nano-mallocr.c (nano_malloc): Fix incorrect cast. (nano_memalign): Likewise.
* Remove extraneous float casts in wcstod.c.Corinna Vinschen2016-12-161-2/+2
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Remove extraneous float casts in strtod.c.Jeff Johnston2016-12-161-2/+2
|
* 2016-12-15 Kyrylo Tkachov <kyrylo.tkachov@arm.com>cygwin-2_6_1-releaseJeff Johnston2016-12-152-8/+29
| | | | | | | | * libc/stdlib/strtod.c (strtof_l): Set errno to ERANGE when double to float conversion results in infinity. (strtof): Likewise. * libc/stdlib/wcstod.c (wcstof_l): Likewise. (wcstof): Likewise.
* Actually return value from __cp_indexCorinna Vinschen2016-10-221-1/+1
| | | | | | | | Fixes Coverty CID 153470 Also drop redundant declaration of __cp_index. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Drop redundant checks for NULL input string in wctomb helper funcsCorinna Vinschen2016-10-221-6/+0
| | | | | | Fixes Coverity CIDs 153465 and 153466 Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Fix pdf build failure wrt documentation of is*_l functionsThomas Preudhomme2016-08-171-2/+2
| | | | | | | | | | | make pdf on arm-none-eabi targets fails to build after the reorganization in baf0c9fcb56e5cf8f54357bf8d8646b51b236886 to fold is*_l documentation in their is* counterpart. This is due two issues: 1) newlib/libc/ctype/ctype.tex still including the def file for the long versions 2) missing angle brackets in .c files for some of is*_l functions This patch fixes the issues and allows make pdf to succeeds.
* Avoid "implicit declaration of function ‘strtold_l’" in wcstold.cCorinna Vinschen2016-08-161-0/+1
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Don't use locale_t in internal headerCorinna Vinschen2016-08-161-1/+1
| | | | Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Implement strto[dflu]_l/wcsto[dflu]_lCorinna Vinschen2016-08-1521-807/+964
| | | | | | | | | | Implement GNU extensions strtod_l, strtof_l, strtol_l, strtold_l, strtoll_l, strtoul_l, strtoull_l, wcstod_l, wcstof_l, wcstol_l, wcstold_l, wcstoll_l, wcstoul_l, wcstoull_l. Export from Cygwin, fix posix.xml. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Consolidate wctomb/mbtowc calls for POSIX-1.2008Corinna Vinschen2016-08-1515-145/+762
| | | | | | | | | | | | | | | | | | | | | - Remove charset parameter from low level __foo_wctomb/__foo_mbtowc calls. - Instead, create array of function for ISO and Windows codepages to point to function which does not require to evaluate the charset string on each call. Create matching helper functions. I.e., __iso_wctomb, __iso_mbtowc, __cp_wctomb and __cp_mbtowc are functions returning the right function pointer now. - Create __WCTOMB/__MBTOWC macros utilizing per-reent locale and replace calls to __wctomb/__mbtowc with calls to __WCTOMB/__MBTOWC. - Drop global __wctomb/__mbtowc vars. - Utilize aforementioned changes in Cygwin to get rid of charset in other, calling functions and simplify the code. - In Cygwin restrict global cygheap locale info to the job performed by internal_setlocale. Use UTF-8 instead of ASCII on the fly in internal conversion functions. - In Cygwin dll_entry, make sure to initialize a TLS area with a NULL _REENT->_locale pointer. Add comment to explain why. Signed-off by: Corinna Vinschen <corinna@vinschen.de>
* Regenerate newlib MakefilesJon Turney2016-07-041-3/+16
|
* Re-enable malloc_lock for newlib-nanoAndre Vieira (lists)2016-06-161-3/+2
| | | | | Re-enable the use of __malloc_lock and __malloc_unlock newlib-nano, tied the newlib-multithread.
* Use __machine_*_t_defined for internal typesSebastian Huber2016-04-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | Newlib defines defaults for internal types via <sys/_types.h> and uses <machine/_types.h> to let targets define their own type if necessary. Previously for example #ifndef __dev_t_defined typedef short __dev_t; #endif However, the __*_t_defined pattern conflicts with the glibc type guard pattern for user types, e.g. dev_t in this example. Introduce a __machine_*_t_defined pattern for internal types (defined by <machine/_types.h>, used by <sys/_types.h>). For example #ifndef __machine_dev_t_defined typedef short __dev_t; #endif Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
* Add Intel MCU targetIgor Venevtsev2016-04-041-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Intel MCU System V ABI are incompartible with i386 System V ABI: o Minimum instruction set is Intel Pentium ISA minus x87 instructions o No x87 or vector registers o First three args are passed in %eax, %edx and %ecx o Full specification available here: https://github.com/hjl-tools/x86-psABI/wiki/iamcu-psABI-0.7.pdf newlib/ * configure.host: Add new ix86-*-elfiamcu target newlib/libc/include/ * setjmp.h: Change _JBLEN for Intel MCU target newlib/libc/machine/i386/ * memchr.S: (memchr) Target-specific size-optimized version * memcmp.S: (memcmp) Likewise * memcpy.S: (memcpy) Likewise * memmove.S: (memmove) Likewise * memset.S: (memset) Likewise * setjmp.S: (setjmp) Likewise * strchr.S: (strchr) Likewise * strlen.S: (strlen) Likewise newlib/libc/stdlib/ * srtold.c: (__flt_rounds) Disable for Intel MCU
* Add simple versions of random() and srandom()Joel Sherrill2016-03-284-14/+110
| | | | | | | | | | | | | Prototypes also added for initstate() and setstate() but they were not implemented in the shared newlib code. * newlib/libc/include/cygwin/stdlib.h: Prototypes added. * winsup/cygwin/include/cygwin/stdlib.h: Prototypes removed. * newlib/libc/stdlib/random.c: New file. * newlib/libc/machine/epiphany/machine/stdlib.h: Removed * newlib/libc/stdlib/Makefile.am: Added random.c. * newlib/libc/stdlib/stdlib.tex: Added random.def. * newlib/libc/stdlib/Makefile.in: Regenerated.
* strtold: Fix Infinity value.Corinna Vinschen2016-03-261-1/+2
| | | | | | | | | | Infinity returned from strtold is recognized as NaN by GCC builtin functions. The reason is that ULtox is missing to set a bit. * libc/stdlib/strtorx.c (ULtox): Set high bit in second word to create valid Infinity value. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Move arc4random Cygwin only code to CygwinSebastian Huber2016-03-211-15/+0
| | | | | | Keep the Newlib arc4random.c identical to the OpenBSD upstream version. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>.
* Allow machine-dependent arc4 lockingCorinna Vinschen2016-03-201-18/+5
| | | | | | | | | | | | newlib: * libc/stdlib/arc4random.h: Remove Cygwin-specific locking code. Conditionalize arc4 locking. Check for _ARC4_LOCK_INIT being undefined to fall back to default implementation. cygwin: * include/machine/_arc4random.h: New file. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Cleanup macros in chacha_private.h to be target-type independentHowland, Craig D2016-03-181-5/+2
| | | | | * libc/stdlib/chacha_private.h (U8C, U32C): Remove un-necessary macros. (U8V, U32V): Drop masking.
* Only export arc4random_stir and arc4random_addrandom on CygwinCorinna Vinschen2016-03-181-8/+5
| | | | | | | Export to maintain backward compatibility, but don't let them do anything useful. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Arc4random locking: Check for threaded application on CygwinCorinna Vinschen2016-03-181-0/+19
| | | | | | | libc/stdlib/arc4random.h (_ARC4_LOCK): Special case Cygwin. (_ARC4_UNLOCK): Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Add arc4random_stir and arc4random_addrandom for OpenBSD compatibilityCorinna Vinschen2016-03-181-0/+18
| | | | | | | * libc/stdlib/arc4random.c (arc4random_stir): New function. (arc4random_addrandom): Ditto. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Add arc4random() etc. from OpenBSD 5.8Sebastian Huber2016-03-186-7/+582
| | | | | | | | | | | | | | | | | | | | | | | | | | | According to the OpenBSD man page, "A Replacement Call for Random". It offers high quality random numbers derived from input data obtained by the OpenBSD specific getentropy() system call which is declared in <unistd.h> and must be implemented for each Newlib port externally. The arc4random() functions are used for example in LibreSSL and OpenSSH. Cygwin provides currently its own implementation of the arc4random family. Maybe it makes sense to use this getentropy() implementation: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libcrypto/crypto/getentropy_win.c?rev=1.4&content-type=text/x-cvsweb-markup * libc/include/stdlib.h (arc4random): Declare if __BSD_VISIBLE. (arc4random_buf): Likewise. (arc4random_uniform): Likewise. * libc/include/sys/unistd.h (getentropy): Likewise. * libc/include/machine/_arc4random.h: New file. * libc/stdlib/arc4random.c: Likewise. * libc/stdlib/arc4random.h: Likewise. * libc/stdlib/arc4random_uniform.c: Likewise. * libc/stdlib/chacha_private.h: Likewise. * libc/sys/rtems/include/machine/_arc4random.h: Likewise. * libc/stdlib/Makefile.am (EXTENDED_SOURCES): Add arc4random.c and arc4random_uniform.c. * libc/stdlib/Makefile.in: Regenerate.
* Feature test macros overhaul: stdlib.hYaakov Selkowitz2016-03-171-0/+2
| | | | | | | | | | | | | | | | | | | | Throughout, simplify the C99/C11 conditionals, and replace __STRICT_ANSI__ with the proper internal POSIX macros. The _*_r reentrant functions need not be guarded (and most haven't been) because such names in the global scope are reserved to the implementation. atoff is unique to newlib. dtoa is not actually exported (_dtoa_r is used internally), is nonstandard, and the declaration conflicts with the code included in MySQL, NSPR, and SpiderMonkey. mktemp was removed in POSIX.1-2001. The qsort_r declarations are reordered so that the GNU version retains precedence. Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
* Fix compile with GCC 5 -WerrorYaakov Selkowitz2016-02-122-0/+3
| | | | | | | | | | | newlib/libc/ * stdio64/freopen64.c: Include <string.h> for memset(). * stdlib/quick_exit.c: Include <unistd.h> for _exit(). * string/gnu_basename.c (__gnu_basename): Fix discarded const qualifier warning. * stdlib/strtold.c: Include "mprec.h" for _strtorx_r(). Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
* Newlib build is broken if configured with nano-malloc and non-reentrant ↵Игорь Веневцев2016-02-081-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | system calls Non-reentrant system calls version implies both MISSING_SYSCALL_NAMES and REENTRANT_SYSCALL_PROVIDED macros to be defined. Being coupled with --enable-newlib-nano-malloc knob it breaks the build: bash-4.3$ ../newlib-2.3.0.20160104/configure CC_FOR_TARGET=gcc AR_FOR_TARGET=ar RANLIB_FOR_TARGET=ranlib CFLAGS_FOR_TARGET="-m32 -DMISSING_SYSCALL_NAMES -DREENTRANT_SYSCALLS_PROVIDED" --target=i386-elf --enable-newlib-nano-malloc && make <...omitted output...> ../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c: In function ‘_mallinfo_r’: ../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:489:35: error: macro "_sbrk_r" requires 2 arguments, but only 1 given sbrk_now = _sbrk_r(RCALL 0); ^ ../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:489:20: error: ‘_sbrk_r’ undeclared (first use in this function) sbrk_now = _sbrk_r(RCALL 0); ^ ../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:489:20: note: each undeclared identifier is reported only once for each function it appears in Makefile:1512: recipe for target 'lib_a-nano-mallinfor.o' failed make[8]: *** [lib_a-nano-mallinfor.o] Error 1 In case of non-reentrant system calls _sbrk_r became a macro with TWO args (defined in reent.h): #define _sbrk_r(__reent, __incr) sbrk(__incr) But in our case only one argument is present. (RCALL 0) is considered as a single argument despite RCALL itself is a macro:) So intermediate one-arg macro will be enough to expand args before final _sbrk_r expansion: #define _SBRK_R(X) _sbrk_r(X) Here is a patch:
* Fix atexit logic to honor _ATEXIT_DYNAMIC_ALLOC setting.Jeff Johnston2015-12-211-0/+7
| | | | | | | | | | | | | If small reent is enabled (_REENT_SMALL is defined) then malloc() was used in __register_exitproc() even if user requested it to be disabled (_ATEXIT_DYNAMIC_ALLOC is defined). With this fix, function fails when _ATEXIT_DYNAMIC_ALLOC is defined and whole static storage is already used. 2015-12-21 Freddie Chopin <freddie.chopin@gmail.com> * libc/stdlib/__atexit.c (__register_exitproc): Fix for _ATEXIT_DYNAMIC_ALLOC.
* Add static instance of _on_exit_args for _REENT_SMALL platforms.Jeff Johnston2015-12-217-22/+96
| | | | | | | | | | | | | 2015-12-21 Freddie Chopin <freddie.chopin@gmail.com> * libc/stdlib/on_exit_args.{c,h}: New files. * libc/stdlib/Makefile.am: Add new source file. * libc/stdlib/Makefile.in: Regenerate. * libc/stdlib/__atexit.c (__register_exitproc): Initialize _on_exit_args_ptr field of _GLOBAL_ATEXIT on first run. * libc/stdlib/on_exit.c: Force linking of static instance of _on_exit_args. * libc/stdlib/cxa_atexit.c: Likewise.
* Add missing lock releases in __register_exitproc().Freddie Chopin2015-12-141-1/+9
| | | | | | | | In some code paths the __atexit_lock held by this function was not released when returning with an error. * libc/stdlib/__atexit.c (__register_exitproc): Always release lock before return.
* Only build _strtodg_r on targets supporting a distinct long double typeCorinna Vinschen2015-11-261-0/+4
| | | | | | | * libc/stdlib/strtodg.c: Add ifdef to check _HAVE_LONG_DOUBLE and _LDBL_EQ_DBL. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* libc/stdlib/strtorx.c: Fix ifdef to check _LDBL_EQ_DBL.Steve Ellcey2015-11-241-2/+2
|
* Handle multibyte decimapl point in strtold.Corinna Vinschen2015-11-211-1/+8
| | | | | | | * libc/stdlib/strtodg.c: Define USE_LOCALE. (_strtodg_r): Handle multibyte decimal point. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Import correctly working strtold from David M. Gay.Corinna Vinschen2015-11-208-13/+1334
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libc/stdlib/Makefile.am (GENERAL_SOURCES): Add strtodg.c and strtorx.c. * libc/stdlib/Makefile.in: Regenerate. * libc/stdlib/strtodg.c: New file implementing generic string to long double conversion. * libc/stdlib/strtorx.c: New file, implementing IEEE format string to long double conversion. * libc/stdlib/mprec.h (_strtodg_r): Declare. (_strtorx_r): Declare. * libc/stdlib/gdtoa.h (__UShort): Define. * libc/stdlib/strtold.c (__flt_rounds): Define for i386 and x86_64 target. (FLT_ROUNDS): Define, as 0 on platforms missing a __flt_rounds function. (_strtold_r): Converted from strtold. Call _strtorx_r on targets supporting distinct long doubles. (strtold): Just call _strtold_r. * libc/include/stdlib.h (_strtold_r): Declare. * libc/stdlib/ldtoa.c (_strtold): Comment out. Explain why. * libc/stdio/vfscanf.c (__SVFSCANF_R): Call _strtold_r instead of _strtold. * libc/machine/powerpc/vfscanf.c (__svfscanf_r): Ditto. * common.din (strtold): Drop redirection to _strtold. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Make match function globally available to stdlib functions.Corinna Vinschen2015-11-203-21/+20
| | | | | | | | * libc/stdlib/strtod.c (match): Move from here... * libc/stdlib/gdtoa-hexnan.c (match): ...to here. * libc/stdlib/mprec.h (match): Declare and add __match define. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Drop unused declaration from wcstold.cCorinna Vinschen2015-11-201-2/+0
| | | | | | * libc/stdlib/wcstold.c (_strtold): Drop unused declaration. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>