Linking problem

Hi,

I'm writing a pass that implements a jump table with an array of
blockaddress and an indirectbr instruction.

It get a blockaddress in the array (via getelementptr and an index) and
then jump to this basicblock via the indirectbr.

I tried to compile several libraries to test my pass and the run their
test-suite. It works fine with, for e.g, libTomCrypt (in -O0,1,2,3).
With GMP or ImageMagick it works fine in -O0, but whenever I try in
-O1,2,3 it fail and I get a tons of errors like (note that the
compilation/link of the libs itself works, it fails when I make a 'make
check'):

...
./.libs/libtests.a(misc.o):(.rodata+0x5b0): undefined reference to
`.Ltmp491'
./.libs/libtests.a(misc.o):(.rodata+0x5b8): undefined reference to
`.Ltmp492'
./.libs/libtests.a(misc.o):(.rodata+0x5c0): undefined reference to
`.Ltmp493'
./.libs/libtests.a(misc.o):(.rodata+0x5c8): undefined reference to
`.Ltmp494'
...

I tried to modify my pass, call my pass in the PassManagerBuilder at
different places,... But I still got the same errors each time.

I ran out of ideas where to look :frowning: I got this problem both on Linux and
OSX.

Any idea which pass could cause this problem ? Maybe it's a pass in the
backend ?

Cheers !

I don’t know which pass it is, but have you tried dumping the final IR to see whether that IR still contains the right code?

You can do that using opt to do the optimization. You can also use -print-after or -print-after-all to see the IR after each pass.

Thanks for your answer !

Normally, I use verifyFunction(...) or verifyModule(...) to check if my IR is correct. So normally the code should be correct.

I'll try to call my pass with opt, maybe I'll be able to identify the 'faulty' pass.

Thanks again.

I finally found the problem !

When compiling with an optimization level higher than -O0, llvm define
some functions has 'available externally' (like atoi(),...).

Those functions where available in the module when my pass ran, but were
'deleted' in the backend. So when linking, the linker missed some info !

Cheers