Howdy do LLVM folks! 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). Not sure this IR is correct but here is what I've been playing with (gc.ll): declare void @llvm.gcroot(i8 **, i8*) declare void @llvm_gc_collect() define void @foo() gc "shadow-stack" { ; int *pa = malloc(sizeof(int)); %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; %t0 = add i32 99,0 %t1 = load i32** %pa ;%t2 = getelementptr i32** %t1, i32 0 store i32 %t0, i32* %t1 store i32* null, i32** %pa; say it's dead ret void } define void @main() { call void @foo() call void @llvm_gc_collect() ret void } Naturally I find ShadowStackCollector.cpp but even crazy links like this: gcc -lLLVMLinker -lLLVMipo /usr/local/lib/LLVMInterpreter.o - lLLVMInstrumentation /usr/local/lib/LLVMExecutionEngine.o /usr/local/ lib/LLVMJIT.o -lLLVMDebugger -lLLVMBitWriter /usr/local/lib/LLVMX86.o -lLLVMSelectionDAG -lLLVMCodeGen -lLLVMScalarOpts - lLLVMTransformUtils -lLLVMipa -lLLVMAsmParser -lLLVMArchive - lLLVMBitReader -lLLVMAnalysis -lLLVMTarget -lLLVMCore -lLLVMSupport - lLLVMSystem /usr/local/llvm-2.2/lib/CodeGen/Release/ ShadowStackCollector.o gc.s don't find the llvm_gc_collect. Tried my best to do a strings on all libs to find...must be out of C++ practice. Clearly I'm including the compiler not runtime stuff above, but trying everything. Can anybody help a guy out? Terence
Hi Terence, 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, Gordon
On Apr 20, 2008, at 5:36 PM, Gordon Henriksen wrote:> 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.doh! That's how I missed the binary. thanks!> 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.Ok, copying; can't find ShadowStackEntry though. Even make in that dir doesn't work: /usr/local/llvm-2.2/runtime/GC/SemiSpace $ sudo make Password: llvm[0]: Compiling semispace.c for Release build (bytecode) semispace.c:107: error: expected specifier-qualifier-list before 'ShadowStackEntry' semispace.c:111: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token semispace.c: In function 'llvm_cg_walk_gcroots': semispace.c:114: error: 'StackEntry' undeclared (first use in this function) semispace.c:114: error: (Each undeclared identifier is reported only once semispace.c:114: error: for each function it appears in.) semispace.c:114: error: 'R' undeclared (first use in this function) make: *** [/usr/local/llvm-2.2/runtime/GC/SemiSpace/Release/ semispace.ll] Error 1 It *seems* like it could be StackEntry instead? Perhaps this is a type I must include / generate for my type system?>> >> %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.Yep, was going to get to that once I could bind; was trying one GC thing at a time. :)> 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.Will do that too :) Got a simple, complete t.ll file that works with the semispace thing? I could reproduce stuff from the shadowstack paper I guess. how does the gc "shadow-stack" gcroot intrinsic work exactly? I couldn't read the assembly very well. Seems my example above wouldn't work would it unless i create/fill in a shadow stack record? Taking a giant step back, I can build something similar to semispace.c myself so I'm in control of my world, right? i would set up the shadow stack using IR instructions and could avoid gcroot by notifying my collector as I see fit... Sorry I'm so lost...just trying to figure out what llvm does for me and what I have to do. Ter -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080420/f3843606/attachment.html>