public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/2, newlib] Allow locking routine to be retargeted
@ 2017-01-24 16:05 Thomas Preudhomme
  2017-01-25 11:39 ` Corinna Vinschen
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Thomas Preudhomme @ 2017-01-24 16:05 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

Hi,

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.

Testing: I've built a simple test program that calls malloc and free with all 
the locking function defined in the same file. Running into a debugger with 
breakpoints on the function shows that they are indeed called. Newlib testsuite 
(the 30 tests that run wich check-target-newlib from GCC) also comes back clean.

Is this ok for master branch?

Best regards,

Thomas

[-- Attachment #2: newlib_retargetable_locking_routine.patch --]
[-- Type: text/x-patch, Size: 19355 bytes --]

diff --git a/newlib/configure b/newlib/configure
index 2ac07fe06bfc795d94ba36d0061e4f8135146125..de28c25b3c4aaeed14b6d0ee8354fdd5c5c3115a 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -802,6 +802,7 @@ enable_newlib_nano_malloc
 enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1473,6 +1474,7 @@ Optional Features:
   --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2474,6 +2476,18 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11780,7 +11794,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11783 "configure"
+#line 11797 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11886,7 +11900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11889 "configure"
+#line 11903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12455,6 +12469,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _RETARGETABLE_LOCKING 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index bfaf038c7f495d32d05ae8caff0172f464895ffe..354c07ca580edf75da59fb858ca2c434e0b1a4e9 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
  esac],[newlib_nano_formatted_io=no])
 
+dnl Support --enable-retargetable-locking
+dnl This option is also read in libc/configure.in.  It is repeated
+dnl here so that it shows up in the help text.
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
 AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/configure b/newlib/libc/configure
index 4dc4d1bf703f388ecd3b4e0d8bef6786f7995021..dabe44fd98d74a2e029a22a217953dd52575736f 100755
--- a/newlib/libc/configure
+++ b/newlib/libc/configure
@@ -751,6 +751,8 @@ build
 newlib_basedir
 MAY_SUPPLY_SYSCALLS_FALSE
 MAY_SUPPLY_SYSCALLS_TRUE
+NEWLIB_RETARGETABLE_LOCKING_FALSE
+NEWLIB_RETARGETABLE_LOCKING_TRUE
 NEWLIB_NANO_FORMATTED_IO_FALSE
 NEWLIB_NANO_FORMATTED_IO_TRUE
 target_alias
@@ -797,6 +799,7 @@ enable_option_checking
 enable_newlib_io_pos_args
 enable_newlib_nano_malloc
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1448,6 +1451,7 @@ Optional Features:
   --enable-newlib-io-pos-args enable printf-family positional arg support
   --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
   --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2252,6 +2256,26 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+ if test x$newlib_retargetable_locking = xyes; then
+  NEWLIB_RETARGETABLE_LOCKING_TRUE=
+  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
+else
+  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
+  NEWLIB_RETARGETABLE_LOCKING_FALSE=
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11525,7 +11549,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11528 "configure"
+#line 11552 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11631,7 +11655,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11634 "configure"
+#line 11658 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
   as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
+  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
   as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
index 0a7bb8815be44fb1e92f753fa2c8df2a31b95f94..ac25a3933c4a4794f3cfe291e0275d0ed001b96a 100644
--- a/newlib/libc/configure.in
+++ b/newlib/libc/configure.in
@@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
  esac],[newlib_nano_formatted_io=no])
 AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
 
+dnl Support --enable-retargetable-locking used by libc/sys
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
+
 NEWLIB_CONFIGURE(..)
 
 AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
index 9075e35c9179968031010432515e3a845ff6ca8d..9a8e2528c79a89d5807da8c4bb0e65151870bf42 100644
--- a/newlib/libc/include/sys/lock.h
+++ b/newlib/libc/include/sys/lock.h
@@ -3,10 +3,13 @@
 
 /* dummy lock routines for single-threaded aps */
 
+#include <newlib.h>
+#include <_ansi.h>
+
+#ifndef _RETARGETABLE_LOCKING
+
 typedef int _LOCK_T;
 typedef int _LOCK_RECURSIVE_T;
- 
-#include <_ansi.h>
 
 #define __LOCK_INIT(class,lock) static int lock = 0;
 #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
@@ -21,4 +24,46 @@ typedef int _LOCK_RECURSIVE_T;
 #define __lock_release(lock) (_CAST_VOID 0)
 #define __lock_release_recursive(lock) (_CAST_VOID 0)
 
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _lock;
+typedef struct _lock * _LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+#define __LOCK_INIT(class,lock) extern struct _lock _lock_ ## lock; \
+	class _LOCK_T lock = &_lock_ ## lock
+#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
+
+extern void __retarget_lock_init(_LOCK_T *lock);
+#define __lock_init(lock) __retarget_lock_init(&lock)
+extern void __retarget_lock_init_recursive(_LOCK_T *lock);
+#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
+extern void __retarget_lock_close(_LOCK_T lock);
+#define __lock_close(lock) __retarget_lock_close(lock)
+extern void __retarget_lock_close_recursive(_LOCK_T lock);
+#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
+extern void __retarget_lock_acquire(_LOCK_T lock);
+#define __lock_acquire(lock) __retarget_lock_acquire(lock)
+extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
+#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
+extern int __retarget_lock_try_acquire(_LOCK_T lock);
+#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
+extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
+#define __lock_try_acquire_recursive(lock) \
+  __retarget_lock_try_acquire_recursive(lock)
+extern void __retarget_lock_release(_LOCK_T lock);
+#define __lock_release(lock) __retarget_lock_release(lock)
+extern void __retarget_lock_release_recursive(_LOCK_T lock);
+#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RETARGETABLE_LOCKING */
+
 #endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
index 3fe8e55f53ca87ba55f3a676b213e55fa66e77aa..7571ef26335c053315ad3f3df428a4742a9cf368 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 0ada8de34e7a3a6084dbab4bfa7caf8cb7f8d8f3..e7925231c203897d917f41accf6560e3336895bc 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 0000000000000000000000000000000000000000..1c69575b33f666c8170c2fe8473ad428f2741137
--- /dev/null
+++ b/newlib/libc/misc/lock.c
@@ -0,0 +1,149 @@
+/*
+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_lock
+INDEX
+	_lock___sfp_lock
+INDEX
+	_lock___atexit_lock
+INDEX
+	_lock___atexit_mutex
+INDEX
+	_lock___malloc_lock_object
+INDEX
+	_lock___env_lock_object
+INDEX
+	_lock___tz_lock_object
+INDEX
+	_lock___dd_hash_lock
+
+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_lock;
+	struct _lock _lock___sfp_lock;
+	struct _lock _lock___atexit_lock;
+	struct _lock _lock___atexit_mutex;
+	struct _lock _lock___malloc_lock_object;
+	struct _lock _lock___env_lock_object;
+	struct _lock _lock___tz_lock_object;
+	struct _lock _lock___dd_hash_lock;
+
+	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 */
+
+#include <sys/lock.h>
+
+struct _lock {
+  char unused;
+};
+
+struct _lock _lock___sinit_lock;
+struct _lock _lock___sfp_lock;
+struct _lock _lock___atexit_lock;
+struct _lock _lock___atexit_mutex;
+struct _lock _lock___malloc_lock_object;
+struct _lock _lock___env_lock_object;
+struct _lock _lock___tz_lock_object;
+struct _lock _lock___dd_hash_lock;
+
+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)
+{
+}
diff --git a/newlib/libc/misc/misc.tex b/newlib/libc/misc/misc.tex
index 22c313eb15c7676443ff4c928c8c76cc038f3f0f..6afd1be5c4a1e90ffd64881c63c5132e144ad364 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
+* lock::     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
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index d03dfac0eea6a8917a92b8f0f3584c2cd42b9388..397bc9b96eafddace3a75be509157040654b6fde 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -82,6 +82,9 @@
 /* Define if small footprint nano-formatted-IO implementation used.  */
 #undef _NANO_FORMATTED_IO
 
+/* Define if using retargetable functions for default lock routines.  */
+#undef _RETARGETABLE_LOCKING
+
 /*
  * Iconv encodings enabled ("to" direction)
  */

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/2, newlib] Allow locking routine to be retargeted
  2017-01-24 16:05 [PATCH 2/2, newlib] Allow locking routine to be retargeted Thomas Preudhomme
@ 2017-01-25 11:39 ` Corinna Vinschen
  2017-01-25 20:43   ` Jeff Johnston
  2017-01-29 11:19 ` [PATCH 2/2, " Freddie Chopin
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 19+ messages in thread
From: Corinna Vinschen @ 2017-01-25 11:39 UTC (permalink / raw)
  To: newlib; +Cc: Jeff Johnston

[-- Attachment #1: Type: text/plain, Size: 23023 bytes --]

Jeff?

On Jan 24 16:05, Thomas Preudhomme wrote:
> Hi,
> 
> 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.
> 
> Testing: I've built a simple test program that calls malloc and free with
> all the locking function defined in the same file. Running into a debugger
> with breakpoints on the function shows that they are indeed called. Newlib
> testsuite (the 30 tests that run wich check-target-newlib from GCC) also
> comes back clean.
> 
> Is this ok for master branch?
> 
> Best regards,
> 
> Thomas

> diff --git a/newlib/configure b/newlib/configure
> index 2ac07fe06bfc795d94ba36d0061e4f8135146125..de28c25b3c4aaeed14b6d0ee8354fdd5c5c3115a 100755
> --- a/newlib/configure
> +++ b/newlib/configure
> @@ -802,6 +802,7 @@ enable_newlib_nano_malloc
>  enable_newlib_unbuf_stream_opt
>  enable_lite_exit
>  enable_newlib_nano_formatted_io
> +enable_newlib_retargetable_locking
>  enable_multilib
>  enable_target_optspace
>  enable_malloc_debugging
> @@ -1473,6 +1474,7 @@ Optional Features:
>    --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
>    --enable-lite-exit	enable light weight exit
>    --enable-newlib-nano-formatted-io    Use nano version formatted IO
> +  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
>    --enable-multilib         build many library versions (default)
>    --enable-target-optspace  optimize for space
>    --enable-malloc-debugging indicate malloc debugging requested
> @@ -2474,6 +2476,18 @@ else
>  fi
>  
>  
> +# Check whether --enable-newlib-retargetable-locking was given.
> +if test "${enable_newlib_retargetable_locking+set}" = set; then :
> +  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
> +   yes) newlib_retargetable_locking=yes ;;
> +   no)  newlib_retargetable_locking=no ;;
> +   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
> + esac
> +else
> +  newlib_retargetable_locking=no
> +fi
> +
> +
>  
>  # Make sure we can run config.sub.
>  $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
> @@ -11780,7 +11794,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 11783 "configure"
> +#line 11797 "configure"
>  #include "confdefs.h"
>  
>  #if HAVE_DLFCN_H
> @@ -11886,7 +11900,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 11889 "configure"
> +#line 11903 "configure"
>  #include "confdefs.h"
>  
>  #if HAVE_DLFCN_H
> @@ -12455,6 +12469,13 @@ _ACEOF
>  
>  fi
>  
> +if test "${newlib_retargetable_locking}" = "yes"; then
> +cat >>confdefs.h <<_ACEOF
> +#define _RETARGETABLE_LOCKING 1
> +_ACEOF
> +
> +fi
> +
>  
>  if test "x${iconv_encodings}" != "x" \
>     || test "x${iconv_to_encodings}" != "x" \
> diff --git a/newlib/configure.in b/newlib/configure.in
> index bfaf038c7f495d32d05ae8caff0172f464895ffe..354c07ca580edf75da59fb858ca2c434e0b1a4e9 100644
> --- a/newlib/configure.in
> +++ b/newlib/configure.in
> @@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
>     *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
>   esac],[newlib_nano_formatted_io=no])
>  
> +dnl Support --enable-retargetable-locking
> +dnl This option is also read in libc/configure.in.  It is repeated
> +dnl here so that it shows up in the help text.
> +AC_ARG_ENABLE(newlib-retargetable-locking,
> +[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
> +[case "${enableval}" in
> +   yes) newlib_retargetable_locking=yes ;;
> +   no)  newlib_retargetable_locking=no ;;
> +   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
> + esac],[newlib_retargetable_locking=no])
> +
>  NEWLIB_CONFIGURE(.)
>  
>  dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
> @@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
>  AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
>  fi
>  
> +if test "${newlib_retargetable_locking}" = "yes"; then
> +AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
> +fi
> +
>  dnl
>  dnl Parse --enable-newlib-iconv-encodings option argument
>  dnl
> diff --git a/newlib/libc/configure b/newlib/libc/configure
> index 4dc4d1bf703f388ecd3b4e0d8bef6786f7995021..dabe44fd98d74a2e029a22a217953dd52575736f 100755
> --- a/newlib/libc/configure
> +++ b/newlib/libc/configure
> @@ -751,6 +751,8 @@ build
>  newlib_basedir
>  MAY_SUPPLY_SYSCALLS_FALSE
>  MAY_SUPPLY_SYSCALLS_TRUE
> +NEWLIB_RETARGETABLE_LOCKING_FALSE
> +NEWLIB_RETARGETABLE_LOCKING_TRUE
>  NEWLIB_NANO_FORMATTED_IO_FALSE
>  NEWLIB_NANO_FORMATTED_IO_TRUE
>  target_alias
> @@ -797,6 +799,7 @@ enable_option_checking
>  enable_newlib_io_pos_args
>  enable_newlib_nano_malloc
>  enable_newlib_nano_formatted_io
> +enable_newlib_retargetable_locking
>  enable_multilib
>  enable_target_optspace
>  enable_malloc_debugging
> @@ -1448,6 +1451,7 @@ Optional Features:
>    --enable-newlib-io-pos-args enable printf-family positional arg support
>    --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
>    --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
> +  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
>    --enable-multilib         build many library versions (default)
>    --enable-target-optspace  optimize for space
>    --enable-malloc-debugging indicate malloc debugging requested
> @@ -2252,6 +2256,26 @@ else
>  fi
>  
>  
> +# Check whether --enable-newlib-retargetable-locking was given.
> +if test "${enable_newlib_retargetable_locking+set}" = set; then :
> +  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
> +   yes) newlib_retargetable_locking=yes ;;
> +   no)  newlib_retargetable_lock=no ;;
> +   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
> + esac
> +else
> +  newlib_retargetable_locking=no
> +fi
> +
> + if test x$newlib_retargetable_locking = xyes; then
> +  NEWLIB_RETARGETABLE_LOCKING_TRUE=
> +  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
> +else
> +  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
> +  NEWLIB_RETARGETABLE_LOCKING_FALSE=
> +fi
> +
> +
>  
>  # Make sure we can run config.sub.
>  $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
> @@ -11525,7 +11549,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 11528 "configure"
> +#line 11552 "configure"
>  #include "confdefs.h"
>  
>  #if HAVE_DLFCN_H
> @@ -11631,7 +11655,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 11634 "configure"
> +#line 11658 "configure"
>  #include "confdefs.h"
>  
>  #if HAVE_DLFCN_H
> @@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
>    as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
>  Usually this means the macro was only invoked conditionally." "$LINENO" 5
>  fi
> +if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
> +  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
> +Usually this means the macro was only invoked conditionally." "$LINENO" 5
> +fi
>  if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
>    as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
>  Usually this means the macro was only invoked conditionally." "$LINENO" 5
> diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
> index 0a7bb8815be44fb1e92f753fa2c8df2a31b95f94..ac25a3933c4a4794f3cfe291e0275d0ed001b96a 100644
> --- a/newlib/libc/configure.in
> +++ b/newlib/libc/configure.in
> @@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
>   esac],[newlib_nano_formatted_io=no])
>  AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
>  
> +dnl Support --enable-retargetable-locking used by libc/sys
> +AC_ARG_ENABLE(newlib-retargetable-locking,
> +[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
> +[case "${enableval}" in
> +   yes) newlib_retargetable_locking=yes ;;
> +   no)  newlib_retargetable_lock=no ;;
> +   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
> + esac],[newlib_retargetable_locking=no])
> +AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
> +
>  NEWLIB_CONFIGURE(..)
>  
>  AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
> diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
> index 9075e35c9179968031010432515e3a845ff6ca8d..9a8e2528c79a89d5807da8c4bb0e65151870bf42 100644
> --- a/newlib/libc/include/sys/lock.h
> +++ b/newlib/libc/include/sys/lock.h
> @@ -3,10 +3,13 @@
>  
>  /* dummy lock routines for single-threaded aps */
>  
> +#include <newlib.h>
> +#include <_ansi.h>
> +
> +#ifndef _RETARGETABLE_LOCKING
> +
>  typedef int _LOCK_T;
>  typedef int _LOCK_RECURSIVE_T;
> - 
> -#include <_ansi.h>
>  
>  #define __LOCK_INIT(class,lock) static int lock = 0;
>  #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
> @@ -21,4 +24,46 @@ typedef int _LOCK_RECURSIVE_T;
>  #define __lock_release(lock) (_CAST_VOID 0)
>  #define __lock_release_recursive(lock) (_CAST_VOID 0)
>  
> +#else
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +struct _lock;
> +typedef struct _lock * _LOCK_T;
> +#define _LOCK_RECURSIVE_T _LOCK_T
> +
> +#define __LOCK_INIT(class,lock) extern struct _lock _lock_ ## lock; \
> +	class _LOCK_T lock = &_lock_ ## lock
> +#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
> +
> +extern void __retarget_lock_init(_LOCK_T *lock);
> +#define __lock_init(lock) __retarget_lock_init(&lock)
> +extern void __retarget_lock_init_recursive(_LOCK_T *lock);
> +#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
> +extern void __retarget_lock_close(_LOCK_T lock);
> +#define __lock_close(lock) __retarget_lock_close(lock)
> +extern void __retarget_lock_close_recursive(_LOCK_T lock);
> +#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
> +extern void __retarget_lock_acquire(_LOCK_T lock);
> +#define __lock_acquire(lock) __retarget_lock_acquire(lock)
> +extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
> +#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
> +extern int __retarget_lock_try_acquire(_LOCK_T lock);
> +#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
> +extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
> +#define __lock_try_acquire_recursive(lock) \
> +  __retarget_lock_try_acquire_recursive(lock)
> +extern void __retarget_lock_release(_LOCK_T lock);
> +#define __lock_release(lock) __retarget_lock_release(lock)
> +extern void __retarget_lock_release_recursive(_LOCK_T lock);
> +#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _RETARGETABLE_LOCKING */
> +
>  #endif /* __SYS_LOCK_H__ */
> diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
> index 3fe8e55f53ca87ba55f3a676b213e55fa66e77aa..7571ef26335c053315ad3f3df428a4742a9cf368 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 0ada8de34e7a3a6084dbab4bfa7caf8cb7f8d8f3..e7925231c203897d917f41accf6560e3336895bc 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 0000000000000000000000000000000000000000..1c69575b33f666c8170c2fe8473ad428f2741137
> --- /dev/null
> +++ b/newlib/libc/misc/lock.c
> @@ -0,0 +1,149 @@
> +/*
> +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_lock
> +INDEX
> +	_lock___sfp_lock
> +INDEX
> +	_lock___atexit_lock
> +INDEX
> +	_lock___atexit_mutex
> +INDEX
> +	_lock___malloc_lock_object
> +INDEX
> +	_lock___env_lock_object
> +INDEX
> +	_lock___tz_lock_object
> +INDEX
> +	_lock___dd_hash_lock
> +
> +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_lock;
> +	struct _lock _lock___sfp_lock;
> +	struct _lock _lock___atexit_lock;
> +	struct _lock _lock___atexit_mutex;
> +	struct _lock _lock___malloc_lock_object;
> +	struct _lock _lock___env_lock_object;
> +	struct _lock _lock___tz_lock_object;
> +	struct _lock _lock___dd_hash_lock;
> +
> +	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 */
> +
> +#include <sys/lock.h>
> +
> +struct _lock {
> +  char unused;
> +};
> +
> +struct _lock _lock___sinit_lock;
> +struct _lock _lock___sfp_lock;
> +struct _lock _lock___atexit_lock;
> +struct _lock _lock___atexit_mutex;
> +struct _lock _lock___malloc_lock_object;
> +struct _lock _lock___env_lock_object;
> +struct _lock _lock___tz_lock_object;
> +struct _lock _lock___dd_hash_lock;
> +
> +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)
> +{
> +}
> diff --git a/newlib/libc/misc/misc.tex b/newlib/libc/misc/misc.tex
> index 22c313eb15c7676443ff4c928c8c76cc038f3f0f..6afd1be5c4a1e90ffd64881c63c5132e144ad364 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
> +* lock::     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
> diff --git a/newlib/newlib.hin b/newlib/newlib.hin
> index d03dfac0eea6a8917a92b8f0f3584c2cd42b9388..397bc9b96eafddace3a75be509157040654b6fde 100644
> --- a/newlib/newlib.hin
> +++ b/newlib/newlib.hin
> @@ -82,6 +82,9 @@
>  /* Define if small footprint nano-formatted-IO implementation used.  */
>  #undef _NANO_FORMATTED_IO
>  
> +/* Define if using retargetable functions for default lock routines.  */
> +#undef _RETARGETABLE_LOCKING
> +
>  /*
>   * Iconv encodings enabled ("to" direction)
>   */


-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/2, newlib] Allow locking routine to be retargeted
  2017-01-25 11:39 ` Corinna Vinschen
@ 2017-01-25 20:43   ` Jeff Johnston
  2017-01-31 17:19     ` [PATCH 3/3, " Thomas Preudhomme
  0 siblings, 1 reply; 19+ messages in thread
From: Jeff Johnston @ 2017-01-25 20:43 UTC (permalink / raw)
  To: newlib

I am fine with this but I would like to see the struct _lock renamed
to be struct __lock and the lock names double-underscored to stay out of user
name space.  After that, it is fine for check-in.

-- Jeff J.

----- Original Message -----
> Jeff?
> 
> On Jan 24 16:05, Thomas Preudhomme wrote:
> > Hi,
> > 
> > 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.
> > 
> > Testing: I've built a simple test program that calls malloc and free with
> > all the locking function defined in the same file. Running into a debugger
> > with breakpoints on the function shows that they are indeed called. Newlib
> > testsuite (the 30 tests that run wich check-target-newlib from GCC) also
> > comes back clean.
> > 
> > Is this ok for master branch?
> > 
> > Best regards,
> > 
> > Thomas
> 
> > diff --git a/newlib/configure b/newlib/configure
> > index
> > 2ac07fe06bfc795d94ba36d0061e4f8135146125..de28c25b3c4aaeed14b6d0ee8354fdd5c5c3115a
> > 100755
> > --- a/newlib/configure
> > +++ b/newlib/configure
> > @@ -802,6 +802,7 @@ enable_newlib_nano_malloc
> >  enable_newlib_unbuf_stream_opt
> >  enable_lite_exit
> >  enable_newlib_nano_formatted_io
> > +enable_newlib_retargetable_locking
> >  enable_multilib
> >  enable_target_optspace
> >  enable_malloc_debugging
> > @@ -1473,6 +1474,7 @@ Optional Features:
> >    --disable-newlib-unbuf-stream-opt    disable unbuffered stream
> >    optimization in streamio
> >    --enable-lite-exit	enable light weight exit
> >    --enable-newlib-nano-formatted-io    Use nano version formatted IO
> > +  --enable-newlib-retargetable-locking    Allow locking routines to be
> > retargeted at link time
> >    --enable-multilib         build many library versions (default)
> >    --enable-target-optspace  optimize for space
> >    --enable-malloc-debugging indicate malloc debugging requested
> > @@ -2474,6 +2476,18 @@ else
> >  fi
> >  
> >  
> > +# Check whether --enable-newlib-retargetable-locking was given.
> > +if test "${enable_newlib_retargetable_locking+set}" = set; then :
> > +  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
> > +   yes) newlib_retargetable_locking=yes ;;
> > +   no)  newlib_retargetable_locking=no ;;
> > +   *) as_fn_error $? "bad value ${enableval} for
> > newlib-retargetable-locking" "$LINENO" 5 ;;
> > + esac
> > +else
> > +  newlib_retargetable_locking=no
> > +fi
> > +
> > +
> >  
> >  # Make sure we can run config.sub.
> >  $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
> > @@ -11780,7 +11794,7 @@ else
> >    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> >    lt_status=$lt_dlunknown
> >    cat > conftest.$ac_ext <<_LT_EOF
> > -#line 11783 "configure"
> > +#line 11797 "configure"
> >  #include "confdefs.h"
> >  
> >  #if HAVE_DLFCN_H
> > @@ -11886,7 +11900,7 @@ else
> >    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> >    lt_status=$lt_dlunknown
> >    cat > conftest.$ac_ext <<_LT_EOF
> > -#line 11889 "configure"
> > +#line 11903 "configure"
> >  #include "confdefs.h"
> >  
> >  #if HAVE_DLFCN_H
> > @@ -12455,6 +12469,13 @@ _ACEOF
> >  
> >  fi
> >  
> > +if test "${newlib_retargetable_locking}" = "yes"; then
> > +cat >>confdefs.h <<_ACEOF
> > +#define _RETARGETABLE_LOCKING 1
> > +_ACEOF
> > +
> > +fi
> > +
> >  
> >  if test "x${iconv_encodings}" != "x" \
> >     || test "x${iconv_to_encodings}" != "x" \
> > diff --git a/newlib/configure.in b/newlib/configure.in
> > index
> > bfaf038c7f495d32d05ae8caff0172f464895ffe..354c07ca580edf75da59fb858ca2c434e0b1a4e9
> > 100644
> > --- a/newlib/configure.in
> > +++ b/newlib/configure.in
> > @@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
> >     *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
> >   esac],[newlib_nano_formatted_io=no])
> >  
> > +dnl Support --enable-retargetable-locking
> > +dnl This option is also read in libc/configure.in.  It is repeated
> > +dnl here so that it shows up in the help text.
> > +AC_ARG_ENABLE(newlib-retargetable-locking,
> > +[  --enable-newlib-retargetable-locking    Allow locking routines to be
> > retargeted at link time],
> > +[case "${enableval}" in
> > +   yes) newlib_retargetable_locking=yes ;;
> > +   no)  newlib_retargetable_locking=no ;;
> > +   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking)
> > ;;
> > + esac],[newlib_retargetable_locking=no])
> > +
> >  NEWLIB_CONFIGURE(.)
> >  
> >  dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
> > @@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
> >  AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
> >  fi
> >  
> > +if test "${newlib_retargetable_locking}" = "yes"; then
> > +AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
> > +fi
> > +
> >  dnl
> >  dnl Parse --enable-newlib-iconv-encodings option argument
> >  dnl
> > diff --git a/newlib/libc/configure b/newlib/libc/configure
> > index
> > 4dc4d1bf703f388ecd3b4e0d8bef6786f7995021..dabe44fd98d74a2e029a22a217953dd52575736f
> > 100755
> > --- a/newlib/libc/configure
> > +++ b/newlib/libc/configure
> > @@ -751,6 +751,8 @@ build
> >  newlib_basedir
> >  MAY_SUPPLY_SYSCALLS_FALSE
> >  MAY_SUPPLY_SYSCALLS_TRUE
> > +NEWLIB_RETARGETABLE_LOCKING_FALSE
> > +NEWLIB_RETARGETABLE_LOCKING_TRUE
> >  NEWLIB_NANO_FORMATTED_IO_FALSE
> >  NEWLIB_NANO_FORMATTED_IO_TRUE
> >  target_alias
> > @@ -797,6 +799,7 @@ enable_option_checking
> >  enable_newlib_io_pos_args
> >  enable_newlib_nano_malloc
> >  enable_newlib_nano_formatted_io
> > +enable_newlib_retargetable_locking
> >  enable_multilib
> >  enable_target_optspace
> >  enable_malloc_debugging
> > @@ -1448,6 +1451,7 @@ Optional Features:
> >    --enable-newlib-io-pos-args enable printf-family positional arg support
> >    --enable-newlib-nano-malloc    Use small-footprint nano-malloc
> >    implementation
> >    --enable-newlib-nano-formatted-io    Use small-footprint
> >    nano-formatted-IO implementation
> > +  --enable-newlib-retargetable-locking    Allow locking routines to be
> > retargeted at link time
> >    --enable-multilib         build many library versions (default)
> >    --enable-target-optspace  optimize for space
> >    --enable-malloc-debugging indicate malloc debugging requested
> > @@ -2252,6 +2256,26 @@ else
> >  fi
> >  
> >  
> > +# Check whether --enable-newlib-retargetable-locking was given.
> > +if test "${enable_newlib_retargetable_locking+set}" = set; then :
> > +  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
> > +   yes) newlib_retargetable_locking=yes ;;
> > +   no)  newlib_retargetable_lock=no ;;
> > +   *) as_fn_error $? "bad value ${enableval} for
> > newlib-retargetable-locking" "$LINENO" 5 ;;
> > + esac
> > +else
> > +  newlib_retargetable_locking=no
> > +fi
> > +
> > + if test x$newlib_retargetable_locking = xyes; then
> > +  NEWLIB_RETARGETABLE_LOCKING_TRUE=
> > +  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
> > +else
> > +  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
> > +  NEWLIB_RETARGETABLE_LOCKING_FALSE=
> > +fi
> > +
> > +
> >  
> >  # Make sure we can run config.sub.
> >  $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
> > @@ -11525,7 +11549,7 @@ else
> >    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> >    lt_status=$lt_dlunknown
> >    cat > conftest.$ac_ext <<_LT_EOF
> > -#line 11528 "configure"
> > +#line 11552 "configure"
> >  #include "confdefs.h"
> >  
> >  #if HAVE_DLFCN_H
> > @@ -11631,7 +11655,7 @@ else
> >    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> >    lt_status=$lt_dlunknown
> >    cat > conftest.$ac_ext <<_LT_EOF
> > -#line 11634 "configure"
> > +#line 11658 "configure"
> >  #include "confdefs.h"
> >  
> >  #if HAVE_DLFCN_H
> > @@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" &&
> > test -z "${NEWLIB_NANO_FORMATTE
> >    as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never
> >    defined.
> >  Usually this means the macro was only invoked conditionally." "$LINENO" 5
> >  fi
> > +if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z
> > "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
> > +  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never
> > defined.
> > +Usually this means the macro was only invoked conditionally." "$LINENO" 5
> > +fi
> >  if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z
> >  "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
> >    as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
> >  Usually this means the macro was only invoked conditionally." "$LINENO" 5
> > diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
> > index
> > 0a7bb8815be44fb1e92f753fa2c8df2a31b95f94..ac25a3933c4a4794f3cfe291e0275d0ed001b96a
> > 100644
> > --- a/newlib/libc/configure.in
> > +++ b/newlib/libc/configure.in
> > @@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
> >   esac],[newlib_nano_formatted_io=no])
> >  AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io =
> >  xyes)
> >  
> > +dnl Support --enable-retargetable-locking used by libc/sys
> > +AC_ARG_ENABLE(newlib-retargetable-locking,
> > +[  --enable-newlib-retargetable-locking    Allow locking routines to be
> > retargeted at link time],
> > +[case "${enableval}" in
> > +   yes) newlib_retargetable_locking=yes ;;
> > +   no)  newlib_retargetable_lock=no ;;
> > +   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking)
> > ;;
> > + esac],[newlib_retargetable_locking=no])
> > +AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test
> > x$newlib_retargetable_locking = xyes)
> > +
> >  NEWLIB_CONFIGURE(..)
> >  
> >  AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
> > diff --git a/newlib/libc/include/sys/lock.h
> > b/newlib/libc/include/sys/lock.h
> > index
> > 9075e35c9179968031010432515e3a845ff6ca8d..9a8e2528c79a89d5807da8c4bb0e65151870bf42
> > 100644
> > --- a/newlib/libc/include/sys/lock.h
> > +++ b/newlib/libc/include/sys/lock.h
> > @@ -3,10 +3,13 @@
> >  
> >  /* dummy lock routines for single-threaded aps */
> >  
> > +#include <newlib.h>
> > +#include <_ansi.h>
> > +
> > +#ifndef _RETARGETABLE_LOCKING
> > +
> >  typedef int _LOCK_T;
> >  typedef int _LOCK_RECURSIVE_T;
> > -
> > -#include <_ansi.h>
> >  
> >  #define __LOCK_INIT(class,lock) static int lock = 0;
> >  #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
> > @@ -21,4 +24,46 @@ typedef int _LOCK_RECURSIVE_T;
> >  #define __lock_release(lock) (_CAST_VOID 0)
> >  #define __lock_release_recursive(lock) (_CAST_VOID 0)
> >  
> > +#else
> > +
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
> > +
> > +struct _lock;
> > +typedef struct _lock * _LOCK_T;
> > +#define _LOCK_RECURSIVE_T _LOCK_T
> > +
> > +#define __LOCK_INIT(class,lock) extern struct _lock _lock_ ## lock; \
> > +	class _LOCK_T lock = &_lock_ ## lock
> > +#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
> > +
> > +extern void __retarget_lock_init(_LOCK_T *lock);
> > +#define __lock_init(lock) __retarget_lock_init(&lock)
> > +extern void __retarget_lock_init_recursive(_LOCK_T *lock);
> > +#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
> > +extern void __retarget_lock_close(_LOCK_T lock);
> > +#define __lock_close(lock) __retarget_lock_close(lock)
> > +extern void __retarget_lock_close_recursive(_LOCK_T lock);
> > +#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
> > +extern void __retarget_lock_acquire(_LOCK_T lock);
> > +#define __lock_acquire(lock) __retarget_lock_acquire(lock)
> > +extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
> > +#define __lock_acquire_recursive(lock)
> > __retarget_lock_acquire_recursive(lock)
> > +extern int __retarget_lock_try_acquire(_LOCK_T lock);
> > +#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
> > +extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
> > +#define __lock_try_acquire_recursive(lock) \
> > +  __retarget_lock_try_acquire_recursive(lock)
> > +extern void __retarget_lock_release(_LOCK_T lock);
> > +#define __lock_release(lock) __retarget_lock_release(lock)
> > +extern void __retarget_lock_release_recursive(_LOCK_T lock);
> > +#define __lock_release_recursive(lock)
> > __retarget_lock_release_recursive(lock)
> > +
> > +#ifdef __cplusplus
> > +}
> > +#endif
> > +
> > +#endif /* _RETARGETABLE_LOCKING */
> > +
> >  #endif /* __SYS_LOCK_H__ */
> > diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
> > index
> > 3fe8e55f53ca87ba55f3a676b213e55fa66e77aa..7571ef26335c053315ad3f3df428a4742a9cf368
> > 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
> > 0ada8de34e7a3a6084dbab4bfa7caf8cb7f8d8f3..e7925231c203897d917f41accf6560e3336895bc
> > 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
> > 0000000000000000000000000000000000000000..1c69575b33f666c8170c2fe8473ad428f2741137
> > --- /dev/null
> > +++ b/newlib/libc/misc/lock.c
> > @@ -0,0 +1,149 @@
> > +/*
> > +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_lock
> > +INDEX
> > +	_lock___sfp_lock
> > +INDEX
> > +	_lock___atexit_lock
> > +INDEX
> > +	_lock___atexit_mutex
> > +INDEX
> > +	_lock___malloc_lock_object
> > +INDEX
> > +	_lock___env_lock_object
> > +INDEX
> > +	_lock___tz_lock_object
> > +INDEX
> > +	_lock___dd_hash_lock
> > +
> > +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_lock;
> > +	struct _lock _lock___sfp_lock;
> > +	struct _lock _lock___atexit_lock;
> > +	struct _lock _lock___atexit_mutex;
> > +	struct _lock _lock___malloc_lock_object;
> > +	struct _lock _lock___env_lock_object;
> > +	struct _lock _lock___tz_lock_object;
> > +	struct _lock _lock___dd_hash_lock;
> > +
> > +	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 */
> > +
> > +#include <sys/lock.h>
> > +
> > +struct _lock {
> > +  char unused;
> > +};
> > +
> > +struct _lock _lock___sinit_lock;
> > +struct _lock _lock___sfp_lock;
> > +struct _lock _lock___atexit_lock;
> > +struct _lock _lock___atexit_mutex;
> > +struct _lock _lock___malloc_lock_object;
> > +struct _lock _lock___env_lock_object;
> > +struct _lock _lock___tz_lock_object;
> > +struct _lock _lock___dd_hash_lock;
> > +
> > +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)
> > +{
> > +}
> > diff --git a/newlib/libc/misc/misc.tex b/newlib/libc/misc/misc.tex
> > index
> > 22c313eb15c7676443ff4c928c8c76cc038f3f0f..6afd1be5c4a1e90ffd64881c63c5132e144ad364
> > 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
> > +* lock::     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
> > diff --git a/newlib/newlib.hin b/newlib/newlib.hin
> > index
> > d03dfac0eea6a8917a92b8f0f3584c2cd42b9388..397bc9b96eafddace3a75be509157040654b6fde
> > 100644
> > --- a/newlib/newlib.hin
> > +++ b/newlib/newlib.hin
> > @@ -82,6 +82,9 @@
> >  /* Define if small footprint nano-formatted-IO implementation used.  */
> >  #undef _NANO_FORMATTED_IO
> >  
> > +/* Define if using retargetable functions for default lock routines.  */
> > +#undef _RETARGETABLE_LOCKING
> > +
> >  /*
> >   * Iconv encodings enabled ("to" direction)
> >   */
> 
> 
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/2, newlib] Allow locking routine to be retargeted
  2017-01-24 16:05 [PATCH 2/2, newlib] Allow locking routine to be retargeted Thomas Preudhomme
  2017-01-25 11:39 ` Corinna Vinschen
@ 2017-01-29 11:19 ` Freddie Chopin
  2017-01-29 17:07   ` Freddie Chopin
  2017-01-29 22:09 ` Freddie Chopin
  2017-01-30 18:53 ` Freddie Chopin
  3 siblings, 1 reply; 19+ messages in thread
From: Freddie Chopin @ 2017-01-29 11:19 UTC (permalink / raw)
  To: newlib

Hello!

After applying this patch to newlib master and _NOT_ enabling the "
--enable-newlib-retargetable-locking" option, I'm seeing a failure
during generation of HTML docs:

--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---

./targetdep.tex:1420: @menu reference to nonexistent node `lock'
stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
sectioning `ecvt' differ
stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
in sectioning `gcvt' differ
stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
sectioning `div' differ
stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
sectioning `ecvtbuf' differ
stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
and in sectioning `ecvt' differ
stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
in sectioning `__env_lock' differ
stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
sectioning `gcvt' differ
stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
and in sectioning `exit' differ
stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
and in sectioning `ecvtbuf' differ
stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
sectioning `__env_lock' differ
stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
`mbsrtowcs' and in sectioning `mblen' differ
stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
sectioning `mbsrtowcs' differ
stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
in sectioning `__malloc_lock' differ
stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
`__malloc_lock' and in sectioning `mblen' differ
stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
and in sectioning `mbtowc' differ
stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
sectioning `mbstowcs' differ
ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
and in sectioning `iswcntrl' differ
ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
and in sectioning `iswblank' differ
ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
and in sectioning `iswalpha' differ
ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
and in sectioning `iswdigit' differ
ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
and in sectioning `iswcntrl' differ
ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
and in sectioning `iswblank' differ
misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
sectioning `__retarget_lock_init' differ
misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
misc/lock.def:1: warning: node `unctrl' is next for
`__retarget_lock_init' in sectioning but not in menu
misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
in sectioning but not in menu
misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
in sectioning but not in menu
./targetdep.tex:1414: node `Misc' lacks menu item for
`__retarget_lock_init' despite being its Up target
misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
sectioning `__retarget_lock_init' differ
reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
in sectioning `_wait_r' differ
reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
in sectioning `_fstat_r' differ
reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
and in sectioning `_fork_r' differ
reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
and in sectioning `_link_r' differ
reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
in sectioning `_wait_r' differ
reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
in sectioning `_fstat_r' differ
reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
in sectioning `_kill_r' differ
reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
in sectioning `_getpid_r' differ
reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
and in sectioning `_sbrk_r' differ
reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
and in sectioning `_stat_r' differ
reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
and in sectioning `_kill_r' differ
reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
in sectioning `_getpid_r' differ
reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
and in sectioning `_write_r' differ
reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
in sectioning `_unlink_r' differ
make[1]: *** [Makefile:561: libc.html] Error 1
make[1]: Leaving directory '/home/freddie/bleeding-edge-
toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
make: *** [Makefile:680: install-html-recursive] Error 1

--- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/2, newlib] Allow locking routine to be retargeted
  2017-01-29 11:19 ` [PATCH 2/2, " Freddie Chopin
@ 2017-01-29 17:07   ` Freddie Chopin
  0 siblings, 0 replies; 19+ messages in thread
From: Freddie Chopin @ 2017-01-29 17:07 UTC (permalink / raw)
  To: newlib

On Sun, 2017-01-29 at 12:19 +0100, Freddie Chopin wrote:
> Hello!
> 
> After applying this patch to newlib master and _NOT_ enabling the "
> --enable-newlib-retargetable-locking" option, I'm seeing a failure
> during generation of HTML docs:
> ...

Hmm... I also see this failure when the option is enabled, so I guess
there must be something wrong with the documentation of these new
functionalities.

Interesting fact - only the build of HTML fails, PDF documentation is
generated fine.

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/2, newlib] Allow locking routine to be retargeted
  2017-01-24 16:05 [PATCH 2/2, newlib] Allow locking routine to be retargeted Thomas Preudhomme
  2017-01-25 11:39 ` Corinna Vinschen
  2017-01-29 11:19 ` [PATCH 2/2, " Freddie Chopin
@ 2017-01-29 22:09 ` Freddie Chopin
  2017-01-30 18:53 ` Freddie Chopin
  3 siblings, 0 replies; 19+ messages in thread
From: Freddie Chopin @ 2017-01-29 22:09 UTC (permalink / raw)
  To: newlib

One more thing - I think the patch should include lock object for
arc4random - either "_arc4random_mutex" (originally) or
"__arc4random_lock_object" (with my change to unify all names).

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/2, newlib] Allow locking routine to be retargeted
  2017-01-24 16:05 [PATCH 2/2, newlib] Allow locking routine to be retargeted Thomas Preudhomme
                   ` (2 preceding siblings ...)
  2017-01-29 22:09 ` Freddie Chopin
@ 2017-01-30 18:53 ` Freddie Chopin
  3 siblings, 0 replies; 19+ messages in thread
From: Freddie Chopin @ 2017-01-30 18:53 UTC (permalink / raw)
  To: newlib

OK, more strangeness...

The idea that a linking error will be produced when you provide an
incomplete retarteging implementation generally works correctly, with
exception of two locks. If I remove the storage for most of the locks,
linking indeed fails with "multiple definitions" error. But this does
not apply to the lock for at_quick_exit() ("__atexit_mutex" or
"__at_quick_exit_mutex") and telldir() ("__dd_hash_lock" or
"__dd_hash_mutex").

1. Why is the lock used by at_quick_exit() not required - I have no
idea. The linking error (when I do not provide storage for this lock)
about multiple definitions is visible only when I actually use the
at_quick_exit() function.

2. It seems that the lock for dd_hash from posix/telldir.c is not
really needed, at least with the newlib configuration which I'm using.
Whole posix/ folder is not compiled at all, so no file from this path
is included in libc.a. Sorry for the earlier confusion.

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-01-25 20:43   ` Jeff Johnston
@ 2017-01-31 17:19     ` Thomas Preudhomme
  2017-02-01  8:43       ` Freddie Chopin
  2017-02-01  9:06       ` Freddie Chopin
  0 siblings, 2 replies; 19+ messages in thread
From: Thomas Preudhomme @ 2017-01-31 17:19 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 24957 bytes --]

Please find an updated patch in attachment in git format-patch format.

Freddie: I have only guarded the dummy lock definition with __SINGLE_THREAD__ 
for simplicity. I did add the lock for arc4random though.

As to your other comments:

 > 1. Why is the lock used by at_quick_exit() not required - I have no
 > idea. The linking error (when I do not provide storage for this lock)
 > about multiple definitions is visible only when I actually use the
 > at_quick_exit() function.

That makes sense. If you don't use at_quick_exit then probably no symbol in the 
corresponding object file is referenced and therefore the file is not linked in. 
That's exactly why the "doubly defined error on missing symbol" work as 
explained in the cover letter: file with dummy symbol is only linked in if it 
solves an undefined reference.

Best regards,

Thomas

On 25/01/17 20:42, Jeff Johnston wrote:
> I am fine with this but I would like to see the struct _lock renamed
> to be struct __lock and the lock names double-underscored to stay out of user
> name space.  After that, it is fine for check-in.
>
> -- Jeff J.
>
> ----- Original Message -----
>> Jeff?
>>
>> On Jan 24 16:05, Thomas Preudhomme wrote:
>>> Hi,
>>>
>>> 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.
>>>
>>> Testing: I've built a simple test program that calls malloc and free with
>>> all the locking function defined in the same file. Running into a debugger
>>> with breakpoints on the function shows that they are indeed called. Newlib
>>> testsuite (the 30 tests that run wich check-target-newlib from GCC) also
>>> comes back clean.
>>>
>>> Is this ok for master branch?
>>>
>>> Best regards,
>>>
>>> Thomas
>>
>>> diff --git a/newlib/configure b/newlib/configure
>>> index
>>> 2ac07fe06bfc795d94ba36d0061e4f8135146125..de28c25b3c4aaeed14b6d0ee8354fdd5c5c3115a
>>> 100755
>>> --- a/newlib/configure
>>> +++ b/newlib/configure
>>> @@ -802,6 +802,7 @@ enable_newlib_nano_malloc
>>>  enable_newlib_unbuf_stream_opt
>>>  enable_lite_exit
>>>  enable_newlib_nano_formatted_io
>>> +enable_newlib_retargetable_locking
>>>  enable_multilib
>>>  enable_target_optspace
>>>  enable_malloc_debugging
>>> @@ -1473,6 +1474,7 @@ Optional Features:
>>>    --disable-newlib-unbuf-stream-opt    disable unbuffered stream
>>>    optimization in streamio
>>>    --enable-lite-exit	enable light weight exit
>>>    --enable-newlib-nano-formatted-io    Use nano version formatted IO
>>> +  --enable-newlib-retargetable-locking    Allow locking routines to be
>>> retargeted at link time
>>>    --enable-multilib         build many library versions (default)
>>>    --enable-target-optspace  optimize for space
>>>    --enable-malloc-debugging indicate malloc debugging requested
>>> @@ -2474,6 +2476,18 @@ else
>>>  fi
>>>
>>>
>>> +# Check whether --enable-newlib-retargetable-locking was given.
>>> +if test "${enable_newlib_retargetable_locking+set}" = set; then :
>>> +  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
>>> +   yes) newlib_retargetable_locking=yes ;;
>>> +   no)  newlib_retargetable_locking=no ;;
>>> +   *) as_fn_error $? "bad value ${enableval} for
>>> newlib-retargetable-locking" "$LINENO" 5 ;;
>>> + esac
>>> +else
>>> +  newlib_retargetable_locking=no
>>> +fi
>>> +
>>> +
>>>
>>>  # Make sure we can run config.sub.
>>>  $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
>>> @@ -11780,7 +11794,7 @@ else
>>>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>>>    lt_status=$lt_dlunknown
>>>    cat > conftest.$ac_ext <<_LT_EOF
>>> -#line 11783 "configure"
>>> +#line 11797 "configure"
>>>  #include "confdefs.h"
>>>
>>>  #if HAVE_DLFCN_H
>>> @@ -11886,7 +11900,7 @@ else
>>>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>>>    lt_status=$lt_dlunknown
>>>    cat > conftest.$ac_ext <<_LT_EOF
>>> -#line 11889 "configure"
>>> +#line 11903 "configure"
>>>  #include "confdefs.h"
>>>
>>>  #if HAVE_DLFCN_H
>>> @@ -12455,6 +12469,13 @@ _ACEOF
>>>
>>>  fi
>>>
>>> +if test "${newlib_retargetable_locking}" = "yes"; then
>>> +cat >>confdefs.h <<_ACEOF
>>> +#define _RETARGETABLE_LOCKING 1
>>> +_ACEOF
>>> +
>>> +fi
>>> +
>>>
>>>  if test "x${iconv_encodings}" != "x" \
>>>     || test "x${iconv_to_encodings}" != "x" \
>>> diff --git a/newlib/configure.in b/newlib/configure.in
>>> index
>>> bfaf038c7f495d32d05ae8caff0172f464895ffe..354c07ca580edf75da59fb858ca2c434e0b1a4e9
>>> 100644
>>> --- a/newlib/configure.in
>>> +++ b/newlib/configure.in
>>> @@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
>>>     *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
>>>   esac],[newlib_nano_formatted_io=no])
>>>
>>> +dnl Support --enable-retargetable-locking
>>> +dnl This option is also read in libc/configure.in.  It is repeated
>>> +dnl here so that it shows up in the help text.
>>> +AC_ARG_ENABLE(newlib-retargetable-locking,
>>> +[  --enable-newlib-retargetable-locking    Allow locking routines to be
>>> retargeted at link time],
>>> +[case "${enableval}" in
>>> +   yes) newlib_retargetable_locking=yes ;;
>>> +   no)  newlib_retargetable_locking=no ;;
>>> +   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking)
>>> ;;
>>> + esac],[newlib_retargetable_locking=no])
>>> +
>>>  NEWLIB_CONFIGURE(.)
>>>
>>>  dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
>>> @@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
>>>  AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
>>>  fi
>>>
>>> +if test "${newlib_retargetable_locking}" = "yes"; then
>>> +AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
>>> +fi
>>> +
>>>  dnl
>>>  dnl Parse --enable-newlib-iconv-encodings option argument
>>>  dnl
>>> diff --git a/newlib/libc/configure b/newlib/libc/configure
>>> index
>>> 4dc4d1bf703f388ecd3b4e0d8bef6786f7995021..dabe44fd98d74a2e029a22a217953dd52575736f
>>> 100755
>>> --- a/newlib/libc/configure
>>> +++ b/newlib/libc/configure
>>> @@ -751,6 +751,8 @@ build
>>>  newlib_basedir
>>>  MAY_SUPPLY_SYSCALLS_FALSE
>>>  MAY_SUPPLY_SYSCALLS_TRUE
>>> +NEWLIB_RETARGETABLE_LOCKING_FALSE
>>> +NEWLIB_RETARGETABLE_LOCKING_TRUE
>>>  NEWLIB_NANO_FORMATTED_IO_FALSE
>>>  NEWLIB_NANO_FORMATTED_IO_TRUE
>>>  target_alias
>>> @@ -797,6 +799,7 @@ enable_option_checking
>>>  enable_newlib_io_pos_args
>>>  enable_newlib_nano_malloc
>>>  enable_newlib_nano_formatted_io
>>> +enable_newlib_retargetable_locking
>>>  enable_multilib
>>>  enable_target_optspace
>>>  enable_malloc_debugging
>>> @@ -1448,6 +1451,7 @@ Optional Features:
>>>    --enable-newlib-io-pos-args enable printf-family positional arg support
>>>    --enable-newlib-nano-malloc    Use small-footprint nano-malloc
>>>    implementation
>>>    --enable-newlib-nano-formatted-io    Use small-footprint
>>>    nano-formatted-IO implementation
>>> +  --enable-newlib-retargetable-locking    Allow locking routines to be
>>> retargeted at link time
>>>    --enable-multilib         build many library versions (default)
>>>    --enable-target-optspace  optimize for space
>>>    --enable-malloc-debugging indicate malloc debugging requested
>>> @@ -2252,6 +2256,26 @@ else
>>>  fi
>>>
>>>
>>> +# Check whether --enable-newlib-retargetable-locking was given.
>>> +if test "${enable_newlib_retargetable_locking+set}" = set; then :
>>> +  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
>>> +   yes) newlib_retargetable_locking=yes ;;
>>> +   no)  newlib_retargetable_lock=no ;;
>>> +   *) as_fn_error $? "bad value ${enableval} for
>>> newlib-retargetable-locking" "$LINENO" 5 ;;
>>> + esac
>>> +else
>>> +  newlib_retargetable_locking=no
>>> +fi
>>> +
>>> + if test x$newlib_retargetable_locking = xyes; then
>>> +  NEWLIB_RETARGETABLE_LOCKING_TRUE=
>>> +  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
>>> +else
>>> +  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
>>> +  NEWLIB_RETARGETABLE_LOCKING_FALSE=
>>> +fi
>>> +
>>> +
>>>
>>>  # Make sure we can run config.sub.
>>>  $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
>>> @@ -11525,7 +11549,7 @@ else
>>>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>>>    lt_status=$lt_dlunknown
>>>    cat > conftest.$ac_ext <<_LT_EOF
>>> -#line 11528 "configure"
>>> +#line 11552 "configure"
>>>  #include "confdefs.h"
>>>
>>>  #if HAVE_DLFCN_H
>>> @@ -11631,7 +11655,7 @@ else
>>>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>>>    lt_status=$lt_dlunknown
>>>    cat > conftest.$ac_ext <<_LT_EOF
>>> -#line 11634 "configure"
>>> +#line 11658 "configure"
>>>  #include "confdefs.h"
>>>
>>>  #if HAVE_DLFCN_H
>>> @@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" &&
>>> test -z "${NEWLIB_NANO_FORMATTE
>>>    as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never
>>>    defined.
>>>  Usually this means the macro was only invoked conditionally." "$LINENO" 5
>>>  fi
>>> +if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z
>>> "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
>>> +  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never
>>> defined.
>>> +Usually this means the macro was only invoked conditionally." "$LINENO" 5
>>> +fi
>>>  if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z
>>>  "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
>>>    as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
>>>  Usually this means the macro was only invoked conditionally." "$LINENO" 5
>>> diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
>>> index
>>> 0a7bb8815be44fb1e92f753fa2c8df2a31b95f94..ac25a3933c4a4794f3cfe291e0275d0ed001b96a
>>> 100644
>>> --- a/newlib/libc/configure.in
>>> +++ b/newlib/libc/configure.in
>>> @@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
>>>   esac],[newlib_nano_formatted_io=no])
>>>  AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io =
>>>  xyes)
>>>
>>> +dnl Support --enable-retargetable-locking used by libc/sys
>>> +AC_ARG_ENABLE(newlib-retargetable-locking,
>>> +[  --enable-newlib-retargetable-locking    Allow locking routines to be
>>> retargeted at link time],
>>> +[case "${enableval}" in
>>> +   yes) newlib_retargetable_locking=yes ;;
>>> +   no)  newlib_retargetable_lock=no ;;
>>> +   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking)
>>> ;;
>>> + esac],[newlib_retargetable_locking=no])
>>> +AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test
>>> x$newlib_retargetable_locking = xyes)
>>> +
>>>  NEWLIB_CONFIGURE(..)
>>>
>>>  AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
>>> diff --git a/newlib/libc/include/sys/lock.h
>>> b/newlib/libc/include/sys/lock.h
>>> index
>>> 9075e35c9179968031010432515e3a845ff6ca8d..9a8e2528c79a89d5807da8c4bb0e65151870bf42
>>> 100644
>>> --- a/newlib/libc/include/sys/lock.h
>>> +++ b/newlib/libc/include/sys/lock.h
>>> @@ -3,10 +3,13 @@
>>>
>>>  /* dummy lock routines for single-threaded aps */
>>>
>>> +#include <newlib.h>
>>> +#include <_ansi.h>
>>> +
>>> +#ifndef _RETARGETABLE_LOCKING
>>> +
>>>  typedef int _LOCK_T;
>>>  typedef int _LOCK_RECURSIVE_T;
>>> -
>>> -#include <_ansi.h>
>>>
>>>  #define __LOCK_INIT(class,lock) static int lock = 0;
>>>  #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
>>> @@ -21,4 +24,46 @@ typedef int _LOCK_RECURSIVE_T;
>>>  #define __lock_release(lock) (_CAST_VOID 0)
>>>  #define __lock_release_recursive(lock) (_CAST_VOID 0)
>>>
>>> +#else
>>> +
>>> +#ifdef __cplusplus
>>> +extern "C" {
>>> +#endif
>>> +
>>> +struct _lock;
>>> +typedef struct _lock * _LOCK_T;
>>> +#define _LOCK_RECURSIVE_T _LOCK_T
>>> +
>>> +#define __LOCK_INIT(class,lock) extern struct _lock _lock_ ## lock; \
>>> +	class _LOCK_T lock = &_lock_ ## lock
>>> +#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
>>> +
>>> +extern void __retarget_lock_init(_LOCK_T *lock);
>>> +#define __lock_init(lock) __retarget_lock_init(&lock)
>>> +extern void __retarget_lock_init_recursive(_LOCK_T *lock);
>>> +#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
>>> +extern void __retarget_lock_close(_LOCK_T lock);
>>> +#define __lock_close(lock) __retarget_lock_close(lock)
>>> +extern void __retarget_lock_close_recursive(_LOCK_T lock);
>>> +#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
>>> +extern void __retarget_lock_acquire(_LOCK_T lock);
>>> +#define __lock_acquire(lock) __retarget_lock_acquire(lock)
>>> +extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
>>> +#define __lock_acquire_recursive(lock)
>>> __retarget_lock_acquire_recursive(lock)
>>> +extern int __retarget_lock_try_acquire(_LOCK_T lock);
>>> +#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
>>> +extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
>>> +#define __lock_try_acquire_recursive(lock) \
>>> +  __retarget_lock_try_acquire_recursive(lock)
>>> +extern void __retarget_lock_release(_LOCK_T lock);
>>> +#define __lock_release(lock) __retarget_lock_release(lock)
>>> +extern void __retarget_lock_release_recursive(_LOCK_T lock);
>>> +#define __lock_release_recursive(lock)
>>> __retarget_lock_release_recursive(lock)
>>> +
>>> +#ifdef __cplusplus
>>> +}
>>> +#endif
>>> +
>>> +#endif /* _RETARGETABLE_LOCKING */
>>> +
>>>  #endif /* __SYS_LOCK_H__ */
>>> diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
>>> index
>>> 3fe8e55f53ca87ba55f3a676b213e55fa66e77aa..7571ef26335c053315ad3f3df428a4742a9cf368
>>> 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
>>> 0ada8de34e7a3a6084dbab4bfa7caf8cb7f8d8f3..e7925231c203897d917f41accf6560e3336895bc
>>> 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
>>> 0000000000000000000000000000000000000000..1c69575b33f666c8170c2fe8473ad428f2741137
>>> --- /dev/null
>>> +++ b/newlib/libc/misc/lock.c
>>> @@ -0,0 +1,149 @@
>>> +/*
>>> +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_lock
>>> +INDEX
>>> +	_lock___sfp_lock
>>> +INDEX
>>> +	_lock___atexit_lock
>>> +INDEX
>>> +	_lock___atexit_mutex
>>> +INDEX
>>> +	_lock___malloc_lock_object
>>> +INDEX
>>> +	_lock___env_lock_object
>>> +INDEX
>>> +	_lock___tz_lock_object
>>> +INDEX
>>> +	_lock___dd_hash_lock
>>> +
>>> +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_lock;
>>> +	struct _lock _lock___sfp_lock;
>>> +	struct _lock _lock___atexit_lock;
>>> +	struct _lock _lock___atexit_mutex;
>>> +	struct _lock _lock___malloc_lock_object;
>>> +	struct _lock _lock___env_lock_object;
>>> +	struct _lock _lock___tz_lock_object;
>>> +	struct _lock _lock___dd_hash_lock;
>>> +
>>> +	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 */
>>> +
>>> +#include <sys/lock.h>
>>> +
>>> +struct _lock {
>>> +  char unused;
>>> +};
>>> +
>>> +struct _lock _lock___sinit_lock;
>>> +struct _lock _lock___sfp_lock;
>>> +struct _lock _lock___atexit_lock;
>>> +struct _lock _lock___atexit_mutex;
>>> +struct _lock _lock___malloc_lock_object;
>>> +struct _lock _lock___env_lock_object;
>>> +struct _lock _lock___tz_lock_object;
>>> +struct _lock _lock___dd_hash_lock;
>>> +
>>> +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)
>>> +{
>>> +}
>>> diff --git a/newlib/libc/misc/misc.tex b/newlib/libc/misc/misc.tex
>>> index
>>> 22c313eb15c7676443ff4c928c8c76cc038f3f0f..6afd1be5c4a1e90ffd64881c63c5132e144ad364
>>> 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
>>> +* lock::     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
>>> diff --git a/newlib/newlib.hin b/newlib/newlib.hin
>>> index
>>> d03dfac0eea6a8917a92b8f0f3584c2cd42b9388..397bc9b96eafddace3a75be509157040654b6fde
>>> 100644
>>> --- a/newlib/newlib.hin
>>> +++ b/newlib/newlib.hin
>>> @@ -82,6 +82,9 @@
>>>  /* Define if small footprint nano-formatted-IO implementation used.  */
>>>  #undef _NANO_FORMATTED_IO
>>>
>>> +/* Define if using retargetable functions for default lock routines.  */
>>> +#undef _RETARGETABLE_LOCKING
>>> +
>>>  /*
>>>   * Iconv encodings enabled ("to" direction)
>>>   */
>>
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat
>>

[-- Attachment #2: newlib_retargetable_locking_routine.patch --]
[-- Type: text/x-patch, Size: 21212 bytes --]

From e258b516753336eba73828e5627c3aa7c8491eae Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date: Tue, 25 Oct 2016 17:38:19 +0100
Subject: [PATCH 2/2] 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.
---
 newlib/configure               |  25 ++++++-
 newlib/configure.in            |  15 ++++
 newlib/libc/configure          |  32 ++++++++-
 newlib/libc/configure.in       |  10 +++
 newlib/libc/include/sys/lock.h |  49 ++++++++++++-
 newlib/libc/misc/Makefile.am   |   7 +-
 newlib/libc/misc/Makefile.in   |  28 ++++++--
 newlib/libc/misc/lock.c        | 155 +++++++++++++++++++++++++++++++++++++++++
 newlib/libc/misc/misc.tex      |   4 ++
 newlib/newlib.hin              |   3 +
 10 files changed, 314 insertions(+), 14 deletions(-)
 create mode 100644 newlib/libc/misc/lock.c

diff --git a/newlib/configure b/newlib/configure
index 2ac07fe..de28c25 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -802,6 +802,7 @@ enable_newlib_nano_malloc
 enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1473,6 +1474,7 @@ Optional Features:
   --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2474,6 +2476,18 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11780,7 +11794,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11783 "configure"
+#line 11797 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11886,7 +11900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11889 "configure"
+#line 11903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12455,6 +12469,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _RETARGETABLE_LOCKING 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index bfaf038..354c07c 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
  esac],[newlib_nano_formatted_io=no])
 
+dnl Support --enable-retargetable-locking
+dnl This option is also read in libc/configure.in.  It is repeated
+dnl here so that it shows up in the help text.
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
 AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/configure b/newlib/libc/configure
index 4dc4d1b..dabe44f 100755
--- a/newlib/libc/configure
+++ b/newlib/libc/configure
@@ -751,6 +751,8 @@ build
 newlib_basedir
 MAY_SUPPLY_SYSCALLS_FALSE
 MAY_SUPPLY_SYSCALLS_TRUE
+NEWLIB_RETARGETABLE_LOCKING_FALSE
+NEWLIB_RETARGETABLE_LOCKING_TRUE
 NEWLIB_NANO_FORMATTED_IO_FALSE
 NEWLIB_NANO_FORMATTED_IO_TRUE
 target_alias
@@ -797,6 +799,7 @@ enable_option_checking
 enable_newlib_io_pos_args
 enable_newlib_nano_malloc
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1448,6 +1451,7 @@ Optional Features:
   --enable-newlib-io-pos-args enable printf-family positional arg support
   --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
   --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2252,6 +2256,26 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+ if test x$newlib_retargetable_locking = xyes; then
+  NEWLIB_RETARGETABLE_LOCKING_TRUE=
+  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
+else
+  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
+  NEWLIB_RETARGETABLE_LOCKING_FALSE=
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11525,7 +11549,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11528 "configure"
+#line 11552 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11631,7 +11655,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11634 "configure"
+#line 11658 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
   as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
+  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
   as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
index 0a7bb88..ac25a39 100644
--- a/newlib/libc/configure.in
+++ b/newlib/libc/configure.in
@@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
  esac],[newlib_nano_formatted_io=no])
 AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
 
+dnl Support --enable-retargetable-locking used by libc/sys
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
+
 NEWLIB_CONFIGURE(..)
 
 AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
index a406ec7..130fbbf 100644
--- a/newlib/libc/include/sys/lock.h
+++ b/newlib/libc/include/sys/lock.h
@@ -3,10 +3,13 @@
 
 /* dummy lock routines for single-threaded aps */
 
+#include <newlib.h>
+#include <_ansi.h>
+
+#if defined(__SINGLE_THREAD__) || !defined(_RETARGETABLE_LOCKING)
+
 typedef int _LOCK_T;
 typedef int _LOCK_RECURSIVE_T;
- 
-#include <_ansi.h>
 
 #ifdef __SINGLE_THREAD__
 #define __LOCK_INIT(class,lock) ;
@@ -27,4 +30,46 @@ typedef int _LOCK_RECURSIVE_T;
 #define __lock_release(lock) (_CAST_VOID 0)
 #define __lock_release_recursive(lock) (_CAST_VOID 0)
 
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct __lock;
+typedef struct __lock * _LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+#define __LOCK_INIT(class,lock) extern struct __lock __lock_ ## lock; \
+	class _LOCK_T lock = &__lock_ ## lock
+#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
+
+extern void __retarget_lock_init(_LOCK_T *lock);
+#define __lock_init(lock) __retarget_lock_init(&lock)
+extern void __retarget_lock_init_recursive(_LOCK_T *lock);
+#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
+extern void __retarget_lock_close(_LOCK_T lock);
+#define __lock_close(lock) __retarget_lock_close(lock)
+extern void __retarget_lock_close_recursive(_LOCK_T lock);
+#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
+extern void __retarget_lock_acquire(_LOCK_T lock);
+#define __lock_acquire(lock) __retarget_lock_acquire(lock)
+extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
+#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
+extern int __retarget_lock_try_acquire(_LOCK_T lock);
+#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
+extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
+#define __lock_try_acquire_recursive(lock) \
+  __retarget_lock_try_acquire_recursive(lock)
+extern void __retarget_lock_release(_LOCK_T lock);
+#define __lock_release(lock) __retarget_lock_release(lock)
+extern void __retarget_lock_release_recursive(_LOCK_T lock);
+#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(__SINGLE_THREAD__) && defined(_RETARGETABLE_LOCKING) */
+
 #endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
index 3fe8e55..7571ef2 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 0ada8de..e792523 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 0000000..dfb4eb4
--- /dev/null
+++ b/newlib/libc/misc/lock.c
@@ -0,0 +1,155 @@
+/*
+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_lock
+INDEX
+	_lock___sfp_lock
+INDEX
+	_lock___atexit_lock
+INDEX
+	_lock___atexit_mutex
+INDEX
+	_lock___malloc_lock_object
+INDEX
+	_lock___env_lock_object
+INDEX
+	_lock___tz_lock_object
+INDEX
+	_lock___dd_hash_lock
+
+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 22c313e..6afd1be 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
+* lock::     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
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index d03dfac..397bc9b 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -82,6 +82,9 @@
 /* Define if small footprint nano-formatted-IO implementation used.  */
 #undef _NANO_FORMATTED_IO
 
+/* Define if using retargetable functions for default lock routines.  */
+#undef _RETARGETABLE_LOCKING
+
 /*
  * Iconv encodings enabled ("to" direction)
  */
-- 
1.9.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-01-31 17:19     ` [PATCH 3/3, " Thomas Preudhomme
@ 2017-02-01  8:43       ` Freddie Chopin
  2017-02-02 10:21         ` Thomas Preudhomme
  2017-02-01  9:06       ` Freddie Chopin
  1 sibling, 1 reply; 19+ messages in thread
From: Freddie Chopin @ 2017-02-01  8:43 UTC (permalink / raw)
  To: newlib

Hi!

With all relevant 3 patches applied the toolchain builds and works
fine, but the issue with HTML documentation still persists - at least
here on Arch Linux:

--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---

make[2]: Entering directory '/home/freddie/bleeding-edge-
toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
for chapter in  ; \
do \
  cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
2.5.0/newlib/libc/syscalls/$chapter >> /home/freddie/bleeding-edge-
toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/tmp-
targetdep.texi ; \
done
make[2]: Leaving directory '/home/freddie/bleeding-edge-
toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
2.5.0/newlib/libc/sys.tex >>tmp-targetdep.texi
/bin/sh /home/freddie/bleeding-edge-toolchain/sources/newlib-
2.5.0/newlib/libc/../../move-if-change tmp-targetdep.texi targetdep.tex
touch stmp-targetdep
rm -rf libc.htp
if makeinfo --split-size=5000000 --html   -I /home/freddie/bleeding-
edge-toolchain/sources/newlib-2.5.0/newlib/libc \
 -o libc.htp /home/freddie/bleeding-edge-toolchain/sources/newlib-
2.5.0/newlib/libc/libc.texinfo; \
then \
  rm -rf libc.html; \
  if test ! -d libc.htp && test -d libc; then \
    mv libc libc.html; else mv libc.htp libc.html; fi; \
else \
  if test ! -d libc.htp && test -d libc; then \
    rm -rf libc; else rm -Rf libc.htp libc.html; fi; \
  exit 1; \
fi
./targetdep.tex:1420: @menu reference to nonexistent node `lock'
stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
sectioning `ecvt' differ
stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
in sectioning `gcvt' differ
stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
sectioning `div' differ
stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
sectioning `ecvtbuf' differ
stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
and in sectioning `ecvt' differ
stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
in sectioning `__env_lock' differ
stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
sectioning `gcvt' differ
stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
and in sectioning `exit' differ
stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
and in sectioning `ecvtbuf' differ
stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
sectioning `__env_lock' differ
stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
`mbsrtowcs' and in sectioning `mblen' differ
stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
sectioning `mbsrtowcs' differ
stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
in sectioning `__malloc_lock' differ
stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
`__malloc_lock' and in sectioning `mblen' differ
stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
and in sectioning `mbtowc' differ
stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
sectioning `mbstowcs' differ
ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
and in sectioning `iswcntrl' differ
ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
and in sectioning `iswblank' differ
ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
and in sectioning `iswalpha' differ
ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
and in sectioning `iswdigit' differ
ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
and in sectioning `iswcntrl' differ
ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
and in sectioning `iswblank' differ
misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
sectioning `__retarget_lock_init' differ
misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
misc/lock.def:1: warning: node `unctrl' is next for
`__retarget_lock_init' in sectioning but not in menu
misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
in sectioning but not in menu
misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
in sectioning but not in menu
./targetdep.tex:1414: node `Misc' lacks menu item for
`__retarget_lock_init' despite being its Up target
misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
sectioning `__retarget_lock_init' differ
reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
in sectioning `_wait_r' differ
reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
in sectioning `_fstat_r' differ
reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
and in sectioning `_fork_r' differ
reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
and in sectioning `_link_r' differ
reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
in sectioning `_wait_r' differ
reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
in sectioning `_fstat_r' differ
reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
in sectioning `_kill_r' differ
reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
in sectioning `_getpid_r' differ
reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
and in sectioning `_sbrk_r' differ
reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
and in sectioning `_stat_r' differ
reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
and in sectioning `_kill_r' differ
reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
in sectioning `_getpid_r' differ
reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
and in sectioning `_write_r' differ
reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
in sectioning `_unlink_r' differ
make[1]: *** [Makefile:561: libc.html] Error 1
make[1]: Leaving directory '/home/freddie/bleeding-edge-
toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
make: *** [Makefile:680: install-html-recursive] Error 1

--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-01-31 17:19     ` [PATCH 3/3, " Thomas Preudhomme
  2017-02-01  8:43       ` Freddie Chopin
@ 2017-02-01  9:06       ` Freddie Chopin
  2017-02-02 10:21         ` Thomas Preudhomme
  1 sibling, 1 reply; 19+ messages in thread
From: Freddie Chopin @ 2017-02-01  9:06 UTC (permalink / raw)
  To: newlib

On Tue, 2017-01-31 at 17:19 +0000, Thomas Preudhomme wrote:
>  > 1. Why is the lock used by at_quick_exit() not required - I have
> no
>  > idea. The linking error (when I do not provide storage for this
> lock)
>  > about multiple definitions is visible only when I actually use the
>  > at_quick_exit() function.
> 
> That makes sense. If you don't use at_quick_exit then probably no
> symbol in the 
> corresponding object file is referenced and therefore the file is not
> linked in. 
> That's exactly why the "doubly defined error on missing symbol" work
> as 
> explained in the cover letter: file with dummy symbol is only linked
> in if it 
> solves an undefined reference.

This case seems a bit different, as it applies only to the
at_quick_exit() lock. In my code I have no references to "env" or "tz"
locks either, but I cannot drop these objects without the "multiple
definitions" error. Maybe my test is flawed, but browsing the assembly
output does not show any uses of __tz_lock(), __tz_unlock(),
__env_lock() or __env_unlock() functions (which are not present in the
output file), and these are the only places of newlib which use this
particular locks. I'll try later with a simpler project.

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-01  8:43       ` Freddie Chopin
@ 2017-02-02 10:21         ` Thomas Preudhomme
  2017-02-02 16:16           ` Freddie Chopin
                             ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Thomas Preudhomme @ 2017-02-02 10:21 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 6670 bytes --]

Ooops, forgot about this. Please find an updated patch attached.

Best regards,

Thomas

On 01/02/17 08:43, Freddie Chopin wrote:
> Hi!
>
> With all relevant 3 patches applied the toolchain builds and works
> fine, but the issue with HTML documentation still persists - at least
> here on Arch Linux:
>
> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
>
> make[2]: Entering directory '/home/freddie/bleeding-edge-
> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
> for chapter in  ; \
> do \
>   cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
> 2.5.0/newlib/libc/syscalls/$chapter >> /home/freddie/bleeding-edge-
> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/tmp-
> targetdep.texi ; \
> done
> make[2]: Leaving directory '/home/freddie/bleeding-edge-
> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
> cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
> 2.5.0/newlib/libc/sys.tex >>tmp-targetdep.texi
> /bin/sh /home/freddie/bleeding-edge-toolchain/sources/newlib-
> 2.5.0/newlib/libc/../../move-if-change tmp-targetdep.texi targetdep.tex
> touch stmp-targetdep
> rm -rf libc.htp
> if makeinfo --split-size=5000000 --html   -I /home/freddie/bleeding-
> edge-toolchain/sources/newlib-2.5.0/newlib/libc \
>  -o libc.htp /home/freddie/bleeding-edge-toolchain/sources/newlib-
> 2.5.0/newlib/libc/libc.texinfo; \
> then \
>   rm -rf libc.html; \
>   if test ! -d libc.htp && test -d libc; then \
>     mv libc libc.html; else mv libc.htp libc.html; fi; \
> else \
>   if test ! -d libc.htp && test -d libc; then \
>     rm -rf libc; else rm -Rf libc.htp libc.html; fi; \
>   exit 1; \
> fi
> ./targetdep.tex:1420: @menu reference to nonexistent node `lock'
> stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
> sectioning `ecvt' differ
> stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
> in sectioning `gcvt' differ
> stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
> sectioning `div' differ
> stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
> sectioning `ecvtbuf' differ
> stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
> and in sectioning `ecvt' differ
> stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
> in sectioning `__env_lock' differ
> stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
> sectioning `gcvt' differ
> stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
> and in sectioning `exit' differ
> stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
> and in sectioning `ecvtbuf' differ
> stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
> sectioning `__env_lock' differ
> stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
> `mbsrtowcs' and in sectioning `mblen' differ
> stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
> sectioning `mbsrtowcs' differ
> stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
> in sectioning `__malloc_lock' differ
> stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
> `__malloc_lock' and in sectioning `mblen' differ
> stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
> and in sectioning `mbtowc' differ
> stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
> sectioning `mbstowcs' differ
> ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
> and in sectioning `iswcntrl' differ
> ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
> and in sectioning `iswblank' differ
> ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
> and in sectioning `iswalpha' differ
> ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
> and in sectioning `iswdigit' differ
> ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
> and in sectioning `iswcntrl' differ
> ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
> and in sectioning `iswblank' differ
> misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
> sectioning `__retarget_lock_init' differ
> misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
> misc/lock.def:1: warning: node `unctrl' is next for
> `__retarget_lock_init' in sectioning but not in menu
> misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
> in sectioning but not in menu
> misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
> in sectioning but not in menu
> ./targetdep.tex:1414: node `Misc' lacks menu item for
> `__retarget_lock_init' despite being its Up target
> misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
> sectioning `__retarget_lock_init' differ
> reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
> in sectioning `_wait_r' differ
> reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
> in sectioning `_fstat_r' differ
> reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
> and in sectioning `_fork_r' differ
> reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
> and in sectioning `_link_r' differ
> reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
> in sectioning `_wait_r' differ
> reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
> in sectioning `_fstat_r' differ
> reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
> in sectioning `_kill_r' differ
> reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
> in sectioning `_getpid_r' differ
> reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
> and in sectioning `_sbrk_r' differ
> reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
> and in sectioning `_stat_r' differ
> reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
> and in sectioning `_kill_r' differ
> reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
> in sectioning `_getpid_r' differ
> reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
> and in sectioning `_write_r' differ
> reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
> in sectioning `_unlink_r' differ
> make[1]: *** [Makefile:561: libc.html] Error 1
> make[1]: Leaving directory '/home/freddie/bleeding-edge-
> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
> make: *** [Makefile:680: install-html-recursive] Error 1
>
> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
>
> Regards,
> FCh
>

[-- Attachment #2: newlib_retargetable_locking_routine.patch --]
[-- Type: text/x-patch, Size: 21224 bytes --]

From 978f6c48d248f33ea21d1693a91b05ca748c2a8b Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date: Tue, 25 Oct 2016 17:38:19 +0100
Subject: [PATCH] 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.
---
 newlib/configure               |  25 ++++++-
 newlib/configure.in            |  15 ++++
 newlib/libc/configure          |  32 ++++++++-
 newlib/libc/configure.in       |  10 +++
 newlib/libc/include/sys/lock.h |  49 ++++++++++++-
 newlib/libc/misc/Makefile.am   |   7 +-
 newlib/libc/misc/Makefile.in   |  28 ++++++--
 newlib/libc/misc/lock.c        | 155 +++++++++++++++++++++++++++++++++++++++++
 newlib/libc/misc/misc.tex      |   4 ++
 newlib/newlib.hin              |   3 +
 10 files changed, 314 insertions(+), 14 deletions(-)
 create mode 100644 newlib/libc/misc/lock.c

diff --git a/newlib/configure b/newlib/configure
index 2ac07fe..de28c25 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -802,6 +802,7 @@ enable_newlib_nano_malloc
 enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1473,6 +1474,7 @@ Optional Features:
   --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2474,6 +2476,18 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11780,7 +11794,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11783 "configure"
+#line 11797 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11886,7 +11900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11889 "configure"
+#line 11903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12455,6 +12469,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _RETARGETABLE_LOCKING 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index bfaf038..354c07c 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
  esac],[newlib_nano_formatted_io=no])
 
+dnl Support --enable-retargetable-locking
+dnl This option is also read in libc/configure.in.  It is repeated
+dnl here so that it shows up in the help text.
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
 AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/configure b/newlib/libc/configure
index 4dc4d1b..dabe44f 100755
--- a/newlib/libc/configure
+++ b/newlib/libc/configure
@@ -751,6 +751,8 @@ build
 newlib_basedir
 MAY_SUPPLY_SYSCALLS_FALSE
 MAY_SUPPLY_SYSCALLS_TRUE
+NEWLIB_RETARGETABLE_LOCKING_FALSE
+NEWLIB_RETARGETABLE_LOCKING_TRUE
 NEWLIB_NANO_FORMATTED_IO_FALSE
 NEWLIB_NANO_FORMATTED_IO_TRUE
 target_alias
@@ -797,6 +799,7 @@ enable_option_checking
 enable_newlib_io_pos_args
 enable_newlib_nano_malloc
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1448,6 +1451,7 @@ Optional Features:
   --enable-newlib-io-pos-args enable printf-family positional arg support
   --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
   --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2252,6 +2256,26 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+ if test x$newlib_retargetable_locking = xyes; then
+  NEWLIB_RETARGETABLE_LOCKING_TRUE=
+  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
+else
+  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
+  NEWLIB_RETARGETABLE_LOCKING_FALSE=
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11525,7 +11549,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11528 "configure"
+#line 11552 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11631,7 +11655,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11634 "configure"
+#line 11658 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
   as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
+  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
   as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
index 0a7bb88..ac25a39 100644
--- a/newlib/libc/configure.in
+++ b/newlib/libc/configure.in
@@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
  esac],[newlib_nano_formatted_io=no])
 AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
 
+dnl Support --enable-retargetable-locking used by libc/sys
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
+
 NEWLIB_CONFIGURE(..)
 
 AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
index a406ec7..130fbbf 100644
--- a/newlib/libc/include/sys/lock.h
+++ b/newlib/libc/include/sys/lock.h
@@ -3,10 +3,13 @@
 
 /* dummy lock routines for single-threaded aps */
 
+#include <newlib.h>
+#include <_ansi.h>
+
+#if defined(__SINGLE_THREAD__) || !defined(_RETARGETABLE_LOCKING)
+
 typedef int _LOCK_T;
 typedef int _LOCK_RECURSIVE_T;
- 
-#include <_ansi.h>
 
 #ifdef __SINGLE_THREAD__
 #define __LOCK_INIT(class,lock) ;
@@ -27,4 +30,46 @@ typedef int _LOCK_RECURSIVE_T;
 #define __lock_release(lock) (_CAST_VOID 0)
 #define __lock_release_recursive(lock) (_CAST_VOID 0)
 
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct __lock;
+typedef struct __lock * _LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+#define __LOCK_INIT(class,lock) extern struct __lock __lock_ ## lock; \
+	class _LOCK_T lock = &__lock_ ## lock
+#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
+
+extern void __retarget_lock_init(_LOCK_T *lock);
+#define __lock_init(lock) __retarget_lock_init(&lock)
+extern void __retarget_lock_init_recursive(_LOCK_T *lock);
+#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
+extern void __retarget_lock_close(_LOCK_T lock);
+#define __lock_close(lock) __retarget_lock_close(lock)
+extern void __retarget_lock_close_recursive(_LOCK_T lock);
+#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
+extern void __retarget_lock_acquire(_LOCK_T lock);
+#define __lock_acquire(lock) __retarget_lock_acquire(lock)
+extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
+#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
+extern int __retarget_lock_try_acquire(_LOCK_T lock);
+#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
+extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
+#define __lock_try_acquire_recursive(lock) \
+  __retarget_lock_try_acquire_recursive(lock)
+extern void __retarget_lock_release(_LOCK_T lock);
+#define __lock_release(lock) __retarget_lock_release(lock)
+extern void __retarget_lock_release_recursive(_LOCK_T lock);
+#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(__SINGLE_THREAD__) && defined(_RETARGETABLE_LOCKING) */
+
 #endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
index 3fe8e55..7571ef2 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 0ada8de..e792523 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 0000000..dfb4eb4
--- /dev/null
+++ b/newlib/libc/misc/lock.c
@@ -0,0 +1,155 @@
+/*
+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_lock
+INDEX
+	_lock___sfp_lock
+INDEX
+	_lock___atexit_lock
+INDEX
+	_lock___atexit_mutex
+INDEX
+	_lock___malloc_lock_object
+INDEX
+	_lock___env_lock_object
+INDEX
+	_lock___tz_lock_object
+INDEX
+	_lock___dd_hash_lock
+
+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 22c313e..248243b 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
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index d03dfac..397bc9b 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -82,6 +82,9 @@
 /* Define if small footprint nano-formatted-IO implementation used.  */
 #undef _NANO_FORMATTED_IO
 
+/* Define if using retargetable functions for default lock routines.  */
+#undef _RETARGETABLE_LOCKING
+
 /*
  * Iconv encodings enabled ("to" direction)
  */
-- 
1.9.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-01  9:06       ` Freddie Chopin
@ 2017-02-02 10:21         ` Thomas Preudhomme
  0 siblings, 0 replies; 19+ messages in thread
From: Thomas Preudhomme @ 2017-02-02 10:21 UTC (permalink / raw)
  To: newlib



On 01/02/17 09:06, Freddie Chopin wrote:
> On Tue, 2017-01-31 at 17:19 +0000, Thomas Preudhomme wrote:
>>  > 1. Why is the lock used by at_quick_exit() not required - I have
>> no
>>  > idea. The linking error (when I do not provide storage for this
>> lock)
>>  > about multiple definitions is visible only when I actually use the
>>  > at_quick_exit() function.
>>
>> That makes sense. If you don't use at_quick_exit then probably no
>> symbol in the
>> corresponding object file is referenced and therefore the file is not
>> linked in.
>> That's exactly why the "doubly defined error on missing symbol" work
>> as
>> explained in the cover letter: file with dummy symbol is only linked
>> in if it
>> solves an undefined reference.
>
> This case seems a bit different, as it applies only to the
> at_quick_exit() lock. In my code I have no references to "env" or "tz"
> locks either, but I cannot drop these objects without the "multiple
> definitions" error. Maybe my test is flawed, but browsing the assembly
> output does not show any uses of __tz_lock(), __tz_unlock(),
> __env_lock() or __env_unlock() functions (which are not present in the
> output file), and these are the only places of newlib which use this
> particular locks. I'll try later with a simpler project.

Your code don't need to reference the env or tz lock directly for them to be 
linked in. The linker does a transitive closure of files until all references 
are resolved. So you code could reference a function a() present in a file A.o 
with that file containing references to function b() in file B.o which contains 
reference to tz_lock in file tz_lock.o which also contains the tz_mutex lock.

If you show me a small testcase where tz_lock or the env lock cannot be removed 
I can tell you why does the error happens.

Best regards,

Thomas

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-02 10:21         ` Thomas Preudhomme
@ 2017-02-02 16:16           ` Freddie Chopin
  2017-02-02 16:25             ` Freddie Chopin
  2017-02-02 23:24           ` Freddie Chopin
  2017-02-07 21:36           ` Jeff Johnston
  2 siblings, 1 reply; 19+ messages in thread
From: Freddie Chopin @ 2017-02-02 16:16 UTC (permalink / raw)
  To: newlib

On Thu, 2017-02-02 at 10:21 +0000, Thomas Preudhomme wrote:
> Ooops, forgot about this. Please find an updated patch attached.

Unfortunately it still fails:

--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---

./targetdep.tex:1420: @menu reference to nonexistent node `lock'
stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
sectioning `ecvt' differ
stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
in sectioning `gcvt' differ
stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
sectioning `div' differ
stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
sectioning `ecvtbuf' differ
stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
and in sectioning `ecvt' differ
stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
in sectioning `__env_lock' differ
stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
sectioning `gcvt' differ
stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
and in sectioning `exit' differ
stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
and in sectioning `ecvtbuf' differ
stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
sectioning `__env_lock' differ
stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
`mbsrtowcs' and in sectioning `mblen' differ
stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
sectioning `mbsrtowcs' differ
stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
in sectioning `__malloc_lock' differ
stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
`__malloc_lock' and in sectioning `mblen' differ
stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
and in sectioning `mbtowc' differ
stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
sectioning `mbstowcs' differ
ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
and in sectioning `iswcntrl' differ
ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
and in sectioning `iswblank' differ
ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
and in sectioning `iswalpha' differ
ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
and in sectioning `iswdigit' differ
ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
and in sectioning `iswcntrl' differ
ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
and in sectioning `iswblank' differ
misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
sectioning `__retarget_lock_init' differ
misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
misc/lock.def:1: warning: node `unctrl' is next for
`__retarget_lock_init' in sectioning but not in menu
misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
in sectioning but not in menu
misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
in sectioning but not in menu
./targetdep.tex:1414: node `Misc' lacks menu item for
`__retarget_lock_init' despite being its Up target
misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
sectioning `__retarget_lock_init' differ
reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
in sectioning `_wait_r' differ
reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
in sectioning `_fstat_r' differ
reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
and in sectioning `_fork_r' differ
reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
and in sectioning `_link_r' differ
reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
in sectioning `_wait_r' differ
reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
in sectioning `_fstat_r' differ
reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
in sectioning `_kill_r' differ
reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
in sectioning `_getpid_r' differ
reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
and in sectioning `_sbrk_r' differ
reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
and in sectioning `_stat_r' differ
reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
and in sectioning `_kill_r' differ
reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
in sectioning `_getpid_r' differ
reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
and in sectioning `_write_r' differ
reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
in sectioning `_unlink_r' differ
make[1]: *** [Makefile:561: libc.html] Error 1
make[1]: Leaving directory '/home/freddie/bleeding-edge-
toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
make: *** [Makefile:680: install-html-recursive] Error 1

--- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-02 16:16           ` Freddie Chopin
@ 2017-02-02 16:25             ` Freddie Chopin
  0 siblings, 0 replies; 19+ messages in thread
From: Freddie Chopin @ 2017-02-02 16:25 UTC (permalink / raw)
  To: newlib

On Thu, 2017-02-02 at 17:16 +0100, Freddie Chopin wrote:
> On Thu, 2017-02-02 at 10:21 +0000, Thomas Preudhomme wrote:
> > Ooops, forgot about this. Please find an updated patch attached.
> 
> Unfortunately it still fails:
> ...

Please ignore this e-mail - this was probably an user error (; I'm
testing that again. Sorry for the noise.

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-02 10:21         ` Thomas Preudhomme
  2017-02-02 16:16           ` Freddie Chopin
@ 2017-02-02 23:24           ` Freddie Chopin
  2017-02-07 21:36           ` Jeff Johnston
  2 siblings, 0 replies; 19+ messages in thread
From: Freddie Chopin @ 2017-02-02 23:24 UTC (permalink / raw)
  To: newlib

On Thu, 2017-02-02 at 10:21 +0000, Thomas Preudhomme wrote:
> Ooops, forgot about this. Please find an updated patch attached.

OK, I happily confirm that everything works fine now. I've applied 3
relevant patches:

0001-Unify-names-of-all-lock-objects.patch
guard_static_lock_single_thread.patch
newlib_retargetable_locking_routine.patch

The toolchain builds fine (including HTML and PDF documentation) and
works as expected, allowing the locking functions to be provided by
user. I have tested toolchain with and without the new "--enable-
newlib-retargetable-locking" option.

Regards,
FCh

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-02 10:21         ` Thomas Preudhomme
  2017-02-02 16:16           ` Freddie Chopin
  2017-02-02 23:24           ` Freddie Chopin
@ 2017-02-07 21:36           ` Jeff Johnston
  2017-02-08  9:07             ` Thomas Preudhomme
  2 siblings, 1 reply; 19+ messages in thread
From: Jeff Johnston @ 2017-02-07 21:36 UTC (permalink / raw)
  To: Thomas Preudhomme; +Cc: newlib

Hi Thomas,

The patch is fine except for the lock.c inline docs still have references
to old lock names (prior to the ANSI_SYNOPSIS).

-- Jeff J.

----- Original Message -----
> Ooops, forgot about this. Please find an updated patch attached.
> 
> Best regards,
> 
> Thomas
> 
> On 01/02/17 08:43, Freddie Chopin wrote:
> > Hi!
> >
> > With all relevant 3 patches applied the toolchain builds and works
> > fine, but the issue with HTML documentation still persists - at least
> > here on Arch Linux:
> >
> > --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
> >
> > make[2]: Entering directory '/home/freddie/bleeding-edge-
> > toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
> > for chapter in  ; \
> > do \
> >   cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
> > 2.5.0/newlib/libc/syscalls/$chapter >> /home/freddie/bleeding-edge-
> > toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/tmp-
> > targetdep.texi ; \
> > done
> > make[2]: Leaving directory '/home/freddie/bleeding-edge-
> > toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
> > cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
> > 2.5.0/newlib/libc/sys.tex >>tmp-targetdep.texi
> > /bin/sh /home/freddie/bleeding-edge-toolchain/sources/newlib-
> > 2.5.0/newlib/libc/../../move-if-change tmp-targetdep.texi targetdep.tex
> > touch stmp-targetdep
> > rm -rf libc.htp
> > if makeinfo --split-size=5000000 --html   -I /home/freddie/bleeding-
> > edge-toolchain/sources/newlib-2.5.0/newlib/libc \
> >  -o libc.htp /home/freddie/bleeding-edge-toolchain/sources/newlib-
> > 2.5.0/newlib/libc/libc.texinfo; \
> > then \
> >   rm -rf libc.html; \
> >   if test ! -d libc.htp && test -d libc; then \
> >     mv libc libc.html; else mv libc.htp libc.html; fi; \
> > else \
> >   if test ! -d libc.htp && test -d libc; then \
> >     rm -rf libc; else rm -Rf libc.htp libc.html; fi; \
> >   exit 1; \
> > fi
> > ./targetdep.tex:1420: @menu reference to nonexistent node `lock'
> > stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
> > sectioning `ecvt' differ
> > stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
> > in sectioning `gcvt' differ
> > stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
> > sectioning `div' differ
> > stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
> > sectioning `ecvtbuf' differ
> > stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
> > and in sectioning `ecvt' differ
> > stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
> > in sectioning `__env_lock' differ
> > stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
> > sectioning `gcvt' differ
> > stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
> > and in sectioning `exit' differ
> > stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
> > and in sectioning `ecvtbuf' differ
> > stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
> > sectioning `__env_lock' differ
> > stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
> > `mbsrtowcs' and in sectioning `mblen' differ
> > stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
> > sectioning `mbsrtowcs' differ
> > stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
> > in sectioning `__malloc_lock' differ
> > stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
> > `__malloc_lock' and in sectioning `mblen' differ
> > stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
> > and in sectioning `mbtowc' differ
> > stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
> > sectioning `mbstowcs' differ
> > ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
> > and in sectioning `iswcntrl' differ
> > ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
> > and in sectioning `iswblank' differ
> > ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
> > and in sectioning `iswalpha' differ
> > ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
> > and in sectioning `iswdigit' differ
> > ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
> > and in sectioning `iswcntrl' differ
> > ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
> > and in sectioning `iswblank' differ
> > misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
> > sectioning `__retarget_lock_init' differ
> > misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
> > misc/lock.def:1: warning: node `unctrl' is next for
> > `__retarget_lock_init' in sectioning but not in menu
> > misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
> > in sectioning but not in menu
> > misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
> > in sectioning but not in menu
> > ./targetdep.tex:1414: node `Misc' lacks menu item for
> > `__retarget_lock_init' despite being its Up target
> > misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
> > sectioning `__retarget_lock_init' differ
> > reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
> > in sectioning `_wait_r' differ
> > reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
> > in sectioning `_fstat_r' differ
> > reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
> > and in sectioning `_fork_r' differ
> > reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
> > and in sectioning `_link_r' differ
> > reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
> > in sectioning `_wait_r' differ
> > reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
> > in sectioning `_fstat_r' differ
> > reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
> > in sectioning `_kill_r' differ
> > reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
> > in sectioning `_getpid_r' differ
> > reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
> > and in sectioning `_sbrk_r' differ
> > reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
> > and in sectioning `_stat_r' differ
> > reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
> > and in sectioning `_kill_r' differ
> > reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
> > in sectioning `_getpid_r' differ
> > reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
> > and in sectioning `_write_r' differ
> > reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
> > in sectioning `_unlink_r' differ
> > make[1]: *** [Makefile:561: libc.html] Error 1
> > make[1]: Leaving directory '/home/freddie/bleeding-edge-
> > toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
> > make: *** [Makefile:680: install-html-recursive] Error 1
> >
> > --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
> >
> > Regards,
> > FCh
> >
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-07 21:36           ` Jeff Johnston
@ 2017-02-08  9:07             ` Thomas Preudhomme
       [not found]               ` <1199540764.24714361.1486590050100.JavaMail.zimbra@redhat.com>
  0 siblings, 1 reply; 19+ messages in thread
From: Thomas Preudhomme @ 2017-02-08  9:07 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 7417 bytes --]

Hi Jeff,

Please find an updated patch with consistent lock naming. Have you had a look at 
the patch prior to this one [1]?

[1] https://sourceware.org/ml/newlib/2017/msg00112.html

Thanks for your time.

Best regards,

Thomas

On 07/02/17 21:36, Jeff Johnston wrote:
> Hi Thomas,
>
> The patch is fine except for the lock.c inline docs still have references
> to old lock names (prior to the ANSI_SYNOPSIS).
>
> -- Jeff J.
>
> ----- Original Message -----
>> Ooops, forgot about this. Please find an updated patch attached.
>>
>> Best regards,
>>
>> Thomas
>>
>> On 01/02/17 08:43, Freddie Chopin wrote:
>>> Hi!
>>>
>>> With all relevant 3 patches applied the toolchain builds and works
>>> fine, but the issue with HTML documentation still persists - at least
>>> here on Arch Linux:
>>>
>>> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
>>>
>>> make[2]: Entering directory '/home/freddie/bleeding-edge-
>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
>>> for chapter in  ; \
>>> do \
>>>   cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>> 2.5.0/newlib/libc/syscalls/$chapter >> /home/freddie/bleeding-edge-
>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/tmp-
>>> targetdep.texi ; \
>>> done
>>> make[2]: Leaving directory '/home/freddie/bleeding-edge-
>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
>>> cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>> 2.5.0/newlib/libc/sys.tex >>tmp-targetdep.texi
>>> /bin/sh /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>> 2.5.0/newlib/libc/../../move-if-change tmp-targetdep.texi targetdep.tex
>>> touch stmp-targetdep
>>> rm -rf libc.htp
>>> if makeinfo --split-size=5000000 --html   -I /home/freddie/bleeding-
>>> edge-toolchain/sources/newlib-2.5.0/newlib/libc \
>>>  -o libc.htp /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>> 2.5.0/newlib/libc/libc.texinfo; \
>>> then \
>>>   rm -rf libc.html; \
>>>   if test ! -d libc.htp && test -d libc; then \
>>>     mv libc libc.html; else mv libc.htp libc.html; fi; \
>>> else \
>>>   if test ! -d libc.htp && test -d libc; then \
>>>     rm -rf libc; else rm -Rf libc.htp libc.html; fi; \
>>>   exit 1; \
>>> fi
>>> ./targetdep.tex:1420: @menu reference to nonexistent node `lock'
>>> stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
>>> sectioning `ecvt' differ
>>> stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
>>> in sectioning `gcvt' differ
>>> stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
>>> sectioning `div' differ
>>> stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
>>> sectioning `ecvtbuf' differ
>>> stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
>>> and in sectioning `ecvt' differ
>>> stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
>>> in sectioning `__env_lock' differ
>>> stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
>>> sectioning `gcvt' differ
>>> stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
>>> and in sectioning `exit' differ
>>> stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
>>> and in sectioning `ecvtbuf' differ
>>> stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
>>> sectioning `__env_lock' differ
>>> stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
>>> `mbsrtowcs' and in sectioning `mblen' differ
>>> stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
>>> sectioning `mbsrtowcs' differ
>>> stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
>>> in sectioning `__malloc_lock' differ
>>> stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
>>> `__malloc_lock' and in sectioning `mblen' differ
>>> stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
>>> and in sectioning `mbtowc' differ
>>> stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
>>> sectioning `mbstowcs' differ
>>> ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
>>> and in sectioning `iswcntrl' differ
>>> ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
>>> and in sectioning `iswblank' differ
>>> ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
>>> and in sectioning `iswalpha' differ
>>> ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
>>> and in sectioning `iswdigit' differ
>>> ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
>>> and in sectioning `iswcntrl' differ
>>> ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
>>> and in sectioning `iswblank' differ
>>> misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
>>> sectioning `__retarget_lock_init' differ
>>> misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
>>> misc/lock.def:1: warning: node `unctrl' is next for
>>> `__retarget_lock_init' in sectioning but not in menu
>>> misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
>>> in sectioning but not in menu
>>> misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
>>> in sectioning but not in menu
>>> ./targetdep.tex:1414: node `Misc' lacks menu item for
>>> `__retarget_lock_init' despite being its Up target
>>> misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
>>> sectioning `__retarget_lock_init' differ
>>> reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
>>> in sectioning `_wait_r' differ
>>> reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
>>> in sectioning `_fstat_r' differ
>>> reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
>>> and in sectioning `_fork_r' differ
>>> reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
>>> and in sectioning `_link_r' differ
>>> reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
>>> in sectioning `_wait_r' differ
>>> reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
>>> in sectioning `_fstat_r' differ
>>> reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
>>> in sectioning `_kill_r' differ
>>> reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
>>> in sectioning `_getpid_r' differ
>>> reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
>>> and in sectioning `_sbrk_r' differ
>>> reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
>>> and in sectioning `_stat_r' differ
>>> reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
>>> and in sectioning `_kill_r' differ
>>> reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
>>> in sectioning `_getpid_r' differ
>>> reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
>>> and in sectioning `_write_r' differ
>>> reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
>>> in sectioning `_unlink_r' differ
>>> make[1]: *** [Makefile:561: libc.html] Error 1
>>> make[1]: Leaving directory '/home/freddie/bleeding-edge-
>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
>>> make: *** [Makefile:680: install-html-recursive] Error 1
>>>
>>> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
>>>
>>> Regards,
>>> FCh
>>>
>>

[-- Attachment #2: newlib_retargetable_locking_routine.patch --]
[-- Type: text/x-patch, Size: 21310 bytes --]

From 46109224fdb16b67406a8aeec5069739bc1dc25c Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date: Tue, 25 Oct 2016 17:38:19 +0100
Subject: [PATCH] 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.
---
 newlib/configure               |  25 ++++++-
 newlib/configure.in            |  15 ++++
 newlib/libc/configure          |  32 ++++++++-
 newlib/libc/configure.in       |  10 +++
 newlib/libc/include/sys/lock.h |  49 ++++++++++++-
 newlib/libc/misc/Makefile.am   |   7 +-
 newlib/libc/misc/Makefile.in   |  28 ++++++--
 newlib/libc/misc/lock.c        | 157 +++++++++++++++++++++++++++++++++++++++++
 newlib/libc/misc/misc.tex      |   4 ++
 newlib/newlib.hin              |   3 +
 10 files changed, 316 insertions(+), 14 deletions(-)
 create mode 100644 newlib/libc/misc/lock.c

diff --git a/newlib/configure b/newlib/configure
index 2ac07fe..de28c25 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -802,6 +802,7 @@ enable_newlib_nano_malloc
 enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1473,6 +1474,7 @@ Optional Features:
   --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2474,6 +2476,18 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11780,7 +11794,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11783 "configure"
+#line 11797 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11886,7 +11900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11889 "configure"
+#line 11903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12455,6 +12469,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _RETARGETABLE_LOCKING 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index bfaf038..354c07c 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
  esac],[newlib_nano_formatted_io=no])
 
+dnl Support --enable-retargetable-locking
+dnl This option is also read in libc/configure.in.  It is repeated
+dnl here so that it shows up in the help text.
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
 AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/configure b/newlib/libc/configure
index 4dc4d1b..dabe44f 100755
--- a/newlib/libc/configure
+++ b/newlib/libc/configure
@@ -751,6 +751,8 @@ build
 newlib_basedir
 MAY_SUPPLY_SYSCALLS_FALSE
 MAY_SUPPLY_SYSCALLS_TRUE
+NEWLIB_RETARGETABLE_LOCKING_FALSE
+NEWLIB_RETARGETABLE_LOCKING_TRUE
 NEWLIB_NANO_FORMATTED_IO_FALSE
 NEWLIB_NANO_FORMATTED_IO_TRUE
 target_alias
@@ -797,6 +799,7 @@ enable_option_checking
 enable_newlib_io_pos_args
 enable_newlib_nano_malloc
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1448,6 +1451,7 @@ Optional Features:
   --enable-newlib-io-pos-args enable printf-family positional arg support
   --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
   --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2252,6 +2256,26 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+ if test x$newlib_retargetable_locking = xyes; then
+  NEWLIB_RETARGETABLE_LOCKING_TRUE=
+  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
+else
+  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
+  NEWLIB_RETARGETABLE_LOCKING_FALSE=
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11525,7 +11549,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11528 "configure"
+#line 11552 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11631,7 +11655,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11634 "configure"
+#line 11658 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
   as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
+  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
   as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
index 0a7bb88..ac25a39 100644
--- a/newlib/libc/configure.in
+++ b/newlib/libc/configure.in
@@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
  esac],[newlib_nano_formatted_io=no])
 AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
 
+dnl Support --enable-retargetable-locking used by libc/sys
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
+
 NEWLIB_CONFIGURE(..)
 
 AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
index a406ec7..130fbbf 100644
--- a/newlib/libc/include/sys/lock.h
+++ b/newlib/libc/include/sys/lock.h
@@ -3,10 +3,13 @@
 
 /* dummy lock routines for single-threaded aps */
 
+#include <newlib.h>
+#include <_ansi.h>
+
+#if defined(__SINGLE_THREAD__) || !defined(_RETARGETABLE_LOCKING)
+
 typedef int _LOCK_T;
 typedef int _LOCK_RECURSIVE_T;
- 
-#include <_ansi.h>
 
 #ifdef __SINGLE_THREAD__
 #define __LOCK_INIT(class,lock) ;
@@ -27,4 +30,46 @@ typedef int _LOCK_RECURSIVE_T;
 #define __lock_release(lock) (_CAST_VOID 0)
 #define __lock_release_recursive(lock) (_CAST_VOID 0)
 
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct __lock;
+typedef struct __lock * _LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+#define __LOCK_INIT(class,lock) extern struct __lock __lock_ ## lock; \
+	class _LOCK_T lock = &__lock_ ## lock
+#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
+
+extern void __retarget_lock_init(_LOCK_T *lock);
+#define __lock_init(lock) __retarget_lock_init(&lock)
+extern void __retarget_lock_init_recursive(_LOCK_T *lock);
+#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
+extern void __retarget_lock_close(_LOCK_T lock);
+#define __lock_close(lock) __retarget_lock_close(lock)
+extern void __retarget_lock_close_recursive(_LOCK_T lock);
+#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
+extern void __retarget_lock_acquire(_LOCK_T lock);
+#define __lock_acquire(lock) __retarget_lock_acquire(lock)
+extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
+#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
+extern int __retarget_lock_try_acquire(_LOCK_T lock);
+#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
+extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
+#define __lock_try_acquire_recursive(lock) \
+  __retarget_lock_try_acquire_recursive(lock)
+extern void __retarget_lock_release(_LOCK_T lock);
+#define __lock_release(lock) __retarget_lock_release(lock)
+extern void __retarget_lock_release_recursive(_LOCK_T lock);
+#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(__SINGLE_THREAD__) && defined(_RETARGETABLE_LOCKING) */
+
 #endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
index 3fe8e55..7571ef2 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 0ada8de..e792523 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 0000000..a763176
--- /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 22c313e..248243b 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
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index d03dfac..397bc9b 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -82,6 +82,9 @@
 /* Define if small footprint nano-formatted-IO implementation used.  */
 #undef _NANO_FORMATTED_IO
 
+/* Define if using retargetable functions for default lock routines.  */
+#undef _RETARGETABLE_LOCKING
+
 /*
  * Iconv encodings enabled ("to" direction)
  */
-- 
1.9.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
       [not found]               ` <1199540764.24714361.1486590050100.JavaMail.zimbra@redhat.com>
@ 2017-02-10 11:15                 ` Thomas Preudhomme
  2017-02-13 22:16                   ` Jeff Johnston
  0 siblings, 1 reply; 19+ messages in thread
From: Thomas Preudhomme @ 2017-02-10 11:15 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 8371 bytes --]

Hi Jeff,

Please find an updated patch which does not add extra noop code for single 
threaded mode in sys/lock.h as requested. Please note that it goes together with 
an updated version of the previous patch in the patch series [1].

[1] https://sourceware.org/ml/newlib/2017/msg00136.html

Best regards,

Thomas

On 08/02/17 21:40, Jeff Johnston wrote:
> Thanks Thomas,
>
> Regarding that other patch.  I do not feel the extra noop code in sys/lock.h is warranted and
> seems extraneous.  I would prefer the users of the lock protect the usage as you have added.
>
> -- Jeff J.
>
> ----- Original Message -----
>> Hi Jeff,
>>
>> Please find an updated patch with consistent lock naming. Have you had a look
>> at
>> the patch prior to this one [1]?
>>
>> [1] https://sourceware.org/ml/newlib/2017/msg00112.html
>>
>> Thanks for your time.
>>
>> Best regards,
>>
>> Thomas
>>
>> On 07/02/17 21:36, Jeff Johnston wrote:
>>> Hi Thomas,
>>>
>>> The patch is fine except for the lock.c inline docs still have references
>>> to old lock names (prior to the ANSI_SYNOPSIS).
>>>
>>> -- Jeff J.
>>>
>>> ----- Original Message -----
>>>> Ooops, forgot about this. Please find an updated patch attached.
>>>>
>>>> Best regards,
>>>>
>>>> Thomas
>>>>
>>>> On 01/02/17 08:43, Freddie Chopin wrote:
>>>>> Hi!
>>>>>
>>>>> With all relevant 3 patches applied the toolchain builds and works
>>>>> fine, but the issue with HTML documentation still persists - at least
>>>>> here on Arch Linux:
>>>>>
>>>>> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
>>>>>
>>>>> make[2]: Entering directory '/home/freddie/bleeding-edge-
>>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
>>>>> for chapter in  ; \
>>>>> do \
>>>>>   cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>>>> 2.5.0/newlib/libc/syscalls/$chapter >> /home/freddie/bleeding-edge-
>>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/tmp-
>>>>> targetdep.texi ; \
>>>>> done
>>>>> make[2]: Leaving directory '/home/freddie/bleeding-edge-
>>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
>>>>> cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>>>> 2.5.0/newlib/libc/sys.tex >>tmp-targetdep.texi
>>>>> /bin/sh /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>>>> 2.5.0/newlib/libc/../../move-if-change tmp-targetdep.texi targetdep.tex
>>>>> touch stmp-targetdep
>>>>> rm -rf libc.htp
>>>>> if makeinfo --split-size=5000000 --html   -I /home/freddie/bleeding-
>>>>> edge-toolchain/sources/newlib-2.5.0/newlib/libc \
>>>>>  -o libc.htp /home/freddie/bleeding-edge-toolchain/sources/newlib-
>>>>> 2.5.0/newlib/libc/libc.texinfo; \
>>>>> then \
>>>>>   rm -rf libc.html; \
>>>>>   if test ! -d libc.htp && test -d libc; then \
>>>>>     mv libc libc.html; else mv libc.htp libc.html; fi; \
>>>>> else \
>>>>>   if test ! -d libc.htp && test -d libc; then \
>>>>>     rm -rf libc; else rm -Rf libc.htp libc.html; fi; \
>>>>>   exit 1; \
>>>>> fi
>>>>> ./targetdep.tex:1420: @menu reference to nonexistent node `lock'
>>>>> stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
>>>>> sectioning `ecvt' differ
>>>>> stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
>>>>> in sectioning `gcvt' differ
>>>>> stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
>>>>> sectioning `div' differ
>>>>> stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
>>>>> sectioning `ecvtbuf' differ
>>>>> stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
>>>>> and in sectioning `ecvt' differ
>>>>> stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
>>>>> in sectioning `__env_lock' differ
>>>>> stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
>>>>> sectioning `gcvt' differ
>>>>> stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
>>>>> and in sectioning `exit' differ
>>>>> stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
>>>>> and in sectioning `ecvtbuf' differ
>>>>> stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
>>>>> sectioning `__env_lock' differ
>>>>> stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
>>>>> `mbsrtowcs' and in sectioning `mblen' differ
>>>>> stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
>>>>> sectioning `mbsrtowcs' differ
>>>>> stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
>>>>> in sectioning `__malloc_lock' differ
>>>>> stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
>>>>> `__malloc_lock' and in sectioning `mblen' differ
>>>>> stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
>>>>> and in sectioning `mbtowc' differ
>>>>> stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
>>>>> sectioning `mbstowcs' differ
>>>>> ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
>>>>> and in sectioning `iswcntrl' differ
>>>>> ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
>>>>> and in sectioning `iswblank' differ
>>>>> ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
>>>>> and in sectioning `iswalpha' differ
>>>>> ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
>>>>> and in sectioning `iswdigit' differ
>>>>> ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
>>>>> and in sectioning `iswcntrl' differ
>>>>> ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
>>>>> and in sectioning `iswblank' differ
>>>>> misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
>>>>> sectioning `__retarget_lock_init' differ
>>>>> misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
>>>>> misc/lock.def:1: warning: node `unctrl' is next for
>>>>> `__retarget_lock_init' in sectioning but not in menu
>>>>> misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
>>>>> in sectioning but not in menu
>>>>> misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
>>>>> in sectioning but not in menu
>>>>> ./targetdep.tex:1414: node `Misc' lacks menu item for
>>>>> `__retarget_lock_init' despite being its Up target
>>>>> misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
>>>>> sectioning `__retarget_lock_init' differ
>>>>> reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
>>>>> in sectioning `_wait_r' differ
>>>>> reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
>>>>> in sectioning `_fstat_r' differ
>>>>> reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
>>>>> and in sectioning `_fork_r' differ
>>>>> reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
>>>>> and in sectioning `_link_r' differ
>>>>> reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
>>>>> in sectioning `_wait_r' differ
>>>>> reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
>>>>> in sectioning `_fstat_r' differ
>>>>> reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
>>>>> in sectioning `_kill_r' differ
>>>>> reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
>>>>> in sectioning `_getpid_r' differ
>>>>> reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
>>>>> and in sectioning `_sbrk_r' differ
>>>>> reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
>>>>> and in sectioning `_stat_r' differ
>>>>> reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
>>>>> and in sectioning `_kill_r' differ
>>>>> reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
>>>>> in sectioning `_getpid_r' differ
>>>>> reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
>>>>> and in sectioning `_write_r' differ
>>>>> reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
>>>>> in sectioning `_unlink_r' differ
>>>>> make[1]: *** [Makefile:561: libc.html] Error 1
>>>>> make[1]: Leaving directory '/home/freddie/bleeding-edge-
>>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
>>>>> make: *** [Makefile:680: install-html-recursive] Error 1
>>>>>
>>>>> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
>>>>>
>>>>> Regards,
>>>>> FCh
>>>>>
>>>>
>>

[-- Attachment #2: newlib_retargetable_locking_routine.patch --]
[-- Type: text/x-patch, Size: 21311 bytes --]

From 22f744ec5afd49b2b9f419b851fc73905dbac59e Mon Sep 17 00:00:00 2001
From: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date: Tue, 25 Oct 2016 17:38:19 +0100
Subject: [PATCH 2/2] 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.
---
 newlib/configure               |  25 ++++++-
 newlib/configure.in            |  15 ++++
 newlib/libc/configure          |  32 ++++++++-
 newlib/libc/configure.in       |  10 +++
 newlib/libc/include/sys/lock.h |  49 ++++++++++++-
 newlib/libc/misc/Makefile.am   |   7 +-
 newlib/libc/misc/Makefile.in   |  28 ++++++--
 newlib/libc/misc/lock.c        | 157 +++++++++++++++++++++++++++++++++++++++++
 newlib/libc/misc/misc.tex      |   4 ++
 newlib/newlib.hin              |   3 +
 10 files changed, 316 insertions(+), 14 deletions(-)
 create mode 100644 newlib/libc/misc/lock.c

diff --git a/newlib/configure b/newlib/configure
index 2ac07fe..de28c25 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -802,6 +802,7 @@ enable_newlib_nano_malloc
 enable_newlib_unbuf_stream_opt
 enable_lite_exit
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1473,6 +1474,7 @@ Optional Features:
   --disable-newlib-unbuf-stream-opt    disable unbuffered stream optimization in streamio
   --enable-lite-exit	enable light weight exit
   --enable-newlib-nano-formatted-io    Use nano version formatted IO
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2474,6 +2476,18 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11780,7 +11794,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11783 "configure"
+#line 11797 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11886,7 +11900,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11889 "configure"
+#line 11903 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12455,6 +12469,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _RETARGETABLE_LOCKING 1
+_ACEOF
+
+fi
+
 
 if test "x${iconv_encodings}" != "x" \
    || test "x${iconv_to_encodings}" != "x" \
diff --git a/newlib/configure.in b/newlib/configure.in
index bfaf038..354c07c 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -218,6 +218,17 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
    *) AC_MSG_ERROR(bad value ${enableval} for newlib-nano-formatted-io) ;;
  esac],[newlib_nano_formatted_io=no])
 
+dnl Support --enable-retargetable-locking
+dnl This option is also read in libc/configure.in.  It is repeated
+dnl here so that it shows up in the help text.
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_locking=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+
 NEWLIB_CONFIGURE(.)
 
 dnl We have to enable libtool after NEWLIB_CONFIGURE because if we try and
@@ -458,6 +469,10 @@ if test "${newlib_nano_formatted_io}" = "yes"; then
 AC_DEFINE_UNQUOTED(_NANO_FORMATTED_IO)
 fi
 
+if test "${newlib_retargetable_locking}" = "yes"; then
+AC_DEFINE_UNQUOTED(_RETARGETABLE_LOCKING)
+fi
+
 dnl
 dnl Parse --enable-newlib-iconv-encodings option argument
 dnl
diff --git a/newlib/libc/configure b/newlib/libc/configure
index 4dc4d1b..dabe44f 100755
--- a/newlib/libc/configure
+++ b/newlib/libc/configure
@@ -751,6 +751,8 @@ build
 newlib_basedir
 MAY_SUPPLY_SYSCALLS_FALSE
 MAY_SUPPLY_SYSCALLS_TRUE
+NEWLIB_RETARGETABLE_LOCKING_FALSE
+NEWLIB_RETARGETABLE_LOCKING_TRUE
 NEWLIB_NANO_FORMATTED_IO_FALSE
 NEWLIB_NANO_FORMATTED_IO_TRUE
 target_alias
@@ -797,6 +799,7 @@ enable_option_checking
 enable_newlib_io_pos_args
 enable_newlib_nano_malloc
 enable_newlib_nano_formatted_io
+enable_newlib_retargetable_locking
 enable_multilib
 enable_target_optspace
 enable_malloc_debugging
@@ -1448,6 +1451,7 @@ Optional Features:
   --enable-newlib-io-pos-args enable printf-family positional arg support
   --enable-newlib-nano-malloc    Use small-footprint nano-malloc implementation
   --enable-newlib-nano-formatted-io    Use small-footprint nano-formatted-IO implementation
+  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time
   --enable-multilib         build many library versions (default)
   --enable-target-optspace  optimize for space
   --enable-malloc-debugging indicate malloc debugging requested
@@ -2252,6 +2256,26 @@ else
 fi
 
 
+# Check whether --enable-newlib-retargetable-locking was given.
+if test "${enable_newlib_retargetable_locking+set}" = set; then :
+  enableval=$enable_newlib_retargetable_locking; case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) as_fn_error $? "bad value ${enableval} for newlib-retargetable-locking" "$LINENO" 5 ;;
+ esac
+else
+  newlib_retargetable_locking=no
+fi
+
+ if test x$newlib_retargetable_locking = xyes; then
+  NEWLIB_RETARGETABLE_LOCKING_TRUE=
+  NEWLIB_RETARGETABLE_LOCKING_FALSE='#'
+else
+  NEWLIB_RETARGETABLE_LOCKING_TRUE='#'
+  NEWLIB_RETARGETABLE_LOCKING_FALSE=
+fi
+
+
 
 # Make sure we can run config.sub.
 $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
@@ -11525,7 +11549,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11528 "configure"
+#line 11552 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11631,7 +11655,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11634 "configure"
+#line 11658 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12248,6 +12272,10 @@ if test -z "${NEWLIB_NANO_FORMATTED_IO_TRUE}" && test -z "${NEWLIB_NANO_FORMATTE
   as_fn_error $? "conditional \"NEWLIB_NANO_FORMATTED_IO\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${NEWLIB_RETARGETABLE_LOCKING_TRUE}" && test -z "${NEWLIB_RETARGETABLE_LOCKING_FALSE}"; then
+  as_fn_error $? "conditional \"NEWLIB_RETARGETABLE_LOCKING\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAY_SUPPLY_SYSCALLS_TRUE}" && test -z "${MAY_SUPPLY_SYSCALLS_FALSE}"; then
   as_fn_error $? "conditional \"MAY_SUPPLY_SYSCALLS\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/newlib/libc/configure.in b/newlib/libc/configure.in
index 0a7bb88..ac25a39 100644
--- a/newlib/libc/configure.in
+++ b/newlib/libc/configure.in
@@ -36,6 +36,16 @@ AC_ARG_ENABLE(newlib_nano_formatted_io,
  esac],[newlib_nano_formatted_io=no])
 AM_CONDITIONAL(NEWLIB_NANO_FORMATTED_IO, test x$newlib_nano_formatted_io = xyes)
 
+dnl Support --enable-retargetable-locking used by libc/sys
+AC_ARG_ENABLE(newlib-retargetable-locking,
+[  --enable-newlib-retargetable-locking    Allow locking routines to be retargeted at link time],
+[case "${enableval}" in
+   yes) newlib_retargetable_locking=yes ;;
+   no)  newlib_retargetable_lock=no ;;
+   *) AC_MSG_ERROR(bad value ${enableval} for newlib-retargetable-locking) ;;
+ esac],[newlib_retargetable_locking=no])
+AM_CONDITIONAL(NEWLIB_RETARGETABLE_LOCKING, test x$newlib_retargetable_locking = xyes)
+
 NEWLIB_CONFIGURE(..)
 
 AM_CONDITIONAL(NEWLIB_NANO_MALLOC, test x$newlib_nano_malloc = xyes)
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
index 9075e35..42f9c4c 100644
--- a/newlib/libc/include/sys/lock.h
+++ b/newlib/libc/include/sys/lock.h
@@ -3,10 +3,13 @@
 
 /* dummy lock routines for single-threaded aps */
 
+#include <newlib.h>
+#include <_ansi.h>
+
+#if !defined(_RETARGETABLE_LOCKING)
+
 typedef int _LOCK_T;
 typedef int _LOCK_RECURSIVE_T;
- 
-#include <_ansi.h>
 
 #define __LOCK_INIT(class,lock) static int lock = 0;
 #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
@@ -21,4 +24,46 @@ typedef int _LOCK_RECURSIVE_T;
 #define __lock_release(lock) (_CAST_VOID 0)
 #define __lock_release_recursive(lock) (_CAST_VOID 0)
 
+#else
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct __lock;
+typedef struct __lock * _LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+#define __LOCK_INIT(class,lock) extern struct __lock __lock_ ## lock; \
+	class _LOCK_T lock = &__lock_ ## lock
+#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
+
+extern void __retarget_lock_init(_LOCK_T *lock);
+#define __lock_init(lock) __retarget_lock_init(&lock)
+extern void __retarget_lock_init_recursive(_LOCK_T *lock);
+#define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
+extern void __retarget_lock_close(_LOCK_T lock);
+#define __lock_close(lock) __retarget_lock_close(lock)
+extern void __retarget_lock_close_recursive(_LOCK_T lock);
+#define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
+extern void __retarget_lock_acquire(_LOCK_T lock);
+#define __lock_acquire(lock) __retarget_lock_acquire(lock)
+extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
+#define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
+extern int __retarget_lock_try_acquire(_LOCK_T lock);
+#define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
+extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
+#define __lock_try_acquire_recursive(lock) \
+  __retarget_lock_try_acquire_recursive(lock)
+extern void __retarget_lock_release(_LOCK_T lock);
+#define __lock_release(lock) __retarget_lock_release(lock)
+extern void __retarget_lock_release_recursive(_LOCK_T lock);
+#define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(_RETARGETABLE_LOCKING) */
+
 #endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/misc/Makefile.am b/newlib/libc/misc/Makefile.am
index 3fe8e55..7571ef2 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 0ada8de..e792523 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 0000000..a763176
--- /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 22c313e..248243b 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
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index d03dfac..397bc9b 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -82,6 +82,9 @@
 /* Define if small footprint nano-formatted-IO implementation used.  */
 #undef _NANO_FORMATTED_IO
 
+/* Define if using retargetable functions for default lock routines.  */
+#undef _RETARGETABLE_LOCKING
+
 /*
  * Iconv encodings enabled ("to" direction)
  */
-- 
1.9.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3, newlib] Allow locking routine to be retargeted
  2017-02-10 11:15                 ` Thomas Preudhomme
@ 2017-02-13 22:16                   ` Jeff Johnston
  0 siblings, 0 replies; 19+ messages in thread
From: Jeff Johnston @ 2017-02-13 22:16 UTC (permalink / raw)
  To: Thomas Preudhomme; +Cc: newlib

Patch checked in.

-- Jeff J.

----- Original Message -----
> Hi Jeff,
> 
> Please find an updated patch which does not add extra noop code for single
> threaded mode in sys/lock.h as requested. Please note that it goes together
> with
> an updated version of the previous patch in the patch series [1].
> 
> [1] https://sourceware.org/ml/newlib/2017/msg00136.html
> 
> Best regards,
> 
> Thomas
> 
> On 08/02/17 21:40, Jeff Johnston wrote:
> > Thanks Thomas,
> >
> > Regarding that other patch.  I do not feel the extra noop code in
> > sys/lock.h is warranted and
> > seems extraneous.  I would prefer the users of the lock protect the usage
> > as you have added.
> >
> > -- Jeff J.
> >
> > ----- Original Message -----
> >> Hi Jeff,
> >>
> >> Please find an updated patch with consistent lock naming. Have you had a
> >> look
> >> at
> >> the patch prior to this one [1]?
> >>
> >> [1] https://sourceware.org/ml/newlib/2017/msg00112.html
> >>
> >> Thanks for your time.
> >>
> >> Best regards,
> >>
> >> Thomas
> >>
> >> On 07/02/17 21:36, Jeff Johnston wrote:
> >>> Hi Thomas,
> >>>
> >>> The patch is fine except for the lock.c inline docs still have references
> >>> to old lock names (prior to the ANSI_SYNOPSIS).
> >>>
> >>> -- Jeff J.
> >>>
> >>> ----- Original Message -----
> >>>> Ooops, forgot about this. Please find an updated patch attached.
> >>>>
> >>>> Best regards,
> >>>>
> >>>> Thomas
> >>>>
> >>>> On 01/02/17 08:43, Freddie Chopin wrote:
> >>>>> Hi!
> >>>>>
> >>>>> With all relevant 3 patches applied the toolchain builds and works
> >>>>> fine, but the issue with HTML documentation still persists - at least
> >>>>> here on Arch Linux:
> >>>>>
> >>>>> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
> >>>>>
> >>>>> make[2]: Entering directory '/home/freddie/bleeding-edge-
> >>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
> >>>>> for chapter in  ; \
> >>>>> do \
> >>>>>   cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
> >>>>> 2.5.0/newlib/libc/syscalls/$chapter >> /home/freddie/bleeding-edge-
> >>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/tmp-
> >>>>> targetdep.texi ; \
> >>>>> done
> >>>>> make[2]: Leaving directory '/home/freddie/bleeding-edge-
> >>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc/syscalls'
> >>>>> cat /home/freddie/bleeding-edge-toolchain/sources/newlib-
> >>>>> 2.5.0/newlib/libc/sys.tex >>tmp-targetdep.texi
> >>>>> /bin/sh /home/freddie/bleeding-edge-toolchain/sources/newlib-
> >>>>> 2.5.0/newlib/libc/../../move-if-change tmp-targetdep.texi targetdep.tex
> >>>>> touch stmp-targetdep
> >>>>> rm -rf libc.htp
> >>>>> if makeinfo --split-size=5000000 --html   -I /home/freddie/bleeding-
> >>>>> edge-toolchain/sources/newlib-2.5.0/newlib/libc \
> >>>>>  -o libc.htp /home/freddie/bleeding-edge-toolchain/sources/newlib-
> >>>>> 2.5.0/newlib/libc/libc.texinfo; \
> >>>>> then \
> >>>>>   rm -rf libc.html; \
> >>>>>   if test ! -d libc.htp && test -d libc; then \
> >>>>>     mv libc libc.html; else mv libc.htp libc.html; fi; \
> >>>>> else \
> >>>>>   if test ! -d libc.htp && test -d libc; then \
> >>>>>     rm -rf libc; else rm -Rf libc.htp libc.html; fi; \
> >>>>>   exit 1; \
> >>>>> fi
> >>>>> ./targetdep.tex:1420: @menu reference to nonexistent node `lock'
> >>>>> stdlib/div.def:1: warning: node next `div' in menu `ecvtbuf' and in
> >>>>> sectioning `ecvt' differ
> >>>>> stdlib/efgcvt.def:1: warning: node next `ecvt' in menu `__env_lock' and
> >>>>> in sectioning `gcvt' differ
> >>>>> stdlib/efgcvt.def:1: warning: node prev `ecvt' in menu `ecvtbuf' and in
> >>>>> sectioning `div' differ
> >>>>> stdlib/efgcvt.def:60: warning: node next `gcvt' in menu `exit' and in
> >>>>> sectioning `ecvtbuf' differ
> >>>>> stdlib/efgcvt.def:60: warning: node prev `gcvt' in menu `__env_lock'
> >>>>> and in sectioning `ecvt' differ
> >>>>> stdlib/ecvtbuf.def:1: warning: node next `ecvtbuf' in menu `ecvt' and
> >>>>> in sectioning `__env_lock' differ
> >>>>> stdlib/ecvtbuf.def:1: warning: node prev `ecvtbuf' in menu `div' and in
> >>>>> sectioning `gcvt' differ
> >>>>> stdlib/envlock.def:1: warning: node next `__env_lock' in menu `gcvt'
> >>>>> and in sectioning `exit' differ
> >>>>> stdlib/envlock.def:1: warning: node prev `__env_lock' in menu `ecvt'
> >>>>> and in sectioning `ecvtbuf' differ
> >>>>> stdlib/exit.def:1: warning: node prev `exit' in menu `gcvt' and in
> >>>>> sectioning `__env_lock' differ
> >>>>> stdlib/mlock.def:1: warning: node next `__malloc_lock' in menu
> >>>>> `mbsrtowcs' and in sectioning `mblen' differ
> >>>>> stdlib/mblen.def:1: warning: node next `mblen' in menu `mbtowc' and in
> >>>>> sectioning `mbsrtowcs' differ
> >>>>> stdlib/mblen.def:1: warning: node prev `mblen' in menu `mbstowcs' and
> >>>>> in sectioning `__malloc_lock' differ
> >>>>> stdlib/mbsnrtowcs.def:1: warning: node prev `mbsrtowcs' in menu
> >>>>> `__malloc_lock' and in sectioning `mblen' differ
> >>>>> stdlib/mbstowcs.def:1: warning: node next `mbstowcs' in menu `mblen'
> >>>>> and in sectioning `mbtowc' differ
> >>>>> stdlib/mbtowc.def:1: warning: node prev `mbtowc' in menu `mblen' and in
> >>>>> sectioning `mbstowcs' differ
> >>>>> ctype/iswalpha.def:1: warning: node next `iswalpha' in menu `iswblank'
> >>>>> and in sectioning `iswcntrl' differ
> >>>>> ctype/iswcntrl.def:1: warning: node next `iswcntrl' in menu `iswdigit'
> >>>>> and in sectioning `iswblank' differ
> >>>>> ctype/iswcntrl.def:1: warning: node prev `iswcntrl' in menu `iswblank'
> >>>>> and in sectioning `iswalpha' differ
> >>>>> ctype/iswblank.def:1: warning: node next `iswblank' in menu `iswcntrl'
> >>>>> and in sectioning `iswdigit' differ
> >>>>> ctype/iswblank.def:1: warning: node prev `iswblank' in menu `iswalpha'
> >>>>> and in sectioning `iswcntrl' differ
> >>>>> ctype/iswdigit.def:1: warning: node prev `iswdigit' in menu `iswcntrl'
> >>>>> and in sectioning `iswblank' differ
> >>>>> misc/ffs.def:1: warning: node next `ffs' in menu `unctrl' and in
> >>>>> sectioning `__retarget_lock_init' differ
> >>>>> misc/lock.def:1: warning: unreferenced node `__retarget_lock_init'
> >>>>> misc/lock.def:1: warning: node `unctrl' is next for
> >>>>> `__retarget_lock_init' in sectioning but not in menu
> >>>>> misc/lock.def:1: warning: node `ffs' is prev for `__retarget_lock_init'
> >>>>> in sectioning but not in menu
> >>>>> misc/lock.def:1: warning: node `Misc' is up for `__retarget_lock_init'
> >>>>> in sectioning but not in menu
> >>>>> ./targetdep.tex:1414: node `Misc' lacks menu item for
> >>>>> `__retarget_lock_init' despite being its Up target
> >>>>> misc/unctrl.def:1: warning: node prev `unctrl' in menu `ffs' and in
> >>>>> sectioning `__retarget_lock_init' differ
> >>>>> reent/execr.def:19: warning: node next `_fork_r' in menu `_fstat_r' and
> >>>>> in sectioning `_wait_r' differ
> >>>>> reent/execr.def:36: warning: node next `_wait_r' in menu `_write_r' and
> >>>>> in sectioning `_fstat_r' differ
> >>>>> reent/execr.def:36: warning: node prev `_wait_r' in menu `_unlink_r'
> >>>>> and in sectioning `_fork_r' differ
> >>>>> reent/fstatr.def:1: warning: node next `_fstat_r' in menu `_getpid_r'
> >>>>> and in sectioning `_link_r' differ
> >>>>> reent/fstatr.def:1: warning: node prev `_fstat_r' in menu `_fork_r' and
> >>>>> in sectioning `_wait_r' differ
> >>>>> reent/linkr.def:1: warning: node prev `_link_r' in menu `_kill_r' and
> >>>>> in sectioning `_fstat_r' differ
> >>>>> reent/sbrkr.def:1: warning: node next `_sbrk_r' in menu `_stat_r' and
> >>>>> in sectioning `_kill_r' differ
> >>>>> reent/signalr.def:1: warning: node next `_kill_r' in menu `_link_r' and
> >>>>> in sectioning `_getpid_r' differ
> >>>>> reent/signalr.def:1: warning: node prev `_kill_r' in menu `_getpid_r'
> >>>>> and in sectioning `_sbrk_r' differ
> >>>>> reent/signalr.def:18: warning: node next `_getpid_r' in menu `_kill_r'
> >>>>> and in sectioning `_stat_r' differ
> >>>>> reent/signalr.def:18: warning: node prev `_getpid_r' in menu `_fstat_r'
> >>>>> and in sectioning `_kill_r' differ
> >>>>> reent/statr.def:1: warning: node prev `_stat_r' in menu `_sbrk_r' and
> >>>>> in sectioning `_getpid_r' differ
> >>>>> reent/unlinkr.def:1: warning: node next `_unlink_r' in menu `_wait_r'
> >>>>> and in sectioning `_write_r' differ
> >>>>> reent/writer.def:1: warning: node prev `_write_r' in menu `_wait_r' and
> >>>>> in sectioning `_unlink_r' differ
> >>>>> make[1]: *** [Makefile:561: libc.html] Error 1
> >>>>> make[1]: Leaving directory '/home/freddie/bleeding-edge-
> >>>>> toolchain/buildNative/newlib-2.5.0/arm-none-eabi/newlib/libc'
> >>>>> make: *** [Makefile:680: install-html-recursive] Error 1
> >>>>>
> >>>>> --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 --- >8 ---
> >>>>>
> >>>>> Regards,
> >>>>> FCh
> >>>>>
> >>>>
> >>
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-02-13 22:16 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-24 16:05 [PATCH 2/2, newlib] Allow locking routine to be retargeted Thomas Preudhomme
2017-01-25 11:39 ` Corinna Vinschen
2017-01-25 20:43   ` Jeff Johnston
2017-01-31 17:19     ` [PATCH 3/3, " Thomas Preudhomme
2017-02-01  8:43       ` Freddie Chopin
2017-02-02 10:21         ` Thomas Preudhomme
2017-02-02 16:16           ` Freddie Chopin
2017-02-02 16:25             ` Freddie Chopin
2017-02-02 23:24           ` Freddie Chopin
2017-02-07 21:36           ` Jeff Johnston
2017-02-08  9:07             ` Thomas Preudhomme
     [not found]               ` <1199540764.24714361.1486590050100.JavaMail.zimbra@redhat.com>
2017-02-10 11:15                 ` Thomas Preudhomme
2017-02-13 22:16                   ` Jeff Johnston
2017-02-01  9:06       ` Freddie Chopin
2017-02-02 10:21         ` Thomas Preudhomme
2017-01-29 11:19 ` [PATCH 2/2, " Freddie Chopin
2017-01-29 17:07   ` Freddie Chopin
2017-01-29 22:09 ` Freddie Chopin
2017-01-30 18:53 ` Freddie Chopin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).