This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

dlopen, RTLD_GLOBAL and global variables


Hey all,
   I'm trying to make a wrapper library that is loaded via LD_LIBRARY_PATH,
and then dlopens the wrapped library with RTLD_GLOBAL.  the wrapper library
gets called for all functions it's interested in, does something (like log
the call), and then calls the 'real' function, and returns its result.  The
goal is to be completely transparent to the application; we want to avoid
recompilation of either the original library or the application.
   That sounds simple enough, and actually is, unless the original library
has global variables.
   For example, I've written a wrapper libgtk-1.2.so that wraps all of
gtk's functions. GTK makes a number of global variables available to
applications.  any application references one of these variables will die on
execution when ran with my wrapper library. ie:
   'gcalc' runs fine, but
   'LD_LIBRARY_PATH=$PWD gcalc'  dies with:
      gcalc: relocation error: /usr/lib/libgnomeui.so.32: undefined symbol:
GTK_TYPE_GDK_COLOR

   GTK_TYPE_GDK_COLOR is declared in gtk/gtktypebuiltins.h as
      extern GtkType GTK_TYPE_GDK_COLOR;

   A simple 'hello world' gtk app which doesn't reference any of these
variables will run fine with or without the wrapped lib.

   I attached a gzipped shell archive of what I'm trying to do.  Inside the
archive is a README that further explains it.

   Any one have any ideas on how I can give applications access to global
variables transparently through the wrapper library?  Is this a problem with
dlopen and RTLD_GLOBAL or something I'm not understanding correctly, or just
missing (flags to ld...).

   If this question doesn't really fit on this list, please point me
somewhere else that I can ask.  This is the best place I could think of.

Scott Moser
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-1533   T/L: 678-1533
ssmoser@us.ibm.com , internal zip: 9812

Attachment: wraptest.sh.gz
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]