I'm writing an article (in french) about libdl.so and faced a behavior I
wasn't expected while trying to chain functions w/ same name in
different libraries using dlsym/RTLD_NEXT on a debian sarge :
Here is a compile time link of the chain components :
for i in 1 2 3 4
do
cat > lib$i.c <<EOF
#include <stdio.h>
#include <dlfcn.h>
void foo() {
void (*next_foo)(void);
printf("lib$i.foo()\n");
if (next_foo = (void (*)(void)) dlsym(RTLD_NEXT, "foo")) next_foo();
}
chain5
l1 is 804a018 l1.foo is 5556d584
l2 is 804a3b0 l2.foo is 55570584
l3 is 804a710 l3.foo is 55572584
l4 is 804aa70 l4.foo is 55574584
l1.foo is 5556d584
l2.foo is 55570584
l3.foo is 55572584
l4.foo is 55574584
default foo is 5556d584
lib1.foo()
So dlsym cannot fetch next symbol when libs are linked runtime w/ dlopen even when
RTLD_GLOBAL|RTLD_NOW are set.
Is this behavior normal under glibc (which on linux implements dlfcn
functions) ?