[LLVMdev] how to use the shadow-stack?

Nicolas Ojeda Bar nojb at math.harvard.edu
Tue Apr 5 08:46:46 PDT 2011


Hi,

I'm trying to start using gc with llvm, and was trying to get
started with the shadow-stack plugin. I'm having trouble putting
everything together, even in this simple case. My compiler generates
the necessary gcroot instructions and for now I would be glad just
being able to walk through the roots and print out some numbers.

For example, I have the following my.ll file:

my.ll:

declare {} @__printi(i64)

define i32 @mymain() gc "shadow-stack" {
entry:
  %0 = alloca [0 x i64]*
  %1 = call [0 x i64]* @malloc(i64 80)
  store [0 x i64]* %1, [0 x i64]** %0
  %2 = bitcast [0 x i64]** %0 to i8**
  call void @llvm.gcroot(i8** %2, i8* null)
  %3 = getelementptr [0 x i64]* %1, i32 0, i32 2
  %4 = load i64* %3
  %printi = call {} @__printi(i64 %4)
  ret i32 0
}

declare noalias [0 x i64]* @malloc(i64) nounwind

declare void @llvm.gcroot(i8**, i8*) nounwind

I'm allocating a 10 element i64 array and then printing
its third element using a library function printi.

On the other hand, I have copied on the file gc.cpp the
code given in the LLVM GC documentation defining a visitor
function visitGCRoots for the shadow-stack plugin and finally
I have on mylib.c the following:

mylib.c

#include <stdio.h>

void __printi (long x)
{
  printf ("%ld\n", x);
}

extern int mymain (void);

int main (void)
{
  return mymain ();
}

Now I'm trying to compile everything with

> llc my.ll
> g++ my.s mylib.c gc.cpp

But get the following error

ld: in /var/folders/Ea/EakEx6b+GBSo6cUn2AnFZk+++TI/-Tmp-//ccTjTjtW.o, section not found for address 0x6D200E00000004DD
collect2: ld returned 1 exit status

How do I have to do to compile?

Thanks!
N



More information about the llvm-dev mailing list