Question

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.

Was it helpful?

Solution

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

http://mentorembedded.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!

OTHER TIPS

Not sure if this will help.

Searching for mangle in the XCode 4.6 docset, I found

LINKER_DISPLAYS_MANGLED_NAMES (Display Mangled Names) Description: Boolean value. Specifies whether the linker displays mangled names for C++ symbols. This information can help in diagnosing C++ linking problems. Values: YES: The linker displays mangled names for C++ symbols (ld --no-demangle). NO: The linker does not display mangled names for C++ symbols. Default value: NO

So I can't tell you what ji and Z7 mean, but this might help you improve your linker messages.

Hope that helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top