Problem linking llvm_gc_collect

We are trying to start an explicit garbage collect by calling
llvm_gc_collect(). We have the function declared in GCInterface.h
with the following lines:
#ifdef __cplusplus
#define C_LINKAGE extern "C"
#else
#define C_LINKAGE
#endif
C_LINKAGE void llvm_gc_initialize(unsigned InitialHeapSize);
C_LINKAGE void llvm_gc_collect();

and I can see it in the gc byte code,
$ llvm-nm GC/Generational/Debug/generational.bc | egrep '(collect|initialize)'
         T llvm_gc_initialize
         t _Z22collect_between_levelsii
         T llvm_gc_collect
         d _ZZ18llvm_gc_initializeE19__PRETTY_FUNCTION__
         d _ZZ22collect_between_levelsiiE19__PRETTY_FUNCTION__

and the unlinked calls from our test code:
$ llvm-nm GC/gc_alloc_type_tag.bc | egrep '(collect|initialize)'
         U llvm_gc_initialize
         U llvm_gc_collect

then I link with
$ llvm-link -v -f -o linked.bc GC/gc_alloc_type_tag.bc ../../../../runtime/GC/Generational/Debug/generational.bc
Loading 'GC/gc_alloc_type_tag.bc'
Loading '../../../../runtime/GC/Generational/Debug/generational.bc'
Linking in '../../../../runtime/GC/Generational/Debug/generational.bc'
Writing bytecode...

and look at nm
$ llvm-nm linked.bc | egrep '(collect|initialize)'
         T llvm_gc_initialize
         U llvm_gc_collect
         t _Z22collect_between_levelsii
         T llvm_gc_collect
         d _ZZ18llvm_gc_initializeE19__PRETTY_FUNCTION__
         d _ZZ22collect_between_levelsiiE19__PRETTY_FUNCTION__

Note that llvm_gc_collect is listed twice, as T and U.
llvm_gc_initialize is only in T.

Running linked.bc fails when it calls llvm_gc_collect
$ lli linked.bc
...
llvm_gc_allocate_level(12, 0) -> 0x872e218, 39 bytes free
ERROR: Program used external function 'llvm_gc_collect' which could
not be resolved!
lli((anonymous namespace)::PrintStackTrace()+0x1a)[0x8573e52]
lli((anonymous namespace)::SignalHandler(int)+0xcb)[0x85740c5]
[0xffffe420]
lli(llvm::JIT::getPointerToFunction(llvm::Function*)+0x129)[0x830f85f]

The only difference I can see between llvm_gc_collect and
llvm_gc_initialize is that
_ZZ18llvm_gc_initializeE19__PRETTY_FUNCTION__ is in the data section
of generational.bc but there is no corresponding munged version of
llvm_gc_collect. Any hints on making this work?

Thanks,
Tom

We are trying to start an explicit garbage collect by calling
llvm_gc_collect(). We have the function declared in GCInterface.h
with the following lines:
#ifdef __cplusplus
#define C_LINKAGE extern "C"
#else
#define C_LINKAGE
#endif
C_LINKAGE void llvm_gc_initialize(unsigned InitialHeapSize);
C_LINKAGE void llvm_gc_collect();

Try:

C_LINKAGE void llvm_gc_collect(void);

Also, make sure that symbols that you need exported are in the runtime/GC/gc_exported_symbols.lst file.

-Chris

and I can see it in the gc byte code,
$ llvm-nm GC/Generational/Debug/generational.bc | egrep '(collect|initialize)'
        T llvm_gc_initialize
        t _Z22collect_between_levelsii
        T llvm_gc_collect
        d _ZZ18llvm_gc_initializeE19__PRETTY_FUNCTION__
        d _ZZ22collect_between_levelsiiE19__PRETTY_FUNCTION__

and the unlinked calls from our test code:
$ llvm-nm GC/gc_alloc_type_tag.bc | egrep '(collect|initialize)'
        U llvm_gc_initialize
        U llvm_gc_collect

then I link with
$ llvm-link -v -f -o linked.bc GC/gc_alloc_type_tag.bc ../../../../runtime/GC/Generational/Debug/generational.bc
Loading 'GC/gc_alloc_type_tag.bc'
Loading '../../../../runtime/GC/Generational/Debug/generational.bc'
Linking in '../../../../runtime/GC/Generational/Debug/generational.bc'
Writing bytecode...

and look at nm
$ llvm-nm linked.bc | egrep '(collect|initialize)'
        T llvm_gc_initialize
        U llvm_gc_collect
        t _Z22collect_between_levelsii
        T llvm_gc_collect
        d _ZZ18llvm_gc_initializeE19__PRETTY_FUNCTION__
        d _ZZ22collect_between_levelsiiE19__PRETTY_FUNCTION__

Note that llvm_gc_collect is listed twice, as T and U.
llvm_gc_initialize is only in T.

Running linked.bc fails when it calls llvm_gc_collect
$ lli linked.bc
...
llvm_gc_allocate_level(12, 0) -> 0x872e218, 39 bytes free
ERROR: Program used external function 'llvm_gc_collect' which could
not be resolved!
lli((anonymous namespace)::PrintStackTrace()+0x1a)[0x8573e52]
lli((anonymous namespace)::SignalHandler(int)+0xcb)[0x85740c5]
[0xffffe420]
lli(llvm::JIT::getPointerToFunction(llvm::Function*)+0x129)[0x830f85f]

The only difference I can see between llvm_gc_collect and
llvm_gc_initialize is that
_ZZ18llvm_gc_initializeE19__PRETTY_FUNCTION__ is in the data section
of generational.bc but there is no corresponding munged version of
llvm_gc_collect. Any hints on making this work?

Thanks,
Tom

-Chris