kdeinit problem: LD_BIND_NOW cached by glibc
Lubos Lunak
l.lunak at suse.cz
Tue Nov 23 09:22:36 CET 2004
On Monday 22 of November 2004 23:52, Karl Vogel wrote:
> While looking at the glibc source I noticed that it caches the
> LD_BIND_NOW variable, which means that unsetting it after program start,
> will not change anything for dlopen()'s done by the program.
>
> This would also mean that the kdeinit hack in KDE will always do a
> complete bind of the symbols when loading the libkdeinit_appname.so
> module.
>
> Time for a test...
>
> ----- te.c ---
> #include <stdio.h>
> #include <stdlib.h>
> #include <dlfcn.h>
>
> int main(int argc, char *argv[])
> {
> void *handle;
> int i;
>
> unsetenv("LD_BIND_NOW");
> for(i= 0; i<100;i++) {
Ah ... I was wondering why a simple dlopen can take up to one minute here.
You almost got me.
> handle= dlopen(argv[1], RTLD_LAZY);
>
> if (handle == NULL)
> perror(dlerror());
>
> dlclose(handle);
> }
> return 0;
> }
> -----
>
> $ time ./te /usr/lib/libkdeinit_konsole.so
>
> real 0m0.227s
> user 0m0.171s
> sys 0m0.009s
real 0m4.244s
user 0m4.140s
sys 0m0.078s
> $ export LD_BIND_NOW=1
> $ time ./te /usr/lib/libkdeinit_konsole.so
>
> real 0m18.408s
> user 0m17.922s
> sys 0m0.413s
real 0m10.224s
user 0m10.042s
sys 0m0.128s
You forgot '-L$KDEDIR/lib -lkparts'. Otherwise you cannot have 100 dlopen's
done within 227ms (in your first case there's probably only a handful of
symbol being resolved and bound).
>
> I also verified this with libltdl and got the same results. This clearly
> shows that unsetenv("LD_BIND_NOW") has no effect on the dlopen.
>
> This is with glibc 2.3.3 (glibc-2.3.3-74) on Fedora Core 3.
SUSE 9.2 , glibc-2.3.3-118.
> Working around this for kdeinit is possible, but will be hackish.
The question is if this really matters. Is 60ms on 1,4GHz machine really
worth it? Maybe we should just modify startkde not to set LD_BIND_NOW in case
KDE_IS_PRELINKED is set. People caring so much about speed are probably using
prelink anyway.
--
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o. e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27 tel: +420 2 9654 2373
190 00 Praha 9 fax: +420 2 9654 2374
Czech Republic http://www.suse.cz/
More information about the Kde-optimize
mailing list