ioslinkerclangldname-mangling

Clang/LD function demangling?


I have two working compilers, clang on a Mac, which can target iPhone, and clang on an iPhone, which also targets iPhone. Normally both work great, generating binaries and libraries. Libraries produced on the Mac can be linked on the iPhone. But now I face a strange issue: a library is not linking while trying to link on iPhone against a library created on the Mac.

Undefined symbols:
  "__Z7JS_Initji", referenced from:
      _main in test-CgDtHX.o

This is a call to JS_Init, which is defined as a macro which expands differently.

iphone-clang will expand it as:

extern JSRuntime * JS_Init(uint32_t maxbytes, int);

mac-clang will expand as:

extern JSRuntime * JS_Init(uint32_t maxbytes, JSUseHelperThreads useHelperThreads);

I am not sure if the macro expansion is the reason for the linking failure.

Ok, now my question, what exactly ji and Z7 mean in __Z7JS_Initji? Where can I find the table that will show me the correspondence between argument types and those mangling ids? This must be ld docs, but I am unable to find it. Mostly because I do not know good query words for this.


Solution

  • Here's a long reference on how (amongst other things) function name mangling works in GCC/Clang:

    http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling

    In section 5.1.5 Type Encodings, you'll see that the "ji" stands for "unsigned int" and "int".

    _Z at the the start is from section 5.1.2 (prefix for all function names), the "7" is the length of the name "JS_Init".

    Hope that helps!

    edit: updated link to the suggested one since the previous one has disappeared.