[llvm-dev] Passing stack pointer to statepoint-gc

Jordan Rudd via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 7 17:22:44 PST 2018


Hi,

I'm trying to use the statepoint-example strategy to build a simple garbage collector. After using the PlaceSafepoints and RewriteStatepointsForGC passes, I can successfully generate a stack map in my binary and call into my runtime's gc poll.

As far as I can tell, I need the stack pointer at the point of the poll to find the correct frame in the stack map. I'm having trouble doing that.

One library I looked at online (statepoint-utils) simply defines a helper function written in assembly that pushes the RSP register to RDI before calling into the runtime, so that the runtime gc polling function can read it as a parameter.

I was trying to do the same thing except in llvm, so from my gc.safepoint_poll definition, I tried adding these lines:

declare void @runtime_safepoint_poll(i64)
declare i64 @llvm.read_register.i64(metadata) #1
!0 = !{!"rsp\00"}

; Read the stack pointer and pass it to our polling function (assumes x64)
define void @gc.safepoint_poll() {
  %stackpointer = call i64 @llvm.read_register.i64(metadata !0)
  call void @runtime_safepoint_poll(i64 %stackpointer)
  ret void
}

attributes #1 = { "gc-leaf-function" nounwind readnone }

Note that the target triple is x86_64-pc-windows-msvc.

When I test this, the values that come from reading RSP are never in the address space of the module. Like, not even close.

As far as I can tell, this should work, and I'm a little stymied as to why I'm getting back garbage. Do I misunderstand the read_register call here?

Thanks,
Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181108/53e15406/attachment.html>


More information about the llvm-dev mailing list