C++ name mangling and dlopen()

Alexandre Oliva aoliva@redhat.com
Fri Sep 28 17:29:00 GMT 2001


On Sep 24, 2001, Kamil Burzynski <K.Burzynski@adbglobal.com> wrote:

> only solution found by me is to call

> pf = (void (*)( void )) dlsym( handle, "foo__1A" );

> Is there any simple solution for that problem?

Nope.

A not-so-simple one would be to have an STL map that maps symbol names
(or any other mnemonic names, for that matter) to their corresponding
addresses.  The shared library would then have to register these
symbols in the map, which it could do at load time, with a dynamic
constructor.

Yet another option, significantly more complicated, would be to walk
the symbol table of a just-loaded library, demangling each symbol and
registering it into such a map.  But beware that the symbol demangler
in libiberty is licensed under the GNU GPL, and that the dynamic
symbol table is actually a hashtable that you'd have to decode to
walk.  I'm not sure there are functions available that already do all
this dirty work.


Yet another option would be to write a name mangler, but this would
probably require a non-trivial amount of annotation in the symbol
names to be able to tell template specializations, namespaces and
such, information that is lost in a human-readable version of the
mangled name, but that would be necessary to map the human-readable
form to the correct mangling.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me



More information about the Gcc-help mailing list