Mangled name of c++ symbol as string

Helge Bahmann hcb@chaoticmind.net
Thu Apr 19 11:40:00 GMT 2007


I have to access C++ symbols in multiple places through their linker names and 
wondered if there is something more maintainable than having 
to "brain-mangle" the names? What I would need is a builtin that transforms a 
name into its mangled representation as string at compile-time.

Essentially I would like to replace something like

__asm__(".set _ZN5media11colorspaces11YUV_CCIR601E, 
_ZN5media11colorspaces3YUVE\n"));

with

__asm__(".set " __mangle__(media::colorspaces::YUV_CCIR601E)  "," 
__mangle__(media::colorspace::YUV) "\n");

(to create a symbol alias) or

dlsym(hdl, "_ZN5media11colorspaces3YUVE");

with

dlsym(hdl, __mangle__(media::colorspaces::YUV));

As far as I could find the only assistance provided with name-mangling is 
run-time and only deals with the inverse problem. Does something like this 
exist (or is there a good reason why it *doesn't* exist and I should not be 
doing what I do?)
-- 
Mathematicians stand on each other's shoulders while computer scientists stand 
on each other's toes.
-- Richard Hamming



More information about the Gcc-help mailing list