Troubles with llvm.gcroot and exception handling

Hi all,

I'm toying around with LLVM's GC support and am struggling with the
following. I have a little test snippet (a .ll file with IR) that uses
llvm.gcroot to mark a GC root, but when I compile it to assembly with
llc, followed by generating an executable with gcc I get an error
related to exception handling:

22:40|melis@juggle2:~/projects/llvm_gc> cat root.ll
%obj = type { i8*, i8, i8 }

declare void @llvm.gcroot(i8**, i8*) nounwind
declare i8* @malloc(i32) nounwind

define i32 @main() nounwind gc "shadow-stack" {
entry:
    %ptr = alloca %obj*
    %ptr_i8 = bitcast %obj** %ptr to i8**
    call void @llvm.gcroot(i8** %ptr_i8, i8* null)

    %t = call i8* @malloc(i32 6)
    %myobj = bitcast i8* %t to %obj*
    store %obj* %myobj, %obj** %ptr

    ret i32 0
}
22:40|melis@juggle2:~/projects/llvm_gc> llc root.ll
22:40|melis@juggle2:~/projects/llvm_gc> gcc -o r root.s
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/../../../../i686-pc-linux-gnu/bin/ld:
error in /tmp/ccGhPZDb.o(.eh_frame); no .eh_frame_hdr table will be created.

I'm actually puzzled that exception handling code is generated, and more
so that it is caused by the llvm.gcroot call. If I comment that one out
all no exception handling stuff is created:

22:42|melis@juggle2:~/projects/llvm_gc> cat root.s
    .file "root.ll"

    .text
    .align 16
    .globl main
    .type main,@function
main: # @main
# BB#0: # %entry
    subl $12, %esp
    movl $6, (%esp)
    call malloc
    movl %eax, 8(%esp)
    xorl %eax, %eax
    addl $12, %esp
    ret
    .size main, .-main
    .type llvm_gc_root_chain,@object
    .section .gnu.linkonce.b.llvm_gc_root_chain,"aw",@nobits
    .comm llvm_gc_root_chain,4,4 #
@llvm_gc_root_chain

    .section .note.GNU-stack,"",@progbits

Any clues? This is on 32-bit x86, linux with binutils 2.18.

Regards,
Paul

Hi Paul,

22:40|melis@juggle2:~/projects/llvm_gc> llc root.ll
22:40|melis@juggle2:~/projects/llvm_gc> gcc -o r root.s
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/../../../../i686-pc-linux-gnu/bin/ld:
error in /tmp/ccGhPZDb.o(.eh_frame); no .eh_frame_hdr table will be created.

the assembler you pasted assembles for me on x86-32 linux.

I'm actually puzzled that exception handling code is generated, and more
so that it is caused by the llvm.gcroot call. If I comment that one out
all no exception handling stuff is created:

The EscapeEnumerator code in ShadowStackGC.cpp adds cleanup code using
invoke and unwind - might be related to this?

Ciao,

Duncan.