Skip to content

Commit

Permalink
Make ./snabb binary more portable
Browse files Browse the repository at this point in the history
This will enable us to release Snabb Switch as a single executable
file for any modern Linux/x86_64.

./snabb will link with any GLIBC version >= 2.7 (released 2007).  This
makes the binary linker-compatible with older Linux distributions such
as Ubuntu 10.04 and CentOS 6.

Tested when built on Ubuntu 14.04. Building on other distributions may
yield different results, but a selftest script is included to catch that.

(There may be other compatibility issues with older kernels and
CPUs. This only takes care of the dynamic linking.)
  • Loading branch information
lukego committed Jan 30, 2015
1 parent c31e288 commit a50aa9d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -5,7 +5,7 @@ COBJ = $(CSRC:.c=.o)

LUAJIT_O := deps/luajit/src/libluajit.a

LUAJIT_CFLAGS := -DLUAJIT_USE_PERFTOOLS -DLUAJIT_USE_GDBJIT -DLUAJIT_NUMMODE=3
LUAJIT_CFLAGS := -DLUAJIT_USE_PERFTOOLS -DLUAJIT_USE_GDBJIT -DLUAJIT_NUMMODE=3 -include $(CURDIR)/gcc-preinclude.h

all: $(LUAJIT_O)
cd src && $(MAKE)
Expand Down
6 changes: 6 additions & 0 deletions gcc-preinclude.h
@@ -0,0 +1,6 @@
// Force an old symbol version on memcpy.
// See: http://www.win.tue.nl/~aeb/linux/misc/gcc-semibug.html
// https://rjpower9000.wordpress.com/2012/04/09/fun-with-shared-libraries-version-glibc_2-14-not-found/
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");


4 changes: 2 additions & 2 deletions src/Makefile
Expand Up @@ -45,7 +45,7 @@ snabb: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ)
$(E) "LINK $@"
$(Q) gcc -Wl,--no-as-needed -Wl,-E -Werror -Wall -o $@ $^ \
../deps/luajit/src/libluajit.a \
-lc -ldl -lm -lrt -lpthread
-lrt -lc -ldl -lm -lpthread
@echo -n "Firmware: "
@ln -fs snabb snabbswitch
@ls -sh snabb
Expand Down Expand Up @@ -99,7 +99,7 @@ $(LUAOBJ): obj/%_lua.o: %.lua Makefile | $(OBJDIR)

$(COBJ): obj/%_c.o: %.c $(CHDR) Makefile | $(OBJDIR)
$(E) "C $@"
$(Q) gcc -Wl,-E -I ../deps/luajit/src -I . -c -Wall -Werror -o $@ $<
$(Q) gcc -Wl,-E -I ../deps/luajit/src -I . -include $(CURDIR)/../gcc-preinclude.h -c -Wall -Werror -o $@ $<

$(HOBJ): obj/%_h.o: %.h Makefile | $(OBJDIR)
$(E) "H $@"
Expand Down
9 changes: 9 additions & 0 deletions src/selftest.sh
@@ -0,0 +1,9 @@
#!/bin/bash
echo "selftest: ./snabb binary portability"
glibc=$(objdump -T snabb | grep GLIBC | sed -e 's/^.*GLIBC_//' -e 's/ .*//' | sort -nr | head -1)
if [ "$glibc" == "2.7" ]; then
echo "ok: links with glibc >= 2.7"
else
echo "error: requires glibc $glibc (> 2.7)"
exit 1
fi

0 comments on commit a50aa9d

Please sign in to comment.