Debug information and JIT

Hi,

I have a problem that was reported some time ago but never received
any solution.
See
http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-November/036113.html
http://llvm.org/bugs/show_bug.cgi?id=6981

JIT emitter for X86 aborts when is asked to emit instruction for
opcode 11 (DBG_VALUE).
That opcode comes from @llvm.dbg.declare intrinsic function.

Should this intrinsic be removed in some earlier stage?

Hi Paweł,

I have a problem that was reported some time ago but never received
any solution.

probably the reason that there is no action is surely that the old JIT
implementation is being replaced with the new MCJIT implementation, so
no-one feels very motivated to fix the old JIT since it is going away.
Try passing -use-mcjit to lli.

Ciao, Duncan.

Hi Paweł,

I have a problem that was reported some time ago but never received
any solution.

probably the reason that there is no action is surely that the old JIT
implementation is being replaced with the new MCJIT implementation, so
no-one feels very motivated to fix the old JIT since it is going away.
Try passing -use-mcjit to lli.

Ciao, Duncan.

Thanks for suggestion. Unfortunately, I can't check it now as MCJIT
does not work with my project at the moment.

I have found a simple example in C that causes the crash:

int main() {
  goto L;
L:
  int a = 0;
  return 0;
}

What is compiled to:

define i32 @main() nounwind {
entry:
  %retval = alloca i32, align 4
  %a = alloca i32, align 4
  store i32 0, i32* %retval
  br label %L, !dbg !12

L: ; preds = %entry
  call void @llvm.dbg.declare(metadata !{i32* %a}, metadata !14), !dbg !15
  store i32 0, i32* %a, align 4, !dbg !16
  ret i32 0, !dbg !17
}

The problem is with @llvm.dbg.declare which is the first instruction
of the block.
I reproduced the crash with lli on win32 and mingw32 but not on linux64.

Probably the easiest thing to do here would be to avoid compiling your module with debug information?

-eric

> probably the reason that there is no action is surely that the old JIT
> implementation is being replaced with the new MCJIT implementation, so
> no-one feels very motivated to fix the old JIT since it is going away.
> Try passing -use-mcjit to lli.
>
> Ciao, Duncan.

Thanks for suggestion. Unfortunately, I can't check it now as MCJIT does not
work with my project at the moment.

Why doesn’t it work with your project?

The old JIT emitter does not support debug info, hence the asserts. It is unlikely at this point that debug info support will be added to it in the future. So IMHO, you have two options:

1. If you need debug information emitted to your JITted machine code, use MCJIT.
2. If you don't need debug info, then as Eric has suggested, simply don't build the code with debug info (don't pass -g to clang when generating IR).

Eli

I actually work on a new compiler so debug info is a feature of it.

It looks like the debug information is stripped before the code is
JIT'd but this process can fail in some cases and some
@llvm.dbg.declare are passed to JIT anyway.

If what you say is true and the old JIT cannot emit debug information
so generating debug info in IR makes no sense neither. I will try to
run it with MCJIT. Thanks for advice.

Paweł