Module: xenomai-gch
Branch: for-head
Commit: ea9279f4bae53185ae03196922171bde4795798e
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=ea9279f4bae53185ae03196922171bde4795798e

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Sep 20 23:09:39 2009 +0200

build: provide front-end script to link static POSIX apps

An unfortunate side-effect of using ld's --wrap magic for shadowing
libpthread symbols by Xenomai's POSIX skin calls, is that we end up
wrapping libpthread's own symbols as well, in case of static linking.

This patch introduces the wrap-link.sh script, which reshuffles a
linker invocation, in order to split it in two separate stages. First,
the wrappable bits are combined into a single relocatable object,
then, the latter object is linked against libpthread without
performing any wrapping.

Typically, invoking:

$ wrap-link.sh gcc -o foo foo.o -Wl,@/usr/xenomai/lib/posix.wrappers 
-L/usr/xenomai/lib -lpthread_rt -lpthread -lrt

will produce:

stage1: gcc -o foo.tmp -Wl,-r -nostdlib tmp foo.o 
-Wl,@/usr/xenomai/lib/posix.wrappers -L/usr/xenomai/lib
stage2: gcc -o foo foo.tmp -lpthread_rt -lpthread -lrt

This means that symbol wrapping will only occur during stage1 of the
linking process, thus preventing spurious wrapping of libpthread
symbols in stage2.

Makefiles used in building applications which depend on the POSIX skin
have been updated in order to use that front-end.

NOTE: this commit clears the previous restriction imposed on the
recent Xenomai/nios2 port regarding POSIX app generation.

---

 scripts/wrap-link.sh                 |  174 ++++++++++++++++++++++++++++++++++
 src/testsuite/clocktest/Makefile.am  |    2 +
 src/testsuite/clocktest/Makefile.in  |    2 +-
 src/testsuite/cyclic/Makefile.am     |    2 +
 src/testsuite/cyclic/Makefile.in     |    2 +-
 src/testsuite/irqbench/Makefile.am   |    2 +
 src/testsuite/irqbench/Makefile.in   |    2 +-
 src/testsuite/switchtest/Makefile.am |    2 +
 src/testsuite/switchtest/Makefile.in |    2 +-
 src/testsuite/unit/Makefile.am       |    2 +
 src/testsuite/unit/Makefile.in       |    2 +-
 11 files changed, 189 insertions(+), 5 deletions(-)

diff --git a/scripts/wrap-link.sh b/scripts/wrap-link.sh
new file mode 100755
index 0000000..3d5aaca
--- /dev/null
+++ b/scripts/wrap-link.sh
@@ -0,0 +1,174 @@
+#! /bin/sh
+# Split link-edit into two stage for linking static applications with
+# Xenomai user-space posix skin.
+
+set -e
+
+usage() {
+    cat <<EOF
+$progname [options] command-line
+
+Split command-line in two parts for linking static applications with
+Xenomai user-space posix skin in two stages.
+
+Options:
+-q be quiet
+-v be verbose (print each command before running it)
+
+Example:
+$progname -v gcc -o foo foo.o -Wl,@/usr/xenomai/lib/posix.wrappers 
-L/usr/xenomai/lib -lpthread_rt -lpthread -lrt
+will print and run:
++ gcc -o foo.tmp -Wl,-r -nostdlib tmp foo.o 
-Wl,@/usr/xenomai/lib/posix.wrappers -L/usr/xenomai/lib
++ gcc -o foo foo.tmp -lpthread_rt -lpthread -lrt
++ rm foo.tmp
+EOF
+}
+
+add_linker_flag() {
+    if $next_is_wrapped_symbol; then
+       stage1_args="$stage1_args -Wl,--wrap $@"
+       next_is_wrapped_symbol=false
+    else
+       stage1_args="$stage1_args $@"
+       stage2_args="$stage2_args $@"
+    fi
+}
+
+add_linker_obj() {
+    if $stage2; then
+       stage2_args="$stage2_args $@"
+    else
+       stage1_args="$stage1_args $@"
+    fi
+}
+
+if test -n "$V" && test $V -gt 0; then
+    verbose=:
+else
+    verbose=false
+fi
+progname=$0
+
+if test $# -eq 0; then
+    usage
+    exit 0
+fi
+
+while test $# -gt 0; do
+    arg="$1"
+    shift
+    case "$arg" in
+       "")
+           usage
+           exit 0
+           ;;
+
+       -v) 
+           verbose=:
+           ;;
+
+       -q) 
+           verbose=false
+           ;;
+
+       -*)
+           cc="$cc $arg"
+           ;;
+
+       *gcc*|*g++*)
+           cc="$cc $arg"
+           break
+           ;;
+
+       *ld)
+           usage
+           /bin/echo -e "\nlinker must be gcc or g++, not ld"
+           exit 1
+           ;;
+
+       *)
+           cc="$cc $arg"
+           ;;
+    esac
+done
+
+next_is_wrapped_symbol=false
+stage1_args=""
+stage2_args=""
+stage2=false
+while test $# -gt 0; do
+    arg="$1"
+    shift
+    case "$arg" in
+       *pthread_rt*|-lpthread)
+           stage2_args="$stage2_args $arg"
+           stage2=:
+           ;;
+
+       -Xlinker)
+           arg="$1"
+           shift
+           case "$arg" in
+               --wrap)
+                   next_is_wrapped_symbol=:
+                   ;;
+               @*posix.wrappers)
+                   stage1_args="$stage1_args -Xlinker $arg"
+                   ;;
+
+               *) 
+                   add_linker_flag -Xlinker "$arg"
+                   ;;
+           esac
+           ;;
+
+       -Wl,--wrap)
+           next_is_wrapped_symbol=:
+           ;;
+
+       -Wl,@*posix.wrappers|-Wl,--wrap,*)
+           stage1_args="$stage1_args $arg"
+           ;;
+
+       -Wl,*)
+           add_linker_flag "$arg"
+           ;;
+
+       -o)
+           output="$1"
+           shift
+           ;;
+
+       -o*)
+           output=`expr $arg : '-o\(.*\)'`
+           ;;
+       
+       -l) 
+           arg="$1"
+           shift
+           add_linker_obj -l $arg
+           ;;
+
+       -l*) #a library
+           add_linker_obj $arg
+           ;;
+
+       *.so)
+           stage2_args="$stage2_args $arg"
+           ;;
+
+       *) 
+           if test -e "$arg"; then
+               add_linker_obj $arg
+           else
+               stage1_args="$stage1_args $arg"
+               stage2_args="$stage2_args $arg"
+           fi
+          ;;
+    esac
+done
+
+$verbose && set -x
+$cc -o "$output.tmp" -Wl,-Ur -nostdlib $stage1_args
+$cc -o "$output" "$output.tmp" $stage2_args
+rm -f $output.tmp
diff --git a/src/testsuite/clocktest/Makefile.am 
b/src/testsuite/clocktest/Makefile.am
index 35e0386..69d10b0 100644
--- a/src/testsuite/clocktest/Makefile.am
+++ b/src/testsuite/clocktest/Makefile.am
@@ -1,5 +1,7 @@
 testdir = $(exec_prefix)/share/xenomai/testsuite/clocktest
 
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
 bin_PROGRAMS = clocktest
 
 clocktest_SOURCES = clocktest.c
diff --git a/src/testsuite/clocktest/Makefile.in 
b/src/testsuite/clocktest/Makefile.in
index 87a2eea..9c5286f 100644
--- a/src/testsuite/clocktest/Makefile.in
+++ b/src/testsuite/clocktest/Makefile.in
@@ -70,7 +70,6 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(AM_CPPFLAGS) \
 LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
@@ -238,6 +237,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 testdir = $(exec_prefix)/share/xenomai/testsuite/clocktest
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 clocktest_SOURCES = clocktest.c
 clocktest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) 
-I$(top_srcdir)/include
 clocktest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
diff --git a/src/testsuite/cyclic/Makefile.am b/src/testsuite/cyclic/Makefile.am
index d3491bc..2ee19de 100644
--- a/src/testsuite/cyclic/Makefile.am
+++ b/src/testsuite/cyclic/Makefile.am
@@ -1,5 +1,7 @@
 testdir = $(exec_prefix)/share/xenomai/testsuite/cyclic
 
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
 bin_PROGRAMS = cyclictest
 
 cyclictest_SOURCES = cyclictest.c
diff --git a/src/testsuite/cyclic/Makefile.in b/src/testsuite/cyclic/Makefile.in
index 06b681a..5d75a3d 100644
--- a/src/testsuite/cyclic/Makefile.in
+++ b/src/testsuite/cyclic/Makefile.in
@@ -70,7 +70,6 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(AM_CPPFLAGS) \
 LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
@@ -238,6 +237,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 testdir = $(exec_prefix)/share/xenomai/testsuite/cyclic
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 cyclictest_SOURCES = cyclictest.c
 cyclictest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) 
-DIPIPE_TRACE=1 -I$(top_srcdir)/include
 cyclictest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
diff --git a/src/testsuite/irqbench/Makefile.am 
b/src/testsuite/irqbench/Makefile.am
index 4a2a94a..29fb308 100644
--- a/src/testsuite/irqbench/Makefile.am
+++ b/src/testsuite/irqbench/Makefile.am
@@ -1,5 +1,7 @@
 testdir = $(exec_prefix)/share/xenomai/testsuite/irqbench
 
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
 bin_PROGRAMS = irqloop
 
 if XENO_LINUX_ARCH_I386
diff --git a/src/testsuite/irqbench/Makefile.in 
b/src/testsuite/irqbench/Makefile.in
index 29946ef..e7765de 100644
--- a/src/testsuite/irqbench/Makefile.in
+++ b/src/testsuite/irqbench/Makefile.in
@@ -78,7 +78,6 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(AM_CPPFLAGS) \
 LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
@@ -246,6 +245,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 testdir = $(exec_prefix)/share/xenomai/testsuite/irqbench
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 irqloop_SOURCES = irqloop.c
 irqloop_CPPFLAGS = \
        -I$(top_srcdir)/include/posix \
diff --git a/src/testsuite/switchtest/Makefile.am 
b/src/testsuite/switchtest/Makefile.am
index 5fdf63a..1117585 100644
--- a/src/testsuite/switchtest/Makefile.am
+++ b/src/testsuite/switchtest/Makefile.am
@@ -1,5 +1,7 @@
 testdir = $(exec_prefix)/share/xenomai/testsuite/switchtest
 
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
 bin_PROGRAMS = switchtest
 
 switchtest_SOURCES = switchtest.c
diff --git a/src/testsuite/switchtest/Makefile.in 
b/src/testsuite/switchtest/Makefile.in
index 7f58dcb..8da3e29 100644
--- a/src/testsuite/switchtest/Makefile.in
+++ b/src/testsuite/switchtest/Makefile.in
@@ -70,7 +70,6 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(AM_CPPFLAGS) \
 LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
@@ -238,6 +237,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 testdir = $(exec_prefix)/share/xenomai/testsuite/switchtest
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 switchtest_SOURCES = switchtest.c
 switchtest_CPPFLAGS = -I$(top_srcdir)/include/posix $(XENO_USER_CFLAGS) -g 
-I$(top_srcdir)/include
 switchtest_LDFLAGS = $(XENO_POSIX_WRAPPERS) $(XENO_USER_LDFLAGS)
diff --git a/src/testsuite/unit/Makefile.am b/src/testsuite/unit/Makefile.am
index ad35e64..24d077a 100644
--- a/src/testsuite/unit/Makefile.am
+++ b/src/testsuite/unit/Makefile.am
@@ -1,5 +1,7 @@
 testdir = $(exec_prefix)/share/xenomai/testsuite/unit
 
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
+
 bin_PROGRAMS = arith wakeup-time mutex-torture-posix mutex-torture-native
 
 arith_SOURCES = arith.c arith-noinline.c arith-noinline.h
diff --git a/src/testsuite/unit/Makefile.in b/src/testsuite/unit/Makefile.in
index e710d11..5c6d2fb 100644
--- a/src/testsuite/unit/Makefile.in
+++ b/src/testsuite/unit/Makefile.in
@@ -93,7 +93,6 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) 
$(AM_CPPFLAGS) \
 LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
        --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
        $(LDFLAGS) -o $@
@@ -263,6 +262,7 @@ top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 testdir = $(exec_prefix)/share/xenomai/testsuite/unit
+CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 arith_SOURCES = arith.c arith-noinline.c arith-noinline.h
 arith_CPPFLAGS = \
        @XENO_USER_CFLAGS@ \


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

Reply via email to