rtld_next broke?

Timo Teras timo.teras at iki.fi
Thu Nov 1 19:13:32 UTC 2012


Hi,

I noticed that dlsym(RTLD_NEXT) seems to be broken under certain
conditions. I also noticed that Floarian observed this earlier too [1],
but no solution seems to have been provided.

It appears this is related closely to the linking order of the final
executable.

E.g. the following happens for me:

$ cat a.c
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>

int main(void)
{
	printf("%p\n", dlsym(RTLD_NEXT, "SSL_library_init"));
	return 0;
}

$ gcc -o a a.c -lssl -ldl && ./a
0x4f6104b4
$ gcc -o a a.c -lc -lssl -ldl && ./a
(nil)
$ gcc -o a a.c -ldl -lssl && ./a
(nil)

So there is certainly something fishy here.

Looking at the code it would seem that the RTLD_NEXT lookup searches
for the module where it's being called from, and executes the
_dl_find_hash only for the next module in the chain. However, if the
looked symbol is not there, the rest of the modules are not looked up.

The problem seems that generally the symbols seem to be merged for the
parent modules. And RTLD_NEXT goes look in the first module after the
parent which contains only full merge of that module - not the all the
modules the parent linked against and follow.

Appears that we need to add some sort of for loop iterating through all
the following modules.

Will try to patch tomorrow. Or does someone have a better solution for
this?

- Timo

[1] http://lists.uclibc.org/pipermail/uclibc/2012-September/047021.html


More information about the uClibc mailing list