[LLVMdev] getting started with IR needing GC
gordonhenriksen at mac.com
Sun Apr 20 17:36:50 PDT 2008
On 2008-04-20, at 20:08, Terence Parr wrote:
> I've exhausted what I can do on my own to make a GC example bind
> (usual googling, reading, playing, looking at source). I can't find
> the shadow collector lib or perhaps the -l options needed to link my
> sample (not even to point where I'm figuring out GC actually as I
> can't link).
The shadow stack walker is in the runtime directory with the semispace
heap example. The runtime directory is built to LLVM IR using llvm-
gcc. So it's skipped unless you configure llvm with llvm-gcc support.
Since the semispace heap doesn't actually work (it's an example, at
best), I suggest you simply copy the stack visitor into your project;
it's only a dozen lines of code or so.
> %a = malloc i32
> %pa = alloca i32*
> store i32* %a, i32** %pa
> %c = bitcast i32** %pa to i8**
> call void @llvm.gcroot(i8** %c, i8* null); *pa = 99;
Note that the malloc instruction always allocates from the system
heap, not your managed heap; putting a malloc pointer into a GC
pointer will probably confuse your collector. So you'll likely need to
replace 'malloc i32' with some call into your own allocator.
Your allocator should probably bzero the memory before returning it;
malloc returns uninitialized memory, which will crash the collector if
you reach a collection point before completely initializing the object.
Hope that helps,
More information about the llvm-dev