Correlating stack map with call frames.

Hi all,

I’m writing a GC plugin, targeting x86_64. I’m stuck on handling stack maps. I generate assembly for them like in the documentation: http://llvm.org/docs/GarbageCollection.html#emitting-assembly-code-gcmetadataprinter and now I’m trying to figure out the best way to correlate stack maps with call frames.

I have an idea to put a label before every stack map entry and then put the address of this label within well known offset from the function. Then, while walking the call stack and having function address I could retrieve relevant stack map entry…
My current approach to generating the label for stack map entries looks like this:

MCSymbol *ala = AP.OutContext.GetOrCreateSymbol(StringRef(“ala”));
OS.EmitLabel(ala);
But then, I don’t know how to emit the address of the label near the function. I mean, I think I’d use something like this ‘OS.EmitSymbolValue(ala, 4)’, but I’m not sure where I should hook into to achieve this.

Note that I’m fairly new to LLVM and the approach I described above does not necessarily make much sense. I’d pleased to hear the proper way to handle stack maps.

Regards,
Paweł

Pawel,

Sorry for taking so long to reply. I just stumbled across your email again and realized I’d never gotten around to responding.

I would suggest that you not attempt to use the existing gc_root mechanism provided by LLVM today. It’s buggy, not well supported, and essentially no one uses it. I am actively hoping to kill it within the near future.

I’d recommend taking a look at the work we’ve been doing on safepoint placement here: . The actual late safepoint placement pass is still under active development and isn’t necessarily ready for general use (though feedback is appreciated!), but the supporting infrastructure is fairly mature at this point. If you’re willing to do eager safepoint insertion in your IR generator, everything should work fairly reliably. In particular, the data your original question asked would be available in the StackMap section which is fairly well documented. All you’d need to do would be write a parser. (Well, and fix/report any bugs you might encounter…) Philip