g++ template name mangling
I need to use the address of a member of a template class in g++ inline assembly (as a compile-time constant value). Is it possible to express this? (I think that I need the mangled name of T<U>::x
).
template < typename U >
struct T {
static int x;
};
template < typename U >
void f () {
开发者_如何学Go asm ("somecommand T<U>::x");
}
Assuming you're using linux, you can use nm.
nm --demangle foo.o gives you the demangled names for your symbols nm --no-demangle foo.o gives you the mangled names for your symbols.
Then you can compare the output of these 2 files to match up the mangled name to the demangled name.
I'd use objdump
to extract the mangled name from an object which references it (you can use c++filt
to go in the other direction but I know of no standalone program giving the mangled name; you could use the spec http://www.codesourcery.com/public/cxx-abi/abi.html and creates a mangler or do the mangling manually, but that's probably overkill).
精彩评论