Commit Graph

2537 Commits

Author SHA1 Message Date
Jon Turney e046e4de14 Update makedocbook for bd547490
Teach makedocbook how to handle some new things seen in the makedoc markup
since bd547490:

- struct lines appearing in the synopsis
- use of @strong{} texinfo markup
2017-02-15 16:32:36 +01:00
Thomas Preud'homme bd54749095 Allow locking routine to be retargeted
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.
2017-02-13 17:07:11 -05:00
Thomas Preud'homme fa55c610fa Only define static locks in multithreaded mode
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.
2017-02-13 17:04:17 -05:00
Freddie Chopin 0eeb4c1d32 Unify names of all lock objects
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
2017-02-06 16:55:09 -05:00
Kyrill Tkachov 52a6da816f arm: Fix addressing in optpld macro
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.
2017-01-26 16:29:36 +01:00
Pat Pannuto 3ebc26958e arm: Remove RETURN macro
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.
2017-01-25 13:32:09 +01:00
Pat Pannuto b219285f87 arm: Remove optpld macro
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
2017-01-25 13:32:09 +01:00
Pat Pannuto e7332409cc Remove unneeded references to arm_asm.h
This should result in no functional changes, it simply removes references
to arm_asm.h that did not use anything from that file.
2017-01-25 13:32:09 +01:00
Sebastian Huber 3cf29149be devctl.h: Fix typo and include proper header
Remove stray commas.  Include <sys/cdefs.h> for __restrict (includes
<stddef.h> indirectly).

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-01-25 12:37:19 +01:00
Sebastian Huber e692cfc121 RTEMS: Harmonize MAXNAMLEN and NAME_MAX
Override MAXNAMLEN definition in <dirent.h> and make sure it equals
NAME_MAX.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-01-25 12:36:37 +01:00
Thomas Preudhomme cd1b883526 Prefix consistenly target-independent locks with __
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
2017-01-25 12:36:05 +01:00
Eric Blake ca3e3bc54e nl_langinfo: Add NL_LOCALE_NAME macro
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>
2017-01-20 10:30:47 +01:00
Joel Sherrill 96267313e1 devctl.h: Use __restrict not restrict 2017-01-17 16:10:58 -06:00
Pat Pannuto e02866a1b4 Add missing headers to fix implicit function defns
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.
2017-01-16 10:14:28 +01:00
Gedare Bloom 338ce06971 Add _POSIX_SHARED_MEMORY_OBJECTS 2017-01-13 13:07:40 -06:00
Joe Seymour c0ac2ea2b3 Expand comments on padding used by nano_malloc
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.
2017-01-13 17:39:21 +01:00
Jeff Johnston e0477b4a0b Fix sys/reent.h to remove use of DEBUG flag.
- 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
2017-01-10 12:19:03 -05:00
Corinna Vinschen 5367b96a4b Fix versions in documentation (manually for now)
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-01-09 16:22:02 +01:00
Sebastian Huber 85d6679ab3 Add pthread_setname_np() and pthread_getname_np()
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>
2017-01-09 16:19:58 +01:00
Joe Seymour 83c39aedac Fix incorrect cast in nano malloc
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.
2017-01-09 16:16:12 +01:00
Sebastian Huber 69dabb3e30 RTEMS: Add user-defined name to thread queues
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>
2017-01-09 16:11:50 +01:00
Jeff Johnston 61f181d6b8 Bump release to 2.5.0 for yearly snapshot. 2016-12-22 21:33:54 -05:00
Jeff Johnston 959d85b341 This is an attempt to fix the problem described here:
https://sourceware.org/ml/newlib/2016/msg01139.html
https://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>
2016-12-22 14:50:00 -05:00
Sebastian Huber 483e696049 RTEMS: Increase SEM_VALUE_MAX
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>
2016-12-20 12:39:31 +01:00
Corinna Vinschen f46f501471 Remove extraneous float casts in wcstod.c.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-12-16 19:25:30 +01:00
Jeff Johnston 84e58ab648 Remove extraneous float casts in strtod.c. 2016-12-16 11:32:25 -05:00
Jeff Johnston dd4a4baab0 2016-12-15 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* 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.
2016-12-15 12:23:27 -05:00
Jeff Johnston 05272960ab 2016-12-15 Giuseppe Musumeci <giuseppe.musumeci@broadcom.com>
__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.
2016-12-15 12:12:31 -05:00
Julian Brown bc4f996f56 Big-endian fix for memcpy-armv7m.S
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>
2016-12-12 11:23:45 +01:00
Jon Turney 4007871174 Fix 'make man' for parallel make
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>
2016-12-06 17:34:47 +00:00
Joel Sherrill 1a2741508b Add <devctl.h> per POSIX 1003.26-2003 2016-12-05 21:00:38 -06:00
Sebastian Huber df2ea99a50 Add missing crt0 symbols for RTEMS
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>
2016-12-05 16:43:17 +01:00
Corinna Vinschen a43e81e233 Enforce no arguments for __get_current_locale/__get_C_locale
Remember: foo() != foo(void)

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-11-28 10:18:49 +01:00
Douglas 5fdd657b36 Correct argument to __get_current_locale.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-11-28 09:54:38 +01:00
Sebastian Huber 724e21493a Self-contained pthread_spinlock_t for RTEMS
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>
2016-11-24 16:57:51 +01:00
Sebastian Huber 9fbd510569 Provide <memory.h>
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>
2016-11-22 14:21:35 +01:00
Sebastian Huber 0bb58fbd3e Declare non-standard pthread_yield()
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>
2016-11-22 14:21:33 +01:00
Sebastian Huber e655d3d34b Move pthread types to <sys/_pthreadtypes.h>
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>
2016-11-17 11:33:15 +01:00
Sebastian Huber ba49de472f Add _TICKET_LOCK_INITIALIZER to <sys/lock.h>
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>
2016-11-17 11:28:45 +01:00
Sebastian Huber 9bbc5a34f2 Use __inline in <sys/lock.h> for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-17 11:28:21 +01:00
Corinna Vinschen 9ba4744620 sys/cdefs.h: Define __hidden as empty on Cygwin
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>
2016-11-08 16:14:43 +01:00
Sebastian Huber 172e2050d9 Use external header file for kernel space time
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-07 14:03:55 +01:00
Sebastian Huber 4b3a664a20 Add kernel space header for <sys/lock.h> for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-07 14:03:54 +01:00
Sebastian Huber dcaf7fedb9 Use external header file for kernel space types
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>
2016-11-07 14:03:53 +01:00
Sebastian Huber 64f900c9ce Provide cap_ioctl_t for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-07 14:03:51 +01:00
Thomas Preudhomme cf6e411f17 Fix pdf build failure with texinfo 6.1.0
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
2016-10-25 17:45:11 +02:00
Sebastian Huber 2b496cf1af Provide vm_page_t for RTEMS via <machine/_types.h>
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-10-25 16:24:07 +02:00
Sebastian Huber 40f07f7922 Provide rman_res_t for RTEMS via <machine/types.h>
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-10-25 16:24:06 +02:00
Sebastian Huber b1f3215380 Provide __intmax_t and __uintmax_t
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>
2016-10-25 16:24:05 +02:00
Sebastian Huber 4e91600796 Fix typo in <sys/_stdint.h>
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-10-25 16:24:03 +02:00