Prelink and libGL.so : a tip

Leon Bottou leon at bottou.org
Tue Dec 2 21:08:07 CET 2003


It seems that Jakub would favor using weakly 
undefined symbols for the libGL.so dependencies.
If of course this can be made to work nicely with KDE.

That would involve adding the following in the Qgl cpp files:
	#pragma weak glCallLists
	#pragma weak glXXXX
	...   // for all required libGL.so functions
plus a few well placed tests to prevent creating Qgl objects
if these functions resolve to NULL...

- L.




On Tue, Dec 02, 2003 at 01:57:21PM -0500, Leon Bottou wrote:
> I saw some exchanges on a mailing list a while ago linking this
> issue to their implementation of thread local variables, etc.
> This seems a complicated issue.  

The XFree86 libGL.so we ship uses TLS and works...
It is really not that complicated.

> > As for your http://lists.kde.org/?l=kde-optimize&m=107007239305615&w=2
> > patch, I'd strongly suggest using different names of the stubs than
> > the names of the functions in libGL.so, since it otherwise creates
> > unnecessary prelink conflicts depending whether libqt comes before
> > libGL.so in search scope.  Also, I think it is better to do all the
> > initialization in one routine (perhaps also guarded with weak pthread_once)
> > so that the stubs are as small as possible.
> 
> Sounds right.
> 
> The conflicts only affect the applications that actually make use of openGL
> (meaning that they are explicitely linked with libGL.so).   But these
> cannot be prelinked at the moment since libGL.so is non pic.

That's not true.  The whole world is not NVidia.

> The pthread_once is definitely missing.

#include <pthread.h>
#pragma weak pthread_once
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
static void *libgl_handle;
if (libgl_handle == NULL)
  {
    if (pthread_once)
      pthread_once (&once_control, init_libgl);
    else
      init_libgl ();
  }

?

> I wonder if we really need to do a dlopen("libGL.so",...).
> All applications that use these classes should be linked with -lGL.
> Maybe weakly undefined symbols would do the trick just as well.

If the KDE folks say it is ok, that is surely the best way to do it.

	Jakub




More information about the Kde-optimize mailing list