[LLVMdev] getting started with IR needing GC

Terence Parr parrt at cs.usfca.edu
Sun Apr 20 18:05:43 PDT 2008


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>


More information about the llvm-dev mailing list