[LLVMdev] Troubles with llvm.gcroot and exception handling

Paul Melis llvm at assumetheposition.nl
Tue Dec 1 13:44:52 PST 2009

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 at 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" {
    %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 at juggle2:~/projects/llvm_gc> llc root.ll
22:40|melis at juggle2:~/projects/llvm_gc> gcc -o r root.s
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 at juggle2:~/projects/llvm_gc> cat root.s
    .file    "root.ll"

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

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

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


More information about the llvm-dev mailing list