Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anything to change the exports name mangling scheme in GCC?

I'm trying to build a project I have and it has several exported functions. The functions follow the stdcall convention and they get mangled if compiled with GCC as

Func@X

Other compilers mangle the name like this:

_Func@X

Is any way I can force GCC to mangle the names of the exported functions to the later example?

like image 581
JP. Avatar asked Nov 09 '09 20:11

JP.


1 Answers

See this answer.

int Func() __asm__("_Func@X");

This will force GCC to name the symbol _Func@X regardless of what it would have done normally.


Oh right, @ is special: it's used for symbol versioning. I thought that __asm__("...@...") used to work, but I guess it doesn't anymore.

int Func() __asm__("_Func");
__asm__(".symver _Func, _Func@X");

This must be accompanied by a version script file, like:

1 {
  global:
    _Func;
};

given to gcc -Wl,--version-script=foo.version when linking.

like image 133
ephemient Avatar answered Oct 05 '22 13:10

ephemient