Accessing a global and MCJIT

Hello,

I’m having a problem while accessing a global variable from a Module compiled by the MCJIT.

For context, I have two modules (namely A and B). Module A is compiled by clang, while Module B is compiled by the MCJIT.

In Module A I defined a global variable like this:
@A = common global [800 x [800 x double]] zeroinitializer, align 16

Module B, references that global like this:

@A = external global [800 x [800 x double]]

The problem that I have is that the MCJIT is not able to solve the symbol for @A. I get the following error:

LLVM ERROR: Program used external function ‘A’ which could not be resolved!

As far as I know, the MCJIT by default uses dlsym to solve the symbols. I tried to get the address for @A using dlsym, but i get NULL.

After compiling Module A, I used llvm-nm to check the symbol table:

0000000000608540 B A
0000000000aea540 B B
0000000000fcc540 B C
00000000006081c8 d _DYNAMIC
0000000000608480 d GLOBAL_OFFSET_TABLE
0000000000402460 R _IO_stdin_used

Any clues?

Thank you,

I suspect this comes down to how your linking module A. If you directly pointing MCJIT at the object file, the common declaration is fine. If not, you probably need to mark this as an explicit symbol.

According to the LangRef, a common symbol is not necessarily exported from the link step. As a result, if you’re building a shared library, the symbol won’t be exported.

Philip