diff --git a/Makefile.static-build b/Makefile.static-build index 809ac9db..6db26d76 100644 --- a/Makefile.static-build +++ b/Makefile.static-build @@ -8,6 +8,10 @@ MSGPACK_LIB=ext/lib/libmsgpack.a TMATE_CONFIGURE=PKG_CONFIG_PATH=./ext/lib/pkgconfig +LIBC=$(shell gcc -print-file-name=libc.a) +STATIC_LIBC_OBJECTS=fdelt_chk +STATIC_COMPAT_OBJECTS=memcpy clock_gettime + all: tmate dependencies: @@ -39,11 +43,18 @@ $(MSGPACK_LIB): $(MSGPACK)/.ready cd $(MSGPACK)/build; ([ -f Makefile ] || cmake -DCMAKE_INSTALL_PREFIX:PATH=$(shell pwd)/ext ..) +make -C $(MSGPACK)/build install -tmate: $(MSGPACK_LIB) $(LIBSSH_LIB) +libc/%.o: + mkdir -p libc + cd libc; ar x $(LIBC) $(notdir $@) + +compat/%.o: compat/%.c + gcc -c -o $@ $< + +tmate: $(MSGPACK_LIB) $(LIBSSH_LIB) $(patsubst %,libc/%.o,$(STATIC_LIBC_OBJECTS)) $(patsubst %,compat/%.o,$(STATIC_COMPAT_OBJECTS)) ./autogen.sh $(TMATE_CONFIGURE) ./configure --enable-static +make clean: - rm -rf ext $(LIBSSH) $(MSGPACK) + rm -rf ext libc $(LIBSSH) $(MSGPACK) +make clean diff --git a/compat/clock_gettime.c b/compat/clock_gettime.c new file mode 100644 index 00000000..0b631b79 --- /dev/null +++ b/compat/clock_gettime.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include +#include + +int clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + return syscall(SYS_clock_gettime, clk_id, tp); +} diff --git a/compat/memcpy.c b/compat/memcpy.c new file mode 100644 index 00000000..37092a33 --- /dev/null +++ b/compat/memcpy.c @@ -0,0 +1,11 @@ +// http://stackoverflow.com/questions/8823267/linking-against-older-symbol-version-in-a-so-file + +#include + +/* some systems do not have newest memcpy@@GLIBC_2.14 - stay with old good one */ +asm (".symver memcpy, memcpy@GLIBC_2.2.5"); + +void *__wrap_memcpy(void *dest, const void *src, size_t n) +{ + return memcpy(dest, src, n); +} diff --git a/configure.ac b/configure.ac index 663a51c5..10d761bc 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,7 @@ if test "x$found_static" = xyes; then CPPFLAGS="$LIBCRYPTO_CFLAGS $CPPFLAGS" LIBS="$LIBCRYPTO_LIBS $LIBS" ]) + # See more static settings below... (search for found_static) fi # Is this gcc? @@ -451,6 +452,12 @@ AM_CONDITIONAL(NO_GETOPT, [test "x$found_getopt" = xno]) if test "x$found_static" = xyes; then # libc and libdl should be dynamically linked. + # but we want to lower our requirements for libc's version. + # so we extract some symobls and add them here + if test `uname -m` = x86_64; then + LIBS="compat/memcpy.o -Wl,--wrap=memcpy $LIBS" + fi + LIBS="compat/clock_gettime.o libc/fdelt_chk.o $LIBS" LIBS="-Wl,-Bstatic ${LIBS/-ldl/} -Wl,-Bdynamic -ldl" fi