Skip to contentSkip to conversation

scripts/xeno-config: fix error message, dump_wrappers is not just POSIX

PATCH In review Henning Schild 2 participants 11 messages Jan 25, 2017 – Mar 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 scripts/xeno-config: fix error message, dump_wrappers is not just POSIX

---
 scripts/xeno-config-cobalt.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/xeno-config-cobalt.in +1 -1
index 62c1f33..d102d04 100644
@@ -25,7 +25,7 @@ dump_wrappers()
 {
    file=$1
    if test \! -r ${XENO_LIBRARY_DIR}/$file; then
-      echo "Xenomai: POSIX wrappers cannot be read from ${XENO_LIBRARY_DIR}/${file}" >&2
+      echo "Xenomai: wrappers cannot be read from ${XENO_LIBRARY_DIR}/${file}" >&2
       exit 1
    fi
    if test "$LD_FILE_OPTION" = "yes"; then
Signature · 1 line
2.10.2
#1 lore raw

PATCH 2/3 scripts/xeno-config: apply the assert_nrt wrappers on all skins

There are basically two classes of wrappers. Those that actually change the implementation, and those that just assert that certain calls are not made from a realtime context. The latter are usefull for all skins and should always be applied.

---
 configure.ac                  | 12 +++++++-----
 debian/libxenomai-dev.install |  1 +
 lib/cobalt/Makefile.am        |  4 +++-
 lib/cobalt/assert.wrappers    |  2 ++
 lib/cobalt/cobalt.wrappers    |  2 --
 scripts/xeno-config-cobalt.in |  4 ++--
 6 files changed, 15 insertions(+), 10 deletions(-)
 create mode 100644 lib/cobalt/assert.wrappers
configure.ac +7 -5
index f61543a..5b9f518 100644
@@ -824,17 +824,19 @@ dnl Build wrapping information. XENO_POSIX_WRAPPERS lists all wrapping
 dnl directives in a format the linker understands, for building the
 dnl in-tree executables which require POSIX symbol wrapping.
 
+   assert_wrappers="$topdir/lib/cobalt/assert.wrappers"
    cobalt_wrappers="$topdir/lib/cobalt/cobalt.wrappers"
    if [[ $ac_cv_ld_file_option = yes ]]; then
-	XENO_POSIX_WRAPPERS="-Wl,@$cobalt_wrappers"
+	XENO_POSIX_WRAPPERS="-Wl,@$assert_wrappers -Wl,@$cobalt_wrappers"
    else
-	XENO_POSIX_WRAPPERS=`while read wrap_option symbol ; do \
-			echo -n "-Wl,$wrap_option,$symbol " ; \
-		done < $cobalt_wrappers`
+	XENO_POSIX_WRAPPERS=`cat $assert_wrappers $cobalt_wrappers | \
+			while read wrap_option symbol ; do \
+				echo -n "-Wl,$wrap_option,$symbol " ; \
+			done`
    fi
 
    AC_SUBST(XENO_POSIX_WRAPPERS)
-   AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$cobalt_wrappers"])
+   AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$assert_wrappers $cobalt_wrappers"])
 fi
 
 dnl
debian/libxenomai-dev.install +1 -0
index 7b107cb..6d7eb7b 100644
@@ -2,5 +2,6 @@ usr/include
 usr/lib/*.la
 usr/lib/*.a
 usr/lib/*.so
+usr/lib/assert.wrappers
 usr/lib/cobalt.wrappers
 usr/lib/dynlist.ld
lib/cobalt/Makefile.am +3 -1
index 576122d..459b207 100644
@@ -46,10 +46,12 @@ libcobalt_la_CPPFLAGS =			\
 install-data-local:
 	$(mkinstalldirs) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) $(srcdir)/cobalt.wrappers $(DESTDIR)$(libdir)
+	$(INSTALL_DATA) $(srcdir)/assert.wrappers $(DESTDIR)$(libdir)
 
 uninstall-local:
 	$(RM) $(DESTDIR)$(libdir)/cobalt.wrappers
+	$(RM) $(DESTDIR)$(libdir)/assert.wrappers
 
-EXTRA_DIST = cobalt.wrappers
+EXTRA_DIST = cobalt.wrappers assert.wrappers
 
 SUBDIRS = arch
lib/cobalt/assert.wrappers new file +2 -0
new file mode 100644
index 0000000..7164858
@@ -0,0 +1,2 @@
+--wrap malloc
+--wrap free
lib/cobalt/cobalt.wrappers +0 -2
index bf7a810..91bd5ef 100644
@@ -94,8 +94,6 @@
 --wrap fclose
 --wrap syslog
 --wrap vsyslog
---wrap malloc
---wrap free
 --wrap gettimeofday
 --wrap __vfprintf_chk
 --wrap __vprintf_chk
scripts/xeno-config-cobalt.in +2 -2
index d102d04..3e1f64c 100644
@@ -235,8 +235,8 @@ if test x$do_ldflags = xy; then
 	echo "no API specified, missing --skin before --ldflags" 1>&2
 	exit 1
     fi
-    ldflags=
-    test x$compat = xy && ldflags="-ltrank "
+    ldflags="`dump_wrappers assert.wrappers`"
+    test x$compat = xy && ldflags="-ltrank $ldflags"
     copperplate=
     for skin in $skin_list; do
 	case "$skin" in
Signature · 1 line
2.10.2
#2 lore raw

PATCH 3/3 lib/cobalt: wrap CXXABI One-time Constructor functions

In reply to Henning Schild

The implementation of these functions uses locks and has the potential to trigger a SIGXCPU when contended. Wrap them with assert_nrt so they reliably cause a switch when used in the rt context.

---
 lib/cobalt/assert.wrappers  |  3 +++
 lib/cobalt/assert_context.c | 19 +++++++++++++++++++
 lib/cobalt/internal.h       | 12 ++++++++++++
 lib/cobalt/wrappers.c       | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+)
lib/cobalt/assert.wrappers +3 -0
index 7164858..65320ab 100644
@@ -1,2 +1,5 @@
 --wrap malloc
 --wrap free
+--wrap __cxa_guard_acquire
+--wrap __cxa_guard_release
+--wrap __cxa_guard_abort
lib/cobalt/assert_context.c +19 -0
index 2085953..fd18d6b 100644
@@ -66,3 +66,22 @@ COBALT_IMPL(void, free, (void *ptr))
 	assert_nrt();
 	__STD(free(ptr));
 }
+
+/* CXXABI 3.3.2 One-time Construction API */
+COBALT_IMPL(int, __cxa_guard_acquire, (__guard *g))
+{
+	assert_nrt();
+	return __STD(__cxa_guard_acquire(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_release, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_release(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_abort, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_abort(g));
+}
lib/cobalt/internal.h +12 -0
index 1531901..8874f71 100644
@@ -93,4 +93,16 @@ extern int __cobalt_std_fifo_minpri,
 extern int __cobalt_std_rr_minpri,
 	   __cobalt_std_rr_maxpri;
 
+#ifdef __ARM_EABI__
+typedef uint32_t __guard;
+#else
+typedef uint64_t __guard;
+#endif
+int __real___cxa_guard_acquire(__guard*);
+void __real___cxa_guard_release(__guard*);
+void __real___cxa_guard_abort(__guard*);
+int __cxa_guard_acquire(__guard*);
+void __cxa_guard_release(__guard*);
+void __cxa_guard_abort(__guard*);
+
 #endif /* _LIB_COBALT_INTERNAL_H */
lib/cobalt/wrappers.c +37 -0
index 43ca630..fa7fbcb 100644
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <boilerplate/compiler.h>
+#include <internal.h>
 
 /* sched */
 __weak
@@ -544,3 +545,39 @@ int __real_usleep(useconds_t usec)
 {
 	return usleep(usec);
 }
+
+__weak
+int __real___cxa_guard_acquire(__guard *g)
+{
+	return __cxa_guard_acquire(g);
+}
+
+__weak
+void __real___cxa_guard_release(__guard *g)
+{
+	return __cxa_guard_release(g);
+}
+
+__weak
+void __real___cxa_guard_abort(__guard *g)
+{
+	return __cxa_guard_abort(g);
+}
+
+__weak
+int __cxa_guard_acquire(__guard *g)
+{
+	return 0;
+}
+
+__weak
+void __cxa_guard_release(__guard *g)
+{
+	return;
+}
+
+__weak
+void __cxa_guard_abort(__guard *g)
+{
+	return;
+}
Signature · 1 line
2.10.2
#3 lore raw

Re: [Xenomai] [PATCH 3/3] lib/cobalt: wrap CXXABI One-time Constructor functions

Quoted 55 lines · On Wed, 25 Jan 2017 16:08:37 +0100 Henning Schild <[email protected]>…

The implementation of these functions uses locks and has the potential to trigger a SIGXCPU when contended. Wrap them with assert_nrt so they reliably cause a switch when used in the rt context.

---
 lib/cobalt/assert.wrappers  |  3 +++
 lib/cobalt/assert_context.c | 19 +++++++++++++++++++
 lib/cobalt/internal.h       | 12 ++++++++++++
 lib/cobalt/wrappers.c       | 37

+++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+)

lib/cobalt/assert.wrappers +3 -0
index 7164858..65320ab 100644
@@ -1,2 +1,5 @@
 --wrap malloc
 --wrap free
+--wrap __cxa_guard_acquire
+--wrap __cxa_guard_release
+--wrap __cxa_guard_abort
lib/cobalt/assert_context.c +19 -0
index 2085953..fd18d6b 100644
@@ -66,3 +66,22 @@ COBALT_IMPL(void, free, (void *ptr))
 	assert_nrt();
 	__STD(free(ptr));
 }
+
+/* CXXABI 3.3.2 One-time Construction API */
+COBALT_IMPL(int, __cxa_guard_acquire, (__guard *g))
+{
+	assert_nrt();
+	return __STD(__cxa_guard_acquire(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_release, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_release(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_abort, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_abort(g));
+}
lib/cobalt/internal.h +0 -0
index 1531901..8874f71 100644

lib/cobalt/internal.h extern int __cobalt_std_fifo_minpri, · line 100

Quoted 8 lines
lib/cobalt/internal.h +5 -0
@@ -93,4 +93,16 @@ extern int __cobalt_std_fifo_minpri,
 extern int __cobalt_std_rr_minpri,
 	   __cobalt_std_rr_maxpri;
 
+#ifdef __ARM_EABI__
+typedef uint32_t __guard;
+#else
+typedef uint64_t __guard;
+#endif

That should do the trick for all architectures. ARM seems to be the only one that does not use 64bits and that only in the EABI case. AArch64 uses a 64bit guard.
I basically looked at clang and gcc code. And tested i686 and x86_64 myself.

Quoted 60 lines
lib/cobalt/internal.h +7 -0
+int __real___cxa_guard_acquire(__guard*);
+void __real___cxa_guard_release(__guard*);
+void __real___cxa_guard_abort(__guard*);
+int __cxa_guard_acquire(__guard*);
+void __cxa_guard_release(__guard*);
+void __cxa_guard_abort(__guard*);
+
 #endif /* _LIB_COBALT_INTERNAL_H */
lib/cobalt/wrappers.c +37 -0
index 43ca630..fa7fbcb 100644
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <boilerplate/compiler.h>
+#include <internal.h>
 
 /* sched */
 __weak
@@ -544,3 +545,39 @@ int __real_usleep(useconds_t usec)
 {
 	return usleep(usec);
 }
+
+__weak
+int __real___cxa_guard_acquire(__guard *g)
+{
+	return __cxa_guard_acquire(g);
+}
+
+__weak
+void __real___cxa_guard_release(__guard *g)
+{
+	return __cxa_guard_release(g);
+}
+
+__weak
+void __real___cxa_guard_abort(__guard *g)
+{
+	return __cxa_guard_abort(g);
+}
+
+__weak
+int __cxa_guard_acquire(__guard *g)
+{
+	return 0;
+}
+
+__weak
+void __cxa_guard_release(__guard *g)
+{
+	return;
+}
+
+__weak
+void __cxa_guard_abort(__guard *g)
+{
+	return;
+}
#4 lore raw

Re: [Xenomai] [PATCH 3/3] lib/cobalt: wrap CXXABI One-time Constructor functions

In reply to Henning Schild

Am Wed, 25 Jan 2017 16:08:37 +0100
schrieb Henning Schild <[email protected]>:

Quoted 95 lines

The implementation of these functions uses locks and has the potential to trigger a SIGXCPU when contended. Wrap them with assert_nrt so they reliably cause a switch when used in the rt context.

---
 lib/cobalt/assert.wrappers  |  3 +++
 lib/cobalt/assert_context.c | 19 +++++++++++++++++++
 lib/cobalt/internal.h       | 12 ++++++++++++
 lib/cobalt/wrappers.c       | 37

+++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+)

lib/cobalt/assert.wrappers +3 -0
index 7164858..65320ab 100644
@@ -1,2 +1,5 @@
 --wrap malloc
 --wrap free
+--wrap __cxa_guard_acquire
+--wrap __cxa_guard_release
+--wrap __cxa_guard_abort
lib/cobalt/assert_context.c +19 -0
index 2085953..fd18d6b 100644
@@ -66,3 +66,22 @@ COBALT_IMPL(void, free, (void *ptr))
 	assert_nrt();
 	__STD(free(ptr));
 }
+
+/* CXXABI 3.3.2 One-time Construction API */
+COBALT_IMPL(int, __cxa_guard_acquire, (__guard *g))
+{
+	assert_nrt();
+	return __STD(__cxa_guard_acquire(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_release, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_release(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_abort, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_abort(g));
+}
lib/cobalt/internal.h +12 -0
index 1531901..8874f71 100644
@@ -93,4 +93,16 @@ extern int __cobalt_std_fifo_minpri,
 extern int __cobalt_std_rr_minpri,
 	   __cobalt_std_rr_maxpri;
 
+#ifdef __ARM_EABI__
+typedef uint32_t __guard;
+#else
+typedef uint64_t __guard;
+#endif
+int __real___cxa_guard_acquire(__guard*);
+void __real___cxa_guard_release(__guard*);
+void __real___cxa_guard_abort(__guard*);
+int __cxa_guard_acquire(__guard*);
+void __cxa_guard_release(__guard*);
+void __cxa_guard_abort(__guard*);
+
 #endif /* _LIB_COBALT_INTERNAL_H */
lib/cobalt/wrappers.c +9 -0
index 43ca630..fa7fbcb 100644
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <boilerplate/compiler.h>
+#include <internal.h>
 
 /* sched */
 __weak
@@ -544,3 +545,39 @@ int __real_usleep(useconds_t usec)
 {
 	return usleep(usec);
 }
+
+__weak
+int __real___cxa_guard_acquire(__guard *g)
+{
+	return __cxa_guard_acquire(g);
+}
+
+__weak

lib/cobalt/wrappers.c int __real_usleep(useconds_t usec) · line 565

Quoted 10 lines
lib/cobalt/wrappers.c +10 -0
+void __real___cxa_guard_release(__guard *g)
+{
+	return __cxa_guard_release(g);
+}
+
+__weak
+void __real___cxa_guard_abort(__guard *g)
+{
+	return __cxa_guard_abort(g);
+}

The following weak symbols are not always replaced by the strong ones from libstdc++. They are just here for C-code and can now break C++.

Quoted 7 lines
lib/cobalt/wrappers.c +7 -0
+__weak
+int __cxa_guard_acquire(__guard *g)
+{
+	return 0;
+}
+
+__weak

lib/cobalt/wrappers.c int __real_usleep(useconds_t usec) · line 583

Quoted 10 lines
lib/cobalt/wrappers.c +10 -0
+void __cxa_guard_release(__guard *g)
+{
+	return;
+}
+
+__weak
+void __cxa_guard_abort(__guard *g)
+{
+	return;
+}

For dynamically linked executables you do need "LD_DYNAMIC_WEAK" in your env and for static linking "--whole-archive". Otherwise you might end up using these weak dummies.

This patch introduced a critical bug! I will come up with a fix but wanted to report the problem first.

Henning

#5 lore raw

Re: [Xenomai] [PATCH 3/3] lib/cobalt: wrap CXXABI One-time Constructor functions

Quoted 134 lines · Henning Schild

Am Wed, 25 Jan 2017 16:08:37 +0100
schrieb Henning Schild <[email protected]>:

Quoted 95 lines

The implementation of these functions uses locks and has the potential to trigger a SIGXCPU when contended. Wrap them with assert_nrt so they reliably cause a switch when used in the rt context.

---
 lib/cobalt/assert.wrappers  |  3 +++
 lib/cobalt/assert_context.c | 19 +++++++++++++++++++
 lib/cobalt/internal.h       | 12 ++++++++++++
 lib/cobalt/wrappers.c       | 37

+++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+)

lib/cobalt/assert.wrappers +3 -0
index 7164858..65320ab 100644
@@ -1,2 +1,5 @@
 --wrap malloc
 --wrap free
+--wrap __cxa_guard_acquire
+--wrap __cxa_guard_release
+--wrap __cxa_guard_abort
lib/cobalt/assert_context.c +19 -0
index 2085953..fd18d6b 100644
@@ -66,3 +66,22 @@ COBALT_IMPL(void, free, (void *ptr))
 	assert_nrt();
 	__STD(free(ptr));
 }
+
+/* CXXABI 3.3.2 One-time Construction API */
+COBALT_IMPL(int, __cxa_guard_acquire, (__guard *g))
+{
+	assert_nrt();
+	return __STD(__cxa_guard_acquire(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_release, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_release(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_abort, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_abort(g));
+}
lib/cobalt/internal.h +12 -0
index 1531901..8874f71 100644
@@ -93,4 +93,16 @@ extern int __cobalt_std_fifo_minpri,
 extern int __cobalt_std_rr_minpri,
 	   __cobalt_std_rr_maxpri;
 
+#ifdef __ARM_EABI__
+typedef uint32_t __guard;
+#else
+typedef uint64_t __guard;
+#endif
+int __real___cxa_guard_acquire(__guard*);
+void __real___cxa_guard_release(__guard*);
+void __real___cxa_guard_abort(__guard*);
+int __cxa_guard_acquire(__guard*);
+void __cxa_guard_release(__guard*);
+void __cxa_guard_abort(__guard*);
+
 #endif /* _LIB_COBALT_INTERNAL_H */
lib/cobalt/wrappers.c +9 -0
index 43ca630..fa7fbcb 100644
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <boilerplate/compiler.h>
+#include <internal.h>
 
 /* sched */
 __weak
@@ -544,3 +545,39 @@ int __real_usleep(useconds_t usec)
 {
 	return usleep(usec);
 }
+
+__weak
+int __real___cxa_guard_acquire(__guard *g)
+{
+	return __cxa_guard_acquire(g);
+}
+
+__weak

lib/cobalt/wrappers.c int __real_usleep(useconds_t usec) · line 565

Quoted 10 lines
lib/cobalt/wrappers.c +10 -0
+void __real___cxa_guard_release(__guard *g)
+{
+	return __cxa_guard_release(g);
+}
+
+__weak
+void __real___cxa_guard_abort(__guard *g)
+{
+	return __cxa_guard_abort(g);
+}

The following weak symbols are not always replaced by the strong ones from libstdc++. They are just here for C-code and can now break C++.

Quoted 7 lines
lib/cobalt/wrappers.c +7 -0
+__weak
+int __cxa_guard_acquire(__guard *g)
+{
+	return 0;
+}
+
+__weak

lib/cobalt/wrappers.c int __real_usleep(useconds_t usec) · line 583

Quoted 10 lines
lib/cobalt/wrappers.c +10 -0
+void __cxa_guard_release(__guard *g)
+{
+	return;
+}
+
+__weak
+void __cxa_guard_abort(__guard *g)
+{
+	return;
+}

For dynamically linked executables you do need "LD_DYNAMIC_WEAK" in your env and for static linking "--whole-archive". Otherwise you might end up using these weak dummies.

Quoted 3 lines

This patch introduced a critical bug! I will come up with a fix but wanted to report the problem first.

Ok, thanks. I'm holding 3.0.4 until this is fixed.

Signature · 1 line
Philippe.
#6 lore raw

PATCH 1/2 cobalt: fix for incorrect assert wrappers commit

Fixes ebc039b62c40e

Be consistent with wrapping the asserts with every compiler invokation. Now you can add arbitrary symbols to assert.wrappers without the linker complaining about them missing.
That problem lead me to include weak dummies for libstdc++ functions in be90f09cf2770 .

---
 configure.ac         | 13 ++++++++++---
 scripts/wrap-link.sh |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)
configure.ac +10 -3
index 4792e46..70990d2 100644
@@ -799,9 +799,14 @@ dnl in-tree executables which require POSIX symbol wrapping.
    assert_wrappers="$topdir/lib/cobalt/assert.wrappers"
    cobalt_wrappers="$topdir/lib/cobalt/cobalt.wrappers"
    if [[ $ac_cv_ld_file_option = yes ]]; then
-	XENO_POSIX_WRAPPERS="-Wl,@$assert_wrappers -Wl,@$cobalt_wrappers"
+	XENO_POSIX_WRAPPERS="-Wl,@$cobalt_wrappers"
+	XENO_ASSERT_WRAPPERS="-Wl,@$assert_wrappers"
    else
-	XENO_POSIX_WRAPPERS=`cat $assert_wrappers $cobalt_wrappers | \
+	XENO_POSIX_WRAPPERS=`cat $cobalt_wrappers | \
+			while read wrap_option symbol ; do \
+				echo -n "-Wl,$wrap_option,$symbol " ; \
+			done`
+	XENO_ASSERT_WRAPPERS=`cat $assert_wrappers | \
 			while read wrap_option symbol ; do \
 				echo -n "-Wl,$wrap_option,$symbol " ; \
 			done`
@@ -809,13 +814,15 @@ dnl in-tree executables which require POSIX symbol wrapping.
 
    AC_SUBST(XENO_POSIX_WRAPPERS)
    AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$assert_wrappers $cobalt_wrappers"])
+else
+   XENO_ASSERT_WRAPPERS=""
 fi
 
 dnl
 dnl Build the Makefiles
 dnl
 
-XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap-internal.o'" -Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld"
+XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap-internal.o'" -Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld $XENO_ASSERT_WRAPPERS"
 AC_SUBST(XENO_AUTOINIT_LDFLAGS)
 
 XENO_CORE_LIB=$rtcore_type/lib${rtcore_type}.la
scripts/wrap-link.sh +1 -1
index 1b8c3f4..0e50586 100755
@@ -138,7 +138,7 @@ while test $# -gt 0; do
 	    next_is_wrapped_symbol=:
 	    ;;
 
-	-Wl,--wrap,main|-Wl,--wrap=main|-Wl,--dynamic-list=*)
+	-Wl,--wrap,main|-Wl,--wrap=main|-Wl,--dynamic-list=*|-Wl,@*assert.wrappers)
 	    # special case so that we can interpose on the main()
 	    # routine. For this we need this wrapping to take place in
 	    # the second stage.
Signature · 1 line
2.10.2
#7 lore raw

PATCH 2/2 lib/cobalt: wrap CXXABI One-time Constructor functions

The implementation of these functions uses locks and has the potential to trigger a SIGXCPU when contended. Wrap them with assert_nrt so they reliably cause a switch when used in the rt context.

This is a corrected version of: be90f09cf2770
which got reverted in: 0ef9dbd42d16d

---
 lib/cobalt/assert.wrappers  |  3 +++
 lib/cobalt/assert_context.c | 19 +++++++++++++++++++
 lib/cobalt/internal.h       | 12 ++++++++++++
 lib/cobalt/wrappers.c       | 19 +++++++++++++++++++
 4 files changed, 53 insertions(+)
lib/cobalt/assert.wrappers +3 -0
index 7164858..65320ab 100644
@@ -1,2 +1,5 @@
 --wrap malloc
 --wrap free
+--wrap __cxa_guard_acquire
+--wrap __cxa_guard_release
+--wrap __cxa_guard_abort
lib/cobalt/assert_context.c +19 -0
index 2085953..fd18d6b 100644
@@ -66,3 +66,22 @@ COBALT_IMPL(void, free, (void *ptr))
 	assert_nrt();
 	__STD(free(ptr));
 }
+
+/* CXXABI 3.3.2 One-time Construction API */
+COBALT_IMPL(int, __cxa_guard_acquire, (__guard *g))
+{
+	assert_nrt();
+	return __STD(__cxa_guard_acquire(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_release, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_release(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_abort, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_abort(g));
+}
lib/cobalt/internal.h +12 -0
index fee3fe1..9f58c6a 100644
@@ -73,4 +73,16 @@ void cobalt_check_features(struct cobalt_featinfo *finfo);
 
 extern struct sigaction __cobalt_orig_sigdebug;
 
+#ifdef __ARM_EABI__
+typedef uint32_t __guard;
+#else
+typedef uint64_t __guard;
+#endif
+int __real___cxa_guard_acquire(__guard*);
+void __real___cxa_guard_release(__guard*);
+void __real___cxa_guard_abort(__guard*);
+int __cxa_guard_acquire(__guard*);
+void __cxa_guard_release(__guard*);
+void __cxa_guard_abort(__guard*);
+
 #endif /* _LIB_COBALT_INTERNAL_H */
lib/cobalt/wrappers.c +19 -0
index 09c74e5..c43772c 100644
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <boilerplate/compiler.h>
+#include <internal.h>
 
 /* sched */
 __weak
@@ -532,3 +533,21 @@ unsigned int __real_sleep(unsigned int seconds)
 {
 	return sleep(seconds);
 }
+
+__weak
+int __real___cxa_guard_acquire(__guard *g)
+{
+	return __cxa_guard_acquire(g);
+}
+
+__weak
+void __real___cxa_guard_release(__guard *g)
+{
+	return __cxa_guard_release(g);
+}
+
+__weak
+void __real___cxa_guard_abort(__guard *g)
+{
+	return __cxa_guard_abort(g);
+}
Signature · 1 line
2.10.2
#8 lore raw

Re: [Xenomai] [PATCH 1/2] cobalt: fix for incorrect assert wrappers commit

In reply to Henning Schild

configure.ac dnl in-tree executables which require POSIX symbol wrapping. · line 826

Quoted 4 lines · Henning Schild
configure.ac +1 -1
-XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap-internal.o'" -Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld"
+XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap-internal.o'" -Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld $XENO_ASSERT_WRAPPERS"
 AC_SUBST(XENO_AUTOINIT_LDFLAGS)

XENO_AUTOINIT_LDFLAGS is only used internally, inside the Xenomai tree for building utilities and test programs which may want the auto-bootstrap feature on. Is this the intent?

Signature · 1 line
Philippe.
#9 lore raw

Re: [Xenomai] [PATCH 1/2] cobalt: fix for incorrect assert wrappers commit

Am Mon, 6 Mar 2017 17:18:23 +0100
schrieb Philippe Gerum <[email protected]>:

Quoted 11 lines · Henning Schild
Quoted 6 lines
(quoted diff) +1 -3
-XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap-internal.o'"
-Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld"
+XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap-internal.o'"
-Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld

$XENO_ASSERT_WRAPPERS" AC_SUBST(XENO_AUTOINIT_LDFLAGS)

XENO_AUTOINIT_LDFLAGS is only used internally, inside the Xenomai tree for building utilities and test programs which may want the auto-bootstrap feature on. Is this the intent?

Honestly, i am not sure where to best put that. And i do not know what the auto-bootstrap feature is. It does solve build problems in the tree i.e. for latency and smokey_net_server.
The process of coming up with this version was a lot of looking at "make V=1" and pattern matching to where the flags came from.

The build issues can be seen when applying 2/2 from this series on top of current master 027898e4732cb5de.

After all the CXXAbi patch should have never come with those dummies. I just put them in because of the above build-problems assuming they would be natural for C-code and that weak symbols could not hurt. Both those assumption where wrong ...

Would be nice if you could look at the problems and suggest a better place for the adjusted LDFLGAS.

regards,
Henning

#10 lore raw

Re: [Xenomai] [PATCH 3/3] lib/cobalt: wrap CXXABI One-time Constructor functions

In reply to Henning Schild

Hey,

i am still not sure how to fix that in an elegant way. Depending on the linking order the weak symbol will be picked regardless of another strong one.

https://en.wikipedia.org/wiki/Weak_symbol#Limitations

Now these dummies are just there to satisfy the linker when C is used and libstdc++ will not be linked. But when we build C++ it would be best those dummies would not be there in the first place.

I did not come up with an idea to handle the language conflict transparently.
One hack that came to mind is to just always link to stdc++, but that pulls in a pretty nasty dependency for C-code.
Another one is using dlsym(RTLD_NEXT, __func__) in the dummies, but that requires -ldl and still causes trouble with static linking.

Maybe someone has an idea how that could be done? Otherwise i guess it will be "-x c++" for xeno-config to include the c++ wrappers.

Henning

Am Thu, 2 Mar 2017 10:56:01 +0100
schrieb Henning Schild <[email protected]>:

Quoted 144 lines

Am Wed, 25 Jan 2017 16:08:37 +0100
schrieb Henning Schild <[email protected]>:

Quoted 96 lines

The implementation of these functions uses locks and has the potential to trigger a SIGXCPU when contended. Wrap them with assert_nrt so they reliably cause a switch when used in the rt context.

---
 lib/cobalt/assert.wrappers  |  3 +++
 lib/cobalt/assert_context.c | 19 +++++++++++++++++++
 lib/cobalt/internal.h       | 12 ++++++++++++
 lib/cobalt/wrappers.c       | 37

+++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+)

lib/cobalt/assert.wrappers +3 -0
index 7164858..65320ab 100644
@@ -1,2 +1,5 @@
 --wrap malloc
 --wrap free
+--wrap __cxa_guard_acquire
+--wrap __cxa_guard_release
+--wrap __cxa_guard_abort
(quoted diff) +0 -0

b/lib/cobalt/assert_context.c index 2085953..fd18d6b 100644

lib/cobalt/assert_context.c +19 -0
@@ -66,3 +66,22 @@ COBALT_IMPL(void, free, (void *ptr))
 	assert_nrt();
 	__STD(free(ptr));
 }
+
+/* CXXABI 3.3.2 One-time Construction API */
+COBALT_IMPL(int, __cxa_guard_acquire, (__guard *g))
+{
+	assert_nrt();
+	return __STD(__cxa_guard_acquire(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_release, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_release(g));
+}
+
+COBALT_IMPL(void, __cxa_guard_abort, (__guard *g))
+{
+	assert_nrt();
+	__STD(__cxa_guard_abort(g));
+}
lib/cobalt/internal.h +12 -0
index 1531901..8874f71 100644
@@ -93,4 +93,16 @@ extern int __cobalt_std_fifo_minpri,
 extern int __cobalt_std_rr_minpri,
 	   __cobalt_std_rr_maxpri;
 
+#ifdef __ARM_EABI__
+typedef uint32_t __guard;
+#else
+typedef uint64_t __guard;
+#endif
+int __real___cxa_guard_acquire(__guard*);
+void __real___cxa_guard_release(__guard*);
+void __real___cxa_guard_abort(__guard*);
+int __cxa_guard_acquire(__guard*);
+void __cxa_guard_release(__guard*);
+void __cxa_guard_abort(__guard*);
+
 #endif /* _LIB_COBALT_INTERNAL_H */
lib/cobalt/wrappers.c +9 -0
index 43ca630..fa7fbcb 100644
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <boilerplate/compiler.h>
+#include <internal.h>
 
 /* sched */
 __weak
@@ -544,3 +545,39 @@ int __real_usleep(useconds_t usec)
 {
 	return usleep(usec);
 }
+
+__weak
+int __real___cxa_guard_acquire(__guard *g)
+{
+	return __cxa_guard_acquire(g);
+}
+
+__weak

lib/cobalt/wrappers.c int __real_usleep(useconds_t usec) · line 565

Quoted 10 lines
lib/cobalt/wrappers.c +10 -0
+void __real___cxa_guard_release(__guard *g)
+{
+	return __cxa_guard_release(g);
+}
+
+__weak
+void __real___cxa_guard_abort(__guard *g)
+{
+	return __cxa_guard_abort(g);
+}  

The following weak symbols are not always replaced by the strong ones from libstdc++. They are just here for C-code and can now break C++.

Quoted 7 lines
lib/cobalt/wrappers.c +7 -0
+__weak
+int __cxa_guard_acquire(__guard *g)
+{
+	return 0;
+}
+
+__weak

lib/cobalt/wrappers.c int __real_usleep(useconds_t usec) · line 583

Quoted 10 lines
lib/cobalt/wrappers.c +10 -0
+void __cxa_guard_release(__guard *g)
+{
+	return;
+}
+
+__weak
+void __cxa_guard_abort(__guard *g)
+{
+	return;
+}  

For dynamically linked executables you do need "LD_DYNAMIC_WEAK" in your env and for static linking "--whole-archive". Otherwise you might end up using these weak dummies.

This patch introduced a critical bug! I will come up with a fix but wanted to report the problem first.

Henning

_______________________________________________
Xenomai mailing list
[email protected]
https://xenomai.org/mailman/listinfo/xenomai