How to call a name-mangled symbol from C?
module.name:version void* function(TypeSig); // Type of the function
I’d want to be able to use codepaths written in my language in C. The function calling convention is about the same. It’s just that I must mangle in the version and the module path inside the symbols I export, and I have the same identifier convention as C has, therefore I can’t just use underscore.
IIUC, you are defining your own language, and are looking for a suitable name mangling algorithm.
You might want to use the Intel et.al. Itanium name mangling algorithm, which is used by g++ on all platforms. For the specific case, you might mangle each of your names as if the C++ declaration was
which would mangle as
As all your symbols use that algorithm, they can’t conflict with each other. They also can’t conflict with a standard C function called
_ZN6module4name4V1_08functionEi, as all names starting with _Z (or, _UPPERCASE) are reserved for the implementation (of C). If you want convenient callability from g++, you can use this exact convention; else you pick a letter different from Z.