KoblentsBlog Photography
Contact About
GCC Name Mangling
I recently had an interesting bit of code to work with - functions were aliased to a mangled function name. I had changed some code, and now the project refused to compile, saying that the name could not be found. I wondered how to solve this chicken and egg problem: the mangled name is output by the compiler, but it won't compile when there are errors.
Turns out you can do it manually!
// Start with _Z
// Then an N
// Then the length of the class name (3), then the class name (Foo)
// Then the length of the function name (3), then the function name (bar)
// Then E
// Then return type (void - v)
#define MYFOOBARALIAS     __attribute__ ((weak, alias ("_ZN3Foo3barEv")))

void Foo::bar() {
Ches Koblents
January 15, 2015
« Newer Older »
© Copyright Koblents.com, 2012-2017