[LLVMdev] Problem linking llvm_gc_collect

Tom Brown tdbrown at uiuc.edu
Sat Dec 11 18:29:39 PST 2004

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"
#define C_LINKAGE
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]

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?


28 70 20 71 2C 65 29 61 9C B1 36 3D D4 69 CE 62 4A 22 8B 0E DC 3E
mailto:tdbrown at uiuc.edu

More information about the llvm-dev mailing list