Module: xenomai-3
Branch: next
Commit: 1fbe3f3797c1e15121a8243ca9fa05dd7e7d2128
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1fbe3f3797c1e15121a8243ca9fa05dd7e7d2128

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Aug 26 21:21:40 2016 +0200

boilerplate: allow for auto-init of external shared libraries

3rd-party shared libraries for which Xenomai auto-initialization is
required must include a position-independent version of the bootstrap
module.

This means that we need to export a PIC object such libraries can
include, in addition to a non-PIC object to be linked in regular
executables as usual. Such objects are available as
@libdir@/xenomai/bootstrap-pic.o and @libdir@/xenomai/bootstrap.o
respectively.

xeno-config* scripts now accept the --auto-init-solib option to emit
the proper link directives for including the PIC bootstrap module into
shared libraries when --ldflags is given.

---

 configure.ac                     |   10 +++++-----
 lib/boilerplate/init/Makefile.am |   19 ++++++++++++++++---
 scripts/xeno-config-cobalt.in    |   30 +++++++++++++++++++++++-------
 scripts/xeno-config-mercury.in   |   30 +++++++++++++++++++++++-------
 4 files changed, 67 insertions(+), 22 deletions(-)

diff --git a/configure.ac b/configure.ac
index 42f2f5d..c61748c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -831,16 +831,16 @@ dnl in-tree executables which require POSIX symbol 
wrapping.
    AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$cobalt_wrappers"])
 fi
 
-XENO_AUTOINIT_LDFLAGS='$(top_builddir)/lib/boilerplate/init/bootstrap.o'" 
-Wl,--wrap=main -Wl,--dynamic-list=$topdir/scripts/dynlist.ld"
+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"
 AC_SUBST(XENO_AUTOINIT_LDFLAGS)
 
 XENO_CORE_LIB=$rtcore_type/lib${rtcore_type}.la
 AC_SUBST(XENO_CORE_LIB)
 
-dnl
-dnl Build the Makefiles
-dnl
-
 AC_SUBST(DOXYGEN_SHOW_INCLUDE_FILES)
 AC_SUBST(DOXYGEN_HAVE_DOT)
 AC_SUBST(DOXYGEN)
diff --git a/lib/boilerplate/init/Makefile.am b/lib/boilerplate/init/Makefile.am
index 7a58f54..f41f419 100644
--- a/lib/boilerplate/init/Makefile.am
+++ b/lib/boilerplate/init/Makefile.am
@@ -7,12 +7,25 @@ libbootstrap_a_CPPFLAGS =             \
        -I$(top_srcdir)/include         \
        -I$(top_srcdir)/lib
 
+noinst_LTLIBRARIES = libbootstrap-pic.la
+
+libbootstrap_pic_la_SOURCES = bootstrap.c
+
+libbootstrap_pic_la_CPPFLAGS =         \
+       @XENO_USER_CFLAGS@              \
+       -I$(top_srcdir)/include         \
+       -I$(top_srcdir)/lib
+
+get_pic_object = $(shell source ./$(libbootstrap_pic_la_OBJECTS) && echo 
$$pic_object)
+
 all-local: $(libbootstrap_a_OBJECTS)
-       cp $(libbootstrap_a_OBJECTS) bootstrap.o
+       @cp $< bootstrap-internal.o
 
 install-data-local:
-       $(mkinstalldirs) $(DESTDIR)$(libdir)/xenomai
-       $(INSTALL_DATA) $(libbootstrap_a_OBJECTS) 
$(DESTDIR)$(libdir)/xenomai/bootstrap.o
+       @$(mkinstalldirs) $(DESTDIR)$(libdir)/xenomai
+       @$(INSTALL_DATA) $(libbootstrap_a_OBJECTS) 
$(DESTDIR)$(libdir)/xenomai/bootstrap.o
+       @test -r $(call get_pic_object) && \
+       $(INSTALL_DATA) $(call get_pic_object) 
$(DESTDIR)$(libdir)/xenomai/bootstrap-pic.o || true
 
 uninstall-local:
        $(RM) -r $(DESTDIR)$(libdir)/xenomai
diff --git a/scripts/xeno-config-cobalt.in b/scripts/xeno-config-cobalt.in
index fec0e28..38f8208 100644
--- a/scripts/xeno-config-cobalt.in
+++ b/scripts/xeno-config-cobalt.in
@@ -18,10 +18,8 @@ XENO_BASE_CFLAGS="-I$XENO_INCLUDE_DIR/cobalt 
-I$XENO_INCLUDE_DIR @XENO_USER_APP_
 XENO_POSIX_LDFLAGS="-L${staging}${libdir} -lcobalt -lpthread -lrt 
@XENO_USER_APP_LDFLAGS@"
 XENO_LIBRARY_DIR="${staging}${libdir}"
 LD_FILE_OPTION="@LD_FILE_OPTION@"
-WRAP_MAIN_OPT="${staging}${libdir}/xenomai/bootstrap.o -Wl,--wrap=main 
-Wl,--dynamic-list=${XENO_LIBRARY_DIR}/dynlist.ld"
-WRAP_MAIN="$WRAP_MAIN_OPT"
 
-unset prefix exec_prefix libdir datadir datarootdir pkgdatadir includedir 
skin_list compat
+unset skin_list compat codegen
 
 dump_wrappers()
 {
@@ -53,7 +51,7 @@ Options :
         --arch
         --prefix
         --[skin=]posix|vxworks|psos|alchemy|rtdm|smokey|cobalt
-        --auto-init|no-auto-init
+        --auto-init|auto-init-solib|no-auto-init
         --cflags
         --ldflags
         --lib*-dir,--libdir,--user-libdir
@@ -109,6 +107,8 @@ fi
 do_ldflags=
 do_cflags=
 do_setinit=
+do_autoinit=y
+do_autoinit_solib=
 
 while test $# -gt 0; do
     case "$1" in
@@ -133,11 +133,22 @@ while test $# -gt 0; do
             ;;
        --no-auto-init)
            do_setinit=y
-           WRAP_MAIN=
+           do_autoinit=
+           do_autoinit_solib=
            ;;
        --auto-init)
            do_setinit=y
-           WRAP_MAIN="$WRAP_MAIN_OPT"
+           do_autoinit=y
+           do_autoinit_solib=
+           ;;
+       --auto-init-solib)
+           if test \! -r ${XENO_LIBRARY_DIR}/xenomai/bootstrap-pic.o; then
+               echo "--auto-init-solib requires shared library support" 1>&2
+               exit 1
+           fi
+           do_setinit=y
+           do_autoinit=y
+           do_autoinit_solib=y
            ;;
         --lib*-dir|--libdir|--user-libdir)
             echo $XENO_LIBRARY_DIR
@@ -249,7 +260,12 @@ if test x$do_ldflags = xy; then
                ;;
        esac
     done
-    echo "$ldflags $copperplate $WRAP_MAIN $XENO_POSIX_LDFLAGS"
+    wrap_main=
+    if test x$do_autoinit = xy; then
+       test x$do_autoinit_solib = xy && codegen=-pic
+       wrap_main="${XENO_LIBRARY_DIR}/xenomai/bootstrap${codegen}.o 
-Wl,--wrap=main -Wl,--dynamic-list=${XENO_LIBRARY_DIR}/dynlist.ld"
+    fi
+    echo "$ldflags $copperplate $wrap_main $XENO_POSIX_LDFLAGS"
 fi
 
 exit 0
diff --git a/scripts/xeno-config-mercury.in b/scripts/xeno-config-mercury.in
index 04fed80..5dab4ba 100644
--- a/scripts/xeno-config-mercury.in
+++ b/scripts/xeno-config-mercury.in
@@ -17,10 +17,8 @@ XENO_INCLUDE_DIR="${staging}${includedir}"
 XENO_BASE_CFLAGS="-I$XENO_INCLUDE_DIR/mercury -I$XENO_INCLUDE_DIR 
@XENO_USER_APP_CFLAGS@ -D__MERCURY__"
 XENO_BASE_LDFLAGS="-L${staging}${libdir} -lmercury -lpthread -lrt 
@XENO_USER_APP_LDFLAGS@"
 XENO_LIBRARY_DIR="${staging}${libdir}"
-WRAP_MAIN_OPT="${staging}${libdir}/xenomai/bootstrap.o -Wl,--wrap=main 
-Wl,--dynamic-list=${XENO_LIBRARY_DIR}/dynlist.ld"
-WRAP_MAIN="$WRAP_MAIN_OPT"
 
-unset prefix exec_prefix libdir datadir datarootdir pkgdatadir includedir 
skin_list
+unset skin_list codegen
 
 usage ()
 {
@@ -35,7 +33,7 @@ Options :
         --arch
         --prefix
         --[skin=]posix|vxworks|psos|alchemy|rtdm|smokey
-        --auto-init|no-auto-init
+        --auto-init|auto-init-solib|no-auto-init
         --cflags
         --ldflags
         --lib*-dir,--libdir,--user-libdir
@@ -80,6 +78,8 @@ fi
 do_ldflags=
 do_cflags=
 do_setinit=
+do_autoinit=y
+do_autoinit_solib=
 
 while test $# -gt 0; do
     case "$1" in
@@ -101,11 +101,22 @@ while test $# -gt 0; do
             ;;
        --no-auto-init)
            do_setinit=y
-           WRAP_MAIN=
+           do_autoinit=
+           do_autoinit_solib=
            ;;
        --auto-init)
            do_setinit=y
-           WRAP_MAIN="$WRAP_MAIN_OPT"
+           do_autoinit=y
+           do_autoinit_solib=
+           ;;
+       --auto-init-solib)
+           if test \! -r ${XENO_LIBRARY_DIR}/xenomai/bootstrap-pic.o; then
+               echo "--auto-init-solib requires shared library support" 1>&2
+               exit 1
+           fi
+           do_setinit=y
+           do_autoinit=y
+           do_autoinit_solib=y
            ;;
         --lib*-dir|--libdir|--user-libdir)
             echo $XENO_LIBRARY_DIR
@@ -193,7 +204,12 @@ if test x$do_ldflags = xy; then
                ;;
        esac
     done
-    echo "$ldflags $copperplate $WRAP_MAIN $XENO_BASE_LDFLAGS"
+    wrap_main=
+    if test x$do_autoinit = xy; then
+       test x$do_autoinit_solib = xy && codegen=-pic
+       wrap_main="${XENO_LIBRARY_DIR}/xenomai/bootstrap${codegen}.o 
-Wl,--wrap=main -Wl,--dynamic-list=${XENO_LIBRARY_DIR}/dynlist.ld"
+    fi
+    echo "$ldflags $copperplate $wrap_main $XENO_BASE_LDFLAGS"
 fi
 
 exit 0


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to