At the moment when targeting bare-metal targets or systems without
definition for the locking primitives newlib, uses dummy empty macros.
This has the advantage of reduced size and faster implementation but
does not allow the application to retarget the locking routines.
Retargeting is useful for a single toolchain to support multiple systems
since then it's only at link time that you know which system you are
targeting.
This patch adds a new configure option
--enable-newlib-retargetable-locking to use dummy empty functions
instead of dummy empty macros. The default is to keep the current
behavior to not have any size or speed impact on targets not interested
in this feature. To allow for any size of lock, the _LOCK_T type is
changed into pointer to struct _lock and the _init function are tasked
with allocating the locks. The platform being targeted must provide the
static locks. A dummy implementation of the locking routines and static
lock is provided for single-threaded applications to link successfully
out of the box.
To ensure that the behavior is consistent (either no locking whatsoever
or working locking), the dummy implementation is strongly defined such
that a partial retargeting will cause a doubly defined link error.
Indeed, the linker will only pull in the file providing the dummy
implementation if it cannot find an implementation for one of the
routine or lock.
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.
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
In patch b219285f87 you have a syntax
error in the PLD instruction. The syntax for the pld argument should be
in square brackets as it's a memory address like so: pld [r1]. With
your patch the newlib build fails for armv7-a targets. This patch fixes
the build failures.
Tested by making sure the newlib build completes successfully.
2016-01-26 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* libc/machine/arm/strcpy.c (strcpy): Fix PLD assembly syntax.
* libc/machine/arm/strlen-stub.c (strlen): Likewise.
LTO can re-order top-level assembly blocks, which can cause this
macro definition to appear after its use (or not at all), causing
compilation failures. On modern toolchains (armv4t+), assembly
should write `bx lr` in all cases, and linkers will transparently
convert them to `mov pc, lr`, allowing us to simply remove the
macro.
(source: https://groups.google.com/forum/#!topic/comp.sys.arm/3l7fVGX-Wug
and verified empirically)
For the armv4.S file, preserve this macro to maximize backwards
compatibility.
LTO can re-order top-level assembly blocks, which can cause this
macro definition to appear after its use (or not at all), causing
compilation failures. As the macro has very few uses, simply removing
it by inlining is a simple fix.
n.b. one of the macro invocations in strlen-stub.c was already
guarded by the relevant #define, so it is simply converted directly
to a pld
Remove stray commas. Include <sys/cdefs.h> for __restrict (includes
<stddef.h> indirectly).
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
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
Provide an extension NL_LOCALE_NAME() macro, with semantics
matching glibc, which can be used as:
nl_langinfo_l(NL_LOCALE_NAME(LC_MESSAGES), locale);
to get back the locale string that locale was originally
created with during newlocale(). This in turn allows a library
(such as gettext) to determine what thread-local locale settings
it has inherited from the main program without having to be told
what parameters were passed to newlocale(), for less overall
coupling between parts of the program.
gnulib is set up to use the extension:
https://lists.gnu.org/archive/html/bug-gnulib/2017-01/msg00129.html
* libc/include/langinfo.h (NL_LOCALE_NAME): New macro
* libc/locale/nl_langinfo.c (nl_langinfo_l): Expose locale names
of a locale_t's category components.
Signed-off-by: Eric Blake <eblake@redhat.com>
A few files were missing headers for memset/malloc, likely missed
because the files don't directly call the functions, rather they
come in via macros in libc/include/sys/reent.h:
#define _REENT_CHECK(var, what, type, size, init) do { \
struct _reent *_r = (var); \
if (_r->what == NULL) { \
_r->what = (type)malloc(size); \
#define _REENT_CHECK_ASCTIME_BUF(var) \
_REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \
memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE))
Without these fixes, implicit function signatures are provided,
which gcc warns could cause aliasing issues down the line:
../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'memset' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: return value type mismatch
_PTR _EXFUN(memset,(_PTR, int, size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: 'memset' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/time/lcltime.c:58:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/string/strsignal.c:70:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
Including the proper headers elminates the implicit function
signatures and these warnings.
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.
- use of DEBUG flag is non-standard and interferes with other
project's using same flag
- change to be _REENT_CHECK_DEBUG which means the flag is
allowing debugging of _REENT_CHECK macros
- use #ifdef instead of #if
The pthread_setname_np() and pthread_getname_np() are GNU extensions and
provided by glibc.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
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.
Add a user-defined name to the self-contained synchronization objects in
order to make system diagnostics, tracing and debugging more user
friendly.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
https://sourceware.org/ml/newlib/2016/msg01139.htmlhttps://gcc.gnu.org/ml/gcc/2016-12/msg00010.html
There is no change if libtool is used.
Some run-time support libraries provided by GCC (e.g. libgomp) use
configure checks to detect certain features, e.g. availability of
thread-local storage. The configure script generates a test program and
tries to compile and link it. It should use target libraries and
startfiles of the build tree if available and not random ones from the
installation prefix for this procedure. The search directories
specified by -B are a bit special, see for_each_path() in gcc.c of the
GCC sources. First a search is performed on all search paths with the
multilib directory appended (if desired), then a second search is
performed on demand with the base directory only. For each multilib
there is a "newlib" subdirectory. This directory is specified by a -B
option for the support libraries. In order to find the newlib artifacts
(ctr0.o, libc.a, libg.a and libm.a) they must be located in a proper
multilib subdirectory withing the build directory.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
RTEMS defined SEM_VALUE_MAX to 32767 unlike other systems like FreeBSD
and glibc. A common value is INT_MAX.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
* 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.
__sinit initialises some common file descriptors as line buffered and
relies on the first users of such FDs to call __smakebuf_r. If
__smakebuf_r realises there's no space for a buffer (malloc returns
NULL), it makes them unbuffered. However, while setting the __SNBF
bit, it doesn't clear the __SLBF bit in the flags. Depending on the
order in which functions check buffering flags in the FD, sometime
they assume it's line buffered (e.g. __sfvwrite_r), trashing
application memory that's not really been allocated to them.
This patch solves the problem by clearing the unbuffered/line buffered
flag when setting the line buffered/unbuffered flag.
In the case of memcpy-armv7m.S being built for a big-endian multilib
(including armv7 without a specific profile), realignment code made
assumptions about the byte ordering being little-endian.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Ensure the Python Lex/Yacc (PLY) cache used by makedocbook is initialized
before it is used by parallelizable rules to make the DocBook XML, as it
appears that these can collide in cache generation, leading to errors.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
In order to enable proper detection of thread-local storage availability
we have to provide some symbols on ARM.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Turn pthread_spinlock_t into a self-contained object. On uni-processor
configurations, interrupts are disabled in the lock/trylock operations
and the previous interrupt status is restored in the corresponding
unlock operations. On SMP configurations, a ticket lock is a acquired
and released in addition.
See also:
https://devel.rtems.org/ticket/2674
This implementation is simple and efficient. However, this test case of
the Linux Test Project would fail due to call of printf() and sleep()
during spin lock ownership:
https://github.com/linux-test-project/ltp/blob/master/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_lock/1-2.c
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Provide <memory.h> for all standard Newlib targets and remove
Cygwin-specific header. Most POSIX like systems provide this historic
header.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
The non-standard pthread_yield() function is available at least on
Cygwin, FreeBSD and glibc.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
This makes it possible provide operating system specific types for
<pthread.h>. It is in line with the FreeBSD header file structure and
allows a future cleanup of <pthread.h> to not expose unrelated things
via <sys/types.h> and <unistd.h>. Glibc uses the similar
<bits/pthreadtypes.h> for this purpose.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Add _TICKET_LOCK_INITIALIZER to statically initialize a
_Ticket_lock_Control structure. This makes it possible to embed a
ticket lock in other structures outside of <sys/lock.h>.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Non-default visibility attributes are unsupported on PE/COFF, so don't
use in __hidden definition for Cygwin. Add comment.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The FreeBSD kernel types are not used in Newlib. Provide them via an
external header file to decouple Newlib and FreeBSD updates for RTEMS.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Hi,
make pdf on Ubuntu 16.04 fail with:
newlib/libc/libc.texinfo:9: Missing @endcsname inserted.
After a lot of fiddling the reason appears to be the combination of concept
and function index despite a lack of concept index entries. Arguably texinfo
should not error in that case but here we are, newlib will fail to build its
documentation on some systems because of this. Since libc.texinfo only
contains function index entries this patch simply removes the combination of
indices. It does the same for libm.texinfo which has concept index entries but
no function index entries.
Tested by running make pdf, make dvi, make info and make html successfully.
libc.pdf appears to have only one index as expected.
== Proposed commit message ==
Fix pdf build failure with texinfo 6.1.0 as provided in Ubuntu 16.04. Index
combination in libc.texinfo and libm.texinfo fails because both file have only
one type of index entries. Removing index combination is thus harmless and
solves the problem.
Is this ok for master?
Best regards,
Thomas
Provide __intmax_t and __uintmax_t via <machine/_default_types.h> and
define intmax_t and uintmax_t in <sys/_stdint.h> for FreeBSD
compatibility.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
The original test is broken. It tests for a NULL locale which
isn't just wrong, it simply can't occur at this point due to an
earlier check for a NULL locale string. Thus, the locale info
for a category is never taken from the environment.
Fixes Coverty CID 153467.
Also, add comment.
Also, add some parens for readability.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Update the getconf utility to support the new flag as well as
_PC_POSIX_PERMISSIONS and _PC_POSIX_SECURITY. These were previously
unsupported, probably as an oversight.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
_ctype_b is defined in ctype_.c as a const char array for non cygwin
targets allowing negative ctype index but as a char array for the same
targets in ctype_.h, giving type conflict at compile time. This is
because the cygwin targets are not treated specially in the latter file.
This patch adds the necessary logic for cygwin targets in ctype_.h.
While both long and long long are 64-bits on x86_64, they are distinct types,
and long was used prior to commit 477463a201.
Changing this breaks the linking of previously compiled C++ functions with
off_t arguments on 64-bit Cygwin with newly compiled code, as the mangling of
long (l) and long long (x) differ.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Keep __ctype_ptr__ available on Cygwin only, for backward compatibility
with existing apps referencing it via the ctype macros.
Otherwise initialize __global_locale.ctype_ptr and __C_locale.ctype_ptr
and use them throughout.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
__C_locale is const. Thus, overwriting the lconv values in __localeconv_l
will try to write to a R/O region. Given the lconv values in __C_locale
are initialized, there's no reason to write them in __localeconv_l at all.
Just return &__C_locale.lconv.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Only access "C" locale using the new __get_C_locale inline function.
Enable __global_locale for !_MB_CAPABLE targets. Accommodate !_MB_CAPABLE
targets in new locale code.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Now that __locale_cjk_lang is an inline function in setlocale.h and
setlocale.h is included, the declaration doesn't make sense.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Change nl_langinfo to nl_langinfo_l using locale given as argument.
Remove outdated TRANSITION_PERIOD_HACK. The codeset is stored in
the locale for quite some time now. For !MB_CAPABLE targets, just
return "US_ASCII" as codeset.
Implement nl_langinfo by calling nl_langinfo_l. Export nl_langinfo_l
from Cygwin DLL and bump minor API version number.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The former __locale_charset always fetched the current locale's charset.
We need the per-locale charset, too, in future. Rename __locale_charset
to __current_locale_charset and change __locale_charset to take a
locale_t as parameter. Accommodate througout.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This reverts commit 4de8596. It worked around a problem which was
actually introduced by patch 10a30e7 a few weeks ago. Rather than
adding special code to the newlib version of __getreent, the followup
patch reinstantiates the original, Cygwin-only implementation of
__getreent.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Stefan Assmann <sassmann@redhat.com>
So far the lib function __getreent always returned _impure_ptr. On Cygwin
this is only correct after _impure_ptr got initialized. The inline
function in include/cygwin/config.h always returns the right _reent ptr,
though.
After introducing per-thread locales, the __getreent function is called
prior to initialization of _impure_ptr (from dll_crt0_0) to access the
locale pointer, which leads to a crash.
Fix the __getreent lib function for Cygwin to return the correct _reent
pointer all the time. Rename inline function to __inline_getreent
and introduce a macro __getreent calling the inline function. Change
the lib function __getreent to call __inline_getreent on Cygwin.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
make pdf on arm-none-eabi targets fails to build after the reorganization in
baf0c9fcb5 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.
Using era_info_t and alt_digits_t indiscriminately in strftime and
strftime_l breaks targets not wanting C99 time formats.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
These functions are used from, e.g., nl_langinfo or strftime, so
we need them for all targets. Just return "C" locale category for
non-__HAVE_LOCALE_INFO__ targets.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Setting the categories strings in tmp_locale short-circuits
__loadlocale. Use a new_categories array instead, just as in
_setlocale_r.
- If we have a base, copy over the *not* defined categories in
category_mask in the first place. Rearrange loop accordingly.
- Free base right in newlocale.
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
Initializing a pointer to struct __locale_t to point to a string "C"
is not such a bright idea in the long run...
Signed-off by: Corinna Vinschen <corinna@vinschen.de>