Commit a7243543 authored by Philippe Gerum's avatar Philippe Gerum

lib/cobalt: move mode checking wrappers to static archive

The mode checking wrappers must reside in a static archive, so that
the linker will pull them on demand, dropping the requirement for
providing potentially conflicting placeholders for wrapped symbols
which may not be present in both C and C++ support libraries
(e.g. __cxa_guard_acquire/release/abort from the one-time C++
constructor API).

See http://www.xenomai.org/pipermail/xenomai/2017-March/037184.html
parent 1ba2fc8e
......@@ -796,19 +796,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"
modechk_wrappers="$topdir/lib/cobalt/modechk.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,@$modechk_wrappers -Wl,@$cobalt_wrappers"
else
XENO_POSIX_WRAPPERS=`cat $assert_wrappers $cobalt_wrappers | \
XENO_POSIX_WRAPPERS=`cat $modechk_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], ["$assert_wrappers $cobalt_wrappers"])
AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ["$modechk_wrappers $cobalt_wrappers"])
fi
dnl
......@@ -818,8 +818,11 @@ 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)
XENO_CORE_LDADD="\$(top_builddir)/lib/$rtcore_type/lib${rtcore_type}.la"
if test $rtcore_type = cobalt; then
XENO_CORE_LDADD="$XENO_CORE_LDADD \$(top_builddir)/lib/cobalt/libmodechk.a"
fi
AC_SUBST(XENO_CORE_LDADD)
AC_SUBST(DOXYGEN_SHOW_INCLUDE_FILES)
AC_SUBST(DOXYGEN_HAVE_DOT)
......
......@@ -2,6 +2,6 @@ usr/include
usr/lib/*.la
usr/lib/*.a
usr/lib/*.so
usr/lib/assert.wrappers
usr/lib/modechk.wrappers
usr/lib/cobalt.wrappers
usr/lib/dynlist.ld
......@@ -13,8 +13,9 @@ cppflags = \
ldadd = \
../../lib/alchemy/libalchemy.la \
../../lib/copperplate/libcopperplate.la \
../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt -lm
altency_SOURCES = altency.c
altency_CPPFLAGS = $(cppflags)
......
......@@ -8,14 +8,14 @@ cppflags = \
$(XENO_USER_CFLAGS) \
-I$(top_srcdir)/include
ldadd = \
../../../lib/alchemy/libalchemy.la \
../../../lib/copperplate/libcopperplate.la \
../../../lib/cobalt/libcobalt.la \
@XENO_AUTOINIT_LDFLAGS@ \
$(XENO_POSIX_WRAPPERS) \
@XENO_USER_LDADD@ \
-lpthread -lrt
ldadd = \
@XENO_AUTOINIT_LDFLAGS@ \
$(XENO_POSIX_WRAPPERS) \
../../../lib/alchemy/libalchemy.la \
../../../lib/copperplate/libcopperplate.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
cross_link_SOURCES = cross-link.c
cross_link_CPPFLAGS = $(cppflags)
......
......@@ -20,7 +20,7 @@ cppflags = \
ldflags = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
ldadd = \
../../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......
......@@ -27,7 +27,7 @@ cyclictest_SOURCES = \
cyclictest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
cyclictest_LDADD = \
../../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@ \
cyclictest_LDADD = \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt -lm
......@@ -17,7 +17,7 @@
*/
#include <sys/types.h>
#include <unistd.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <xenomai/init.h>
......@@ -77,7 +77,7 @@ __bootstrap_ctor static void xenomai_bootstrap(void)
if (fd < 0)
return;
arglist = malloc(len);
arglist = __STD(malloc(len));
if (arglist == NULL) {
__STD(close(fd));
return;
......@@ -87,14 +87,14 @@ __bootstrap_ctor static void xenomai_bootstrap(void)
__STD(close(fd));
if (ret < 0) {
free(arglist);
__STD(free(arglist));
return;
}
if (ret < len)
break;
free(arglist);
__STD(free(arglist));
len <<= 1;
}
......@@ -106,9 +106,9 @@ __bootstrap_ctor static void xenomai_bootstrap(void)
p += strlen(p) + 1;
}
v = malloc((n + 1) * sizeof(char *));
v = __STD(malloc((n + 1) * sizeof(char *)));
if (v == NULL) {
free(arglist);
__STD(free(arglist));
return;
}
......
......@@ -43,15 +43,33 @@ libcobalt_la_CPPFLAGS = \
-I$(top_srcdir)/include/cobalt \
-I$(top_srcdir)/include
# The mode checking wrappers must reside in a static archive, so that
# the linker will pull them on demand, dropping the requirement for
# providing potentially conflicting placeholders for wrapped symbols
# which may not be present in both C and C++ support libraries
# (e.g. __cxa_guard_acquire/release/abort from the one-time C++
# constructor API).
lib_LIBRARIES = libmodechk.a
libmodechk_a_SOURCES = \
malloc.c \
malloc-nowrap.c
libmodechk_a_CPPFLAGS = \
@XENO_COBALT_CFLAGS@ \
-I$(top_srcdir)/include/cobalt \
-I$(top_srcdir)/include
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(libdir)
$(INSTALL_DATA) $(srcdir)/cobalt.wrappers $(DESTDIR)$(libdir)
$(INSTALL_DATA) $(srcdir)/assert.wrappers $(DESTDIR)$(libdir)
$(INSTALL_DATA) $(srcdir)/modechk.wrappers $(DESTDIR)$(libdir)
uninstall-local:
$(RM) $(DESTDIR)$(libdir)/cobalt.wrappers
$(RM) $(DESTDIR)$(libdir)/assert.wrappers
$(RM) $(DESTDIR)$(libdir)/modechk.wrappers
EXTRA_DIST = cobalt.wrappers assert.wrappers
EXTRA_DIST = cobalt.wrappers modechk.wrappers
SUBDIRS = arch
......@@ -53,16 +53,3 @@ void assert_nrt_fast(void) /* OBSOLETE */
{
assert_nrt();
}
/* Memory allocation services */
COBALT_IMPL(void *, malloc, (size_t size))
{
assert_nrt();
return __STD(malloc(size));
}
COBALT_IMPL(void, free, (void *ptr))
{
assert_nrt();
__STD(free(ptr));
}
/*
* Copyright (C) 2008, 2009 Jan Kiszka <jan.kiszka@siemens.com>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdlib.h>
__weak
void *__real_malloc(size_t size)
{
return malloc(size);
}
__weak
void __real_free(void *ptr)
{
free(ptr);
}
/*
* Copyright (C) 2008, 2009 Jan Kiszka <jan.kiszka@siemens.com>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdlib.h>
void assert_nrt(void);
/* Memory allocation services */
COBALT_IMPL(void *, malloc, (size_t size))
{
assert_nrt();
return __STD(malloc(size));
}
COBALT_IMPL(void, free, (void *ptr))
{
assert_nrt();
__STD(free(ptr));
}
......@@ -472,18 +472,6 @@ void __real_vsyslog(int priority, const char *fmt, va_list ap)
vsyslog(priority, fmt, ap);
}
__weak
void *__real_malloc(size_t size)
{
return malloc(size);
}
__weak
void __real_free(void *ptr)
{
free(ptr);
}
__weak
int __real_gettimeofday(struct timeval *tv, struct timezone *tz)
{
......
......@@ -10,7 +10,7 @@ LDFLAGS = $(XENO_POSIX_WRAPPERS)
LDADD = \
../libcopperplate.la \
../../@XENO_CORE_LIB@ \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......
......@@ -19,10 +19,10 @@ Options:
-n dry run (print all commands but don't run any)
Example:
$1 -v gcc -o foo foo.o -Wl,@/usr/xenomai/lib/cobalt.wrappers -L/usr/xenomai/lib -lcobalt -lpthread -lrt
$1 -v gcc -o foo foo.o -Wl,@/usr/xenomai/lib/cobalt.wrappers -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -lrt
will print and run:
+ gcc -o foo.tmp -Wl,-Ur -nostdlib foo.o -Wl,@/usr/xenomai/lib/cobalt.wrappers -L/usr/xenomai/lib
+ gcc -o foo foo.tmp -L/usr/xenomai/lib -lcobalt -lpthread -lrt
+ gcc -o foo.tmp -Wl,-Ur -nostdlib foo.o -Wl,@/usr/xenomai/lib/cobalt.wrappers -Wl,@/usr/xenomai/lib/modechk.wrappers -L/usr/xenomai/lib
+ gcc -o foo foo.tmp -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -lrt
+ rm foo.tmp
EOF
}
......
......@@ -15,7 +15,7 @@ XENO_CC="@CC@"
XENO_TARGET_ARCH="@XENO_TARGET_ARCH@"
XENO_INCLUDE_DIR="${staging}${includedir}"
XENO_BASE_CFLAGS="-I$XENO_INCLUDE_DIR/cobalt -I$XENO_INCLUDE_DIR @XENO_USER_APP_CFLAGS@ -D__COBALT__"
XENO_POSIX_LDFLAGS="-L${staging}${libdir} -lcobalt -lpthread -lrt @XENO_USER_APP_LDFLAGS@"
XENO_POSIX_LDFLAGS="-L${staging}${libdir} -lcobalt -lmodechk -lpthread -lrt @XENO_USER_APP_LDFLAGS@"
XENO_LIBRARY_DIR="${staging}${libdir}"
LD_FILE_OPTION="@LD_FILE_OPTION@"
......@@ -235,7 +235,7 @@ if test x$do_ldflags = xy; then
echo "no API specified, missing --skin before --ldflags" 1>&2
exit 1
fi
ldflags="`dump_wrappers assert.wrappers`"
ldflags="`dump_wrappers modechk.wrappers`"
test x$compat = xy && ldflags="-ltrank $ldflags"
copperplate=
for skin in $skin_list; do
......
......@@ -13,6 +13,6 @@ clocktest_CPPFLAGS = \
clocktest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
clocktest_LDADD = \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -14,6 +14,6 @@ gpiotest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
gpiotest_LDADD = \
../../lib/smokey/libsmokey.la \
../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@ \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -12,7 +12,7 @@ latency_CPPFLAGS = \
latency_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
latency_LDADD = \
../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@ \
latency_LDADD = \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt -lm
......@@ -59,6 +59,6 @@ smokey_LDADD = \
$(plugin_list) \
../../lib/smokey/libsmokey.la \
../../lib/copperplate/libcopperplate.la \
../../lib/@XENO_CORE_LIB@ \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -22,6 +22,6 @@ smokey_net_server_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@
smokey_net_server_LDADD = \
libnet_common.a \
$(top_builddir)/lib/@XENO_CORE_LIB@ \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -14,6 +14,6 @@ spitest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
spitest_LDADD = \
../../lib/smokey/libsmokey.la \
../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@ \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -12,7 +12,7 @@ switchtest_CPPFLAGS = \
switchtest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
switchtest_LDADD = \
../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@ \
switchtest_LDADD = \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -25,7 +25,7 @@ analogy_config_SOURCES = analogy_config.c
analogy_config_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -34,7 +34,7 @@ analogy_calibrate.c: calibration_ni_m.h
analogy_calibrate_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt -lm
......@@ -44,7 +44,7 @@ cmd_read_LDADD = \
../../lib/analogy/libanalogy.la \
../../lib/alchemy/libalchemy.la \
../../lib/copperplate/libcopperplate.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -54,7 +54,7 @@ cmd_write_LDADD = \
../../lib/analogy/libanalogy.la \
../../lib/alchemy/libalchemy.la \
../../lib/copperplate/libcopperplate.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -62,7 +62,7 @@ cmd_bits_SOURCES = cmd_bits.c
cmd_bits_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -70,7 +70,7 @@ insn_read_SOURCES = insn_read.c
insn_read_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -78,7 +78,7 @@ insn_write_SOURCES = insn_write.c
insn_write_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -86,7 +86,7 @@ insn_bits_SOURCES = insn_bits.c
insn_bits_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -95,6 +95,6 @@ wf_generate_LDADD = \
@XENO_AUTOINIT_LDFLAGS@ \
./libwaveform.la \
../../lib/analogy/libanalogy.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lrt -lpthread -lm
......@@ -12,6 +12,6 @@ autotune_CPPFLAGS = \
autotune_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
autotune_LDADD = \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -13,7 +13,7 @@ LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
rtcanconfig_SOURCES = rtcanconfig.c
rtcanconfig_LDADD = \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -22,7 +22,7 @@ rtcanrecv_SOURCES = rtcanrecv.c
rtcanrecv_LDADD = \
../../lib/alchemy/libalchemy.la \
../../lib/copperplate/libcopperplate.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -31,6 +31,6 @@ rtcansend_SOURCES = rtcansend.c
rtcansend_LDADD = \
../../lib/alchemy/libalchemy.la \
../../lib/copperplate/libcopperplate.la \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -12,6 +12,6 @@ corectl_CPPFLAGS = \
corectl_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
corectl_LDADD = \
../../lib/cobalt/libcobalt.la \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
......@@ -10,6 +10,6 @@ hdb_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@
hdb_LDADD = \
../../lib/copperplate/libcopperplate.la \
../../lib/@XENO_CORE_LIB@ \
@XENO_USER_LDADD@ \
@XENO_CORE_LDADD@ \
@XENO_USER_LDADD@ \
-lpthread -lrt
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment