segfault when linking with libiptables
hi,
I have the following problem when linking an user program with libiptables. the program may be as simple as the following:
#include <iptables.h>
#include <iptables_common.h>
#include <libiptc/libiptc.h>
int main(void) {
find_match("dscp", LOAD_MUST_SUCCEED);
return 0;
}I compiled it with:
cc -c -O2 -ggdb -Wall -Wunused myprog.c
cc -O2 -ggdb -Wall -Wunused -export-dynamic -o myprog myprog.o -liptables -liptc -ldl
(Makefile attached)
when trying to load the dscp match extension, dlopen (which is invoked by find_match) segfaults. here is a transcript from gdb:
[...]
Reading symbols from /lib/tls/libdl.so.2...done.
Loaded symbols for /lib/tls/libdl.so.2
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /usr/local/lib/iptables/libipt_dscp.so...done. Loaded symbols for /usr/local/lib/iptables/libipt_dscp.so #0 0x400a0034 in strcmp () from /lib/tls/libc.so.6
does anybody have an idea which the cause could be? I am using gcc version 3.3.3 (Debian) and iptables-dev unstable. any help would be greatly appreciated.
cheers,
John.
========== Makefile ==========
all: myprog
CFLAGS:=-O2 -ggdb -Wall -Wunused
LDFLAGS = -export-dynamic
LDLIBS = -liptc -ldl
%.o : %.c
$(CC) -c $(CFLAGS) $<
myprog: myprog.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
clean:
rm myprog.o myprog
initialization of program_version --- was: Re: segfault when linking with libiptables
hi,
this is because of the "program_version", which is referenced in "register_match" and needs therefore to be initialized before calling "find_match".
wouldn't be it better to have it set by libiptables itself, rather that in iptables_standalone.c?
cheers,
John.