diff options
author | Thomas Preud'homme <thomas.preudhomme@arm.com> | 2016-10-25 19:38:19 +0300 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2017-02-14 01:07:11 +0300 |
commit | bd54749095ee45d7136b6e7c8a1e5218749c87b6 (patch) | |
tree | 44af0f859a2f5f43d7bf62d92caa2ae27a9eabe2 /newlib/libc/misc | |
parent | fa55c610facaae12e38d90d14e44fecd1259b3ab (diff) |
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.
Diffstat (limited to 'newlib/libc/misc')
-rw-r--r-- | newlib/libc/misc/Makefile.am | 7 | ||||
-rw-r--r-- | newlib/libc/misc/Makefile.in | 28 | ||||
-rw-r--r-- | newlib/libc/misc/lock.c | 157 | ||||
-rw-r--r-- | newlib/libc/misc/misc.tex | 4 |
4 files changed, 188 insertions, 8 deletions
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am index 3fe8e55f5..7571ef263 100644 --- a/newlib/libc/misc/Makefile.am +++ b/newlib/libc/misc/Makefile.am @@ -6,6 +6,11 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c fini.c +if NEWLIB_RETARGETABLE_LOCKING +LIB_SOURCES += \ + lock.c +endif + libmisc_la_LDFLAGS = -Xcompiler -nostdlib if USE_LIBTOOL @@ -21,5 +26,5 @@ endif # USE_LIBTOOL include $(srcdir)/../../Makefile.shared -CHEWOUT_FILES = unctrl.def ffs.def +CHEWOUT_FILES = unctrl.def lock.def ffs.def CHAPTERS = misc.tex diff --git a/newlib/libc/misc/Makefile.in b/newlib/libc/misc/Makefile.in index 0ada8de34..e7925231c 100644 --- a/newlib/libc/misc/Makefile.in +++ b/newlib/libc/misc/Makefile.in @@ -53,6 +53,9 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +@NEWLIB_RETARGETABLE_LOCKING_TRUE@am__append_1 = \ +@NEWLIB_RETARGETABLE_LOCKING_TRUE@ lock.c + DIST_COMMON = $(srcdir)/../../Makefile.shared $(srcdir)/Makefile.in \ $(srcdir)/Makefile.am subdir = misc @@ -72,14 +75,19 @@ LIBRARIES = $(noinst_LIBRARIES) ARFLAGS = cru lib_a_AR = $(AR) $(ARFLAGS) lib_a_LIBADD = -am__objects_1 = lib_a-__dprintf.$(OBJEXT) lib_a-unctrl.$(OBJEXT) \ - lib_a-ffs.$(OBJEXT) lib_a-init.$(OBJEXT) lib_a-fini.$(OBJEXT) -@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) +@NEWLIB_RETARGETABLE_LOCKING_TRUE@am__objects_1 = \ +@NEWLIB_RETARGETABLE_LOCKING_TRUE@ lib_a-lock.$(OBJEXT) +am__objects_2 = lib_a-__dprintf.$(OBJEXT) lib_a-unctrl.$(OBJEXT) \ + lib_a-ffs.$(OBJEXT) lib_a-init.$(OBJEXT) lib_a-fini.$(OBJEXT) \ + $(am__objects_1) +@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_2) lib_a_OBJECTS = $(am_lib_a_OBJECTS) LTLIBRARIES = $(noinst_LTLIBRARIES) libmisc_la_LIBADD = -am__objects_2 = __dprintf.lo unctrl.lo ffs.lo init.lo fini.lo -@USE_LIBTOOL_TRUE@am_libmisc_la_OBJECTS = $(am__objects_2) +@NEWLIB_RETARGETABLE_LOCKING_TRUE@am__objects_3 = lock.lo +am__objects_4 = __dprintf.lo unctrl.lo ffs.lo init.lo fini.lo \ + $(am__objects_3) +@USE_LIBTOOL_TRUE@am_libmisc_la_OBJECTS = $(am__objects_4) libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS) libmisc_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ @@ -252,7 +260,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) -LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c fini.c +LIB_SOURCES = __dprintf.c unctrl.c ffs.c init.c fini.c $(am__append_1) libmisc_la_LDFLAGS = -Xcompiler -nostdlib @USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libmisc.la @USE_LIBTOOL_TRUE@libmisc_la_SOURCES = $(LIB_SOURCES) @@ -271,7 +279,7 @@ DOCBOOK_CHEW = ${top_srcdir}/../doc/makedocbook.py DOCBOOK_OUT_FILES = $(CHEWOUT_FILES:.def=.xml) DOCBOOK_CHAPTERS = $(CHAPTERS:.tex=.xml) CLEANFILES = $(CHEWOUT_FILES) $(CHEWOUT_FILES:.def=.ref) $(DOCBOOK_OUT_FILES) -CHEWOUT_FILES = unctrl.def ffs.def +CHEWOUT_FILES = unctrl.def lock.def ffs.def CHAPTERS = misc.tex all: all-am @@ -372,6 +380,12 @@ lib_a-fini.o: fini.c lib_a-fini.obj: fini.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fini.obj `if test -f 'fini.c'; then $(CYGPATH_W) 'fini.c'; else $(CYGPATH_W) '$(srcdir)/fini.c'; fi` +lib_a-lock.o: lock.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lock.o `test -f 'lock.c' || echo '$(srcdir)/'`lock.c + +lib_a-lock.obj: lock.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lock.obj `if test -f 'lock.c'; then $(CYGPATH_W) 'lock.c'; else $(CYGPATH_W) '$(srcdir)/lock.c'; fi` + mostlyclean-libtool: -rm -f *.lo diff --git a/newlib/libc/misc/lock.c b/newlib/libc/misc/lock.c new file mode 100644 index 000000000..a76317668 --- /dev/null +++ b/newlib/libc/misc/lock.c @@ -0,0 +1,157 @@ +/* +FUNCTION +<<__retarget_lock_init>>, <<__retarget_lock_init_recursive>>, <<__retarget_lock_close>>, <<__retarget_lock_close_recursive>>, <<__retarget_lock_acquire>>, <<__retarget_lock_acquire_recursive>>, <<__retarget_lock_try_acquire>>, <<__retarget_lock_try_acquire_recursive>>, <<__retarget_lock_release>>, <<__retarget_lock_release_recursive>>---locking routines + +INDEX + __lock___sinit_recursive_mutex +INDEX + __lock___sfp_recursive_mutex +INDEX + __lock___atexit_recursive_mutex +INDEX + __lock___at_quick_exit_mutex +INDEX + __lock___malloc_recursive_mutex +INDEX + __lock___env_recursive_mutex +INDEX + __lock___tz_mutex +INDEX + __lock___dd_hash_mutex +INDEX + __lock___arc4random_mutex + +INDEX + __retarget_lock_init +INDEX + __retarget_lock_init_recursive +INDEX + __retarget_lock_close +INDEX + __retarget_lock_close_recursive +INDEX + __retarget_lock_acquire +INDEX + __retarget_lock_acquire_recursive +INDEX + __retarget_lock_try_acquire +INDEX + __retarget_lock_try_acquire_recursive +INDEX + __retarget_lock_release +INDEX + __retarget_lock_release_recursive + +ANSI_SYNOPSIS + #include <lock.h> + struct __lock __lock___sinit_recursive_mutex; + struct __lock __lock___sfp_recursive_mutex; + struct __lock __lock___atexit_recursive_mutex; + struct __lock __lock___at_quick_exit_mutex; + struct __lock __lock___malloc_recursive_mutex; + struct __lock __lock___env_recursive_mutex; + struct __lock __lock___tz_mutex; + struct __lock __lock___dd_hash_mutex; + struct __lock __lock___arc4random_mutex; + + void __retarget_lock_init (_LOCK_T * <[lock_ptr]>); + void __retarget_lock_init_recursive (_LOCK_T * <[lock_ptr]>); + void __retarget_lock_close (_LOCK_T <[lock]>); + void __retarget_lock_close_recursive (_LOCK_T <[lock]>); + void __retarget_lock_acquire (_LOCK_T <[lock]>); + void __retarget_lock_acquire_recursive (_LOCK_T <[lock]>); + int __retarget_lock_try_acquire (_LOCK_T <[lock]>); + int __retarget_lock_try_acquire_recursive (_LOCK_T <[lock]>); + void __retarget_lock_release (_LOCK_T <[lock]>); + void __retarget_lock_release_recursive (_LOCK_T <[lock]>); + +DESCRIPTION +Newlib was configured to allow the target platform to provide the locking +routines and static locks at link time. As such, a dummy default +implementation of these routines and static locks is provided for +single-threaded application to link successfully out of the box on bare-metal +systems. + +For multi-threaded applications the target platform is required to provide +an implementation for @strong{all} these routines and static locks. If some +routines or static locks are missing, the link will fail with doubly defined +symbols. + +PORTABILITY +These locking routines and static lock are newlib-specific. Supporting OS +subroutines are required for linking multi-threaded applications. +*/ + +/* dummy lock routines and static locks for single-threaded apps */ + +#ifndef __SINGLE_THREAD__ + +#include <sys/lock.h> + +struct __lock { + char unused; +}; + +struct __lock __lock___sinit_recursive_mutex; +struct __lock __lock___sfp_recursive_mutex; +struct __lock __lock___atexit_recursive_mutex; +struct __lock __lock___at_quick_exit_mutex; +struct __lock __lock___malloc_recursive_mutex; +struct __lock __lock___env_recursive_mutex; +struct __lock __lock___tz_mutex; +struct __lock __lock___dd_hash_mutex; +struct __lock __lock___arc4random_mutex; + +void +__retarget_lock_init (_LOCK_T *lock) +{ +} + +void +__retarget_lock_init_recursive(_LOCK_T *lock) +{ +} + +void +__retarget_lock_close(_LOCK_T lock) +{ +} + +void +__retarget_lock_close_recursive(_LOCK_T lock) +{ +} + +void +__retarget_lock_acquire (_LOCK_T lock) +{ +} + +void +__retarget_lock_acquire_recursive (_LOCK_T lock) +{ +} + +int +__retarget_lock_try_acquire(_LOCK_T lock) +{ + return 1; +} + +int +__retarget_lock_try_acquire_recursive(_LOCK_T lock) +{ + return 1; +} + +void +__retarget_lock_release (_LOCK_T lock) +{ +} + +void +__retarget_lock_release_recursive (_LOCK_T lock) +{ +} + +#endif /* !defined(__SINGLE_THREAD__) */ diff --git a/newlib/libc/misc/misc.tex b/newlib/libc/misc/misc.tex index 22c313eb1..248243b53 100644 --- a/newlib/libc/misc/misc.tex +++ b/newlib/libc/misc/misc.tex @@ -4,6 +4,7 @@ This chapter describes miscellaneous routines not covered elsewhere. @menu * ffs:: Return first bit set in a word +* __retarget_lock_init:: Retargetable locking routines * unctrl:: Return printable representation of a character @end menu @@ -11,4 +12,7 @@ This chapter describes miscellaneous routines not covered elsewhere. @include misc/ffs.def @page +@include misc/lock.def + +@page @include misc/unctrl.def |