Skip to contentSkip to conversation

Refactor management of auto-shadowing, TLS and dlopen

PATCH In review Jan Kiszka 2 participants 3 messages Nov 21, 2008 – Nov 22, 2008

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 Refactor management of auto-shadowing, TLS and dlopen

This patch implements my suggestion to replace configures's --without-__thread switch with a more focused one: --enable-dlopen-skins When enabled, initial-exec TLS support is turned off as well as auto-shadowing done by the POSIX skin lib. This avoids bad interaction with the context of dlopen and the already running process in general, while also clarifying the actual choice here.

Jan

PS: Patch might be best applied in two steps, but I was too lazy to split up now.

---
 ChangeLog              |    6 ++++++
 configure.in           |   19 +++++++++++++------
 src/skins/posix/init.c |   45 +++++++++++++++++++++++++++++----------------
 3 files changed, 48 insertions(+), 22 deletions(-)
configure.in +13 -6
Index: xenomai/configure.in
===================================================================
@@ -763,14 +763,21 @@ AC_CHECK_FUNCS([shm_open shm_unlink])
 LIBS="$save_LIBS"
 
 XENO_DLOPEN_CONSTRAINT=
-AC_ARG_WITH([__thread],
-	    AC_HELP_STRING([--without-__thread],
-			   [do not use TLS features (allows for dlopen'ing Xenomai libs)]),
-	    [use__thread=$withval],
-	    [use__thread=yes])
+AC_MSG_CHECKING(whether to enable dlopen support for skin libraries)
+AC_ARG_ENABLE(dlopen-skins,
+	AC_HELP_STRING([--enable-dlopen-skins], [Disable TLS features and automatic
+main thread mapping by the POSIX skin to allows dlopen'ing Xenomai libs.]),
+	[case "$enableval" in
+	y | yes) CONFIG_XENO_LIBS_DLOPEN=y ;;
+	*) unset CONFIG_XENO_LIBS_DLOPEN ;;
+	esac])
+AC_MSG_RESULT(${CONFIG_XENO_LIBS_DLOPEN:-no})
+if test x$CONFIG_XENO_LIBS_DLOPEN = xy; then
+	AC_DEFINE(CONFIG_XENO_LIBS_DLOPEN,1,[config])
+fi
 
 dnl Check whether the compiler supports the __thread keyword.
-if test "x$use__thread" != xno; then
+if test "x$CONFIG_XENO_LIBS_DLOPEN" != xy; then
 	AC_CACHE_CHECK([for __thread], libc_cv_gcc___thread,
 	[cat > conftest.c <<\EOF
 __thread int a __attribute__ ((tls_model ("initial-exec"))) = 42;
src/skins/posix/init.c +29 -16

64 lines not on this page · raw message

ChangeLog +6 -0
Index: xenomai/ChangeLog
===================================================================
@@ -1,5 +1,11 @@
 2008-11-21  Jan Kiszka  <[email protected]>
 
+	* configure.in: Convert --without-__thread into
+	--enable-dlopen-skins.
+
+	* src/skins/posix/init.c: Don't perform auto-shadowing if we may
+	be loaded via dlopen.
+
 	* configure.in, src/skins/*/Makefile.am: Mark libs with nodlopen
 	if initial-exec __thread variables are used.
 
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 ES-OS
Corporate Competence Center Embedded Linux
#1 lore raw

src/skins/posix/init.c void __init_posix_interface(void) · line 76

Quoted 5 lines · Jan Kiszka
src/skins/posix/init.c +1 -0
+#ifndef CONFIG_XENO_POSIX_AUTO_MLOCKALL
 	if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
 		perror("Xenomai Posix skin init: mlockall");
 		exit(EXIT_FAILURE);
 	}

Errr... I do not get it, the mlockall should take place if AUTO_MLOCKALL is set, no ?

+ struct sched_param parm = { .sched_priority = 0 };

I do not like the everything-on-one-line style. And are we sure this will work if sched_priority is a macro ?

Signature · 1 line
                                                 Gilles.
author
#2 lore raw
Quoted 9 lines · Gilles Chanteperdrix

Review

Quoted 5 lines · Jan Kiszka
(quoted diff) +1 -0
+#ifndef CONFIG_XENO_POSIX_AUTO_MLOCKALL
 	if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
 		perror("Xenomai Posix skin init: mlockall");
 		exit(EXIT_FAILURE);
 	}

Errr... I do not get it, the mlockall should take place if AUTO_MLOCKALL is set, no ?

Typo. Noticed it before posting, but I forgot to include the refreshed patch.

Quoted 5 lines
(quoted diff) +1 -0
+		struct sched_param parm = { .sched_priority = 0 };

I do not like the everything-on-one-line style. And are we sure this will work if sched_priority is a macro ?

If parm.sched_priority can be referenced (and that's what the spec requires), the above works as well, even if sched_priority resolves to something like "__hidden_struct.__prio".

Regarding detection of denied dlopen: The 'nodlopen' marker my other patch introduces will give an error message like "libpthread_rt.so.1:
shared object cannot be dlopen()ed" - if the caller is clever enough to use dlerror. We can't configure that message (it linker generated), all we could do is to add a few words about it to the TROUBLESHOOTING guide.

Jan

---
 ChangeLog              |    6 ++++++
 configure.in           |   19 +++++++++++++------
 src/skins/posix/init.c |   45 +++++++++++++++++++++++++++++----------------
 3 files changed, 48 insertions(+), 22 deletions(-)
configure.in +13 -6
Index: xenomai/configure.in
===================================================================
@@ -763,14 +763,21 @@ AC_CHECK_FUNCS([shm_open shm_unlink])
 LIBS="$save_LIBS"
 
 XENO_DLOPEN_CONSTRAINT=
-AC_ARG_WITH([__thread],
-	    AC_HELP_STRING([--without-__thread],
-			   [do not use TLS features (allows for dlopen'ing Xenomai libs)]),
-	    [use__thread=$withval],
-	    [use__thread=yes])
+AC_MSG_CHECKING(whether to enable dlopen support for skin libraries)
+AC_ARG_ENABLE(dlopen-skins,
+	AC_HELP_STRING([--enable-dlopen-skins], [Disable TLS features and automatic
+main thread mapping by the POSIX skin to allows dlopen'ing Xenomai libs.]),
+	[case "$enableval" in
+	y | yes) CONFIG_XENO_LIBS_DLOPEN=y ;;
+	*) unset CONFIG_XENO_LIBS_DLOPEN ;;
+	esac])
+AC_MSG_RESULT(${CONFIG_XENO_LIBS_DLOPEN:-no})
+if test x$CONFIG_XENO_LIBS_DLOPEN = xy; then
+	AC_DEFINE(CONFIG_XENO_LIBS_DLOPEN,1,[config])
+fi
 
 dnl Check whether the compiler supports the __thread keyword.
-if test "x$use__thread" != xno; then
+if test "x$CONFIG_XENO_LIBS_DLOPEN" != xy; then
 	AC_CACHE_CHECK([for __thread], libc_cv_gcc___thread,
 	[cat > conftest.c <<\EOF
 __thread int a __attribute__ ((tls_model ("initial-exec"))) = 42;
src/skins/posix/init.c +29 -16

64 lines not on this page · raw message

ChangeLog +6 -0
Index: xenomai/ChangeLog
===================================================================
@@ -1,5 +1,11 @@
 2008-11-21  Jan Kiszka  <[email protected]>
 
+	* configure.in: Convert --without-__thread into
+	--enable-dlopen-skins.
+
+	* src/skins/posix/init.c: Don't perform auto-shadowing if we may
+	be loaded via dlopen.
+
 	* configure.in, src/skins/*/Makefile.am: Mark libs with nodlopen
 	if initial-exec __thread variables are used.