[LLVMdev] getting closer!
Terence Parr
parrt at cs.usfca.edu
Mon Apr 21 17:09:37 PDT 2008
Ok, I *might* be getting this from the assembly code. The assembly
code has:
L_llvm_gc_root_chain$non_lazy_ptr:
.indirect_symbol _llvm_gc_root_chain
.long 0
and I see it being used in the function preamble. Is that a ref to an
extern symbol or the def? I.e., is it referring to
StackEntry *llvm_gc_root_chain;
that I must have in my GC C code? (semispace.c has it)
SO! I might be getting this. The shadow stack plugin assumes I have
struct StackEntry {
StackEntry *Next; // Caller's stack entry.
const FrameMap *Map; // Pointer to constant FrameMap.
void *Roots[]; // Stack roots (in-place array).
};
as my stack item layout and I must provide a shadow stack head. From
that, it will push/pop in functions? If so, that's easy enough. :)
What I was/am missing is the explicit link between types and variables
in a GC.c file and the generated machine code. If I can get that last
explicit link, I'm off to the races. Anybody? My IR doesn't seem to
have any roots, even though I've allocated an int and declared a ptr
on the stack.
declare void @llvm.gcroot(i8 **, i8*)
declare void @llvm_gc_collect()
declare i32* @llvm_gc_allocate(i32)
declare void @llvm_gc_initialize(i32)
define void @foo() gc "shadow-stack" {
; int *pa = malloc(sizeof(int));
%a = call i32* @llvm_gc_allocate(i32 4)
%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 @llvm_gc_initialize(i32 1024)
call void @foo()
call void @llvm_gc_collect()
ret void
}
I get llvm_gc_root_chain as null when I try to walk roots.
Ter
More information about the llvm-dev
mailing list