summaryrefslogtreecommitdiffstats
path: root/tc
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-11-06 06:09:22 -0500
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-11-10 10:44:20 -0800
commitf2e27cfb016e2465cd3f07e0b556058060702578 (patch)
treec8f111902c95f4d8624408e36aa35acdc3176cc9 /tc
parenta7a9ddbb675b7fbd184c3ab40817265b0b207a23 (diff)
support static-only systems
The iptables code supports a "no shared libs" mode where it can be used without requiring dlfcn related functionality. This adds similar support to iproute2 so that it can easily be used on systems like nommu Linux (but obviously with a few limitations -- no dynamic plugins). Rather than modify every location that uses dlfcn.h, I hooked the dlfcn.h header with stub functions when shared library support is disabled. Then symbol lookup is done via a local static lookup table (which is generated automatically at build time) so that internal symbols can be found. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'tc')
-rw-r--r--tc/Makefile23
-rw-r--r--tc/m_ipt.c4
-rw-r--r--tc/static-syms.c6
3 files changed, 29 insertions, 4 deletions
diff --git a/tc/Makefile b/tc/Makefile
index 3ff25358..027055cf 100644
--- a/tc/Makefile
+++ b/tc/Makefile
@@ -3,6 +3,7 @@ TCOBJ= tc.o tc_qdisc.o tc_class.o tc_filter.o tc_util.o \
m_ematch.o emp_ematch.yacc.o emp_ematch.lex.o
include ../Config
+SHARED_LIBS ?= y
TCMODULES :=
TCMODULES += q_fifo.o
@@ -57,7 +58,12 @@ else
endif
TCOBJ += $(TCMODULES)
-LDLIBS += -L. -ltc -lm -ldl
+LDLIBS += -L. -ltc -lm
+
+ifeq ($(SHARED_LIBS),y)
+LDLIBS += -ldl
+LDFLAGS += -Wl,-export-dynamic
+endif
TCLIB := tc_core.o
TCLIB += tc_red.o
@@ -72,9 +78,6 @@ ifeq ($(TC_CONFIG_ATM),y)
TCSO += q_atm.so
endif
-
-LDFLAGS += -Wl,-export-dynamic
-
YACC := bison
LEX := flex
@@ -108,3 +111,15 @@ q_atm.so: q_atm.c
%.lex.c: %.l
$(LEX) $(LEXFLAGS) -o$@ $<
+
+ifneq ($(SHARED_LIBS),y)
+
+tc: static-syms.o
+static-syms.o: static-syms.h
+static-syms.h: $(wildcard *.c)
+ files="$^" ; \
+ for s in `grep -B 3 '\<dlsym' $$files | sed -n '/snprintf/{s:.*"\([^"]*\)".*:\1:;s:%s::;p}'` ; do \
+ sed -n '/'$$s'[^ ]* =/{s:.* \([^ ]*'$$s'[^ ]*\) .*:extern char \1[] __attribute__((weak)); if (!strcmp(sym, "\1")) return \1;:;p}' $$files ; \
+ done > $@
+
+endif
diff --git a/tc/m_ipt.c b/tc/m_ipt.c
index d17d3245..99d9965a 100644
--- a/tc/m_ipt.c
+++ b/tc/m_ipt.c
@@ -226,6 +226,10 @@ get_target_name(const char *name)
struct iptables_target *m;
char path[strlen(lib_dir) + sizeof ("/libipt_.so") + strlen(name)];
+#ifdef NO_SHARED_LIBS
+ return NULL;
+#endif
+
new_name = malloc(strlen(name) + 1);
lname = malloc(strlen(name) + 1);
if (new_name)
diff --git a/tc/static-syms.c b/tc/static-syms.c
new file mode 100644
index 00000000..1ed3a8a9
--- /dev/null
+++ b/tc/static-syms.c
@@ -0,0 +1,6 @@
+#include <string.h>
+void *_dlsym(const char *sym)
+{
+#include "static-syms.h"
+ return NULL;
+}