[LLVMdev] Segment section

Tim Northover t.p.northover at gmail.com
Thu Feb 20 01:37:43 PST 2014


> I've been playing lately a lot with LLVM Interpreter. During the execution
> of IR I would like to know where my variables are allocated (e.g. stack,
> heap, global). Is there a function inside of the execution engine which
> provides such information?

Are you interested in the classification of an underlying address
(likely to be invariant over an object's lifetime), or the value of
the variable at some random point during execution (where the answer
may be "it's in register r10 at the moment")?

LLVM doesn't provide a function for the first one, you might start by
looking is at a process's memory map (/proc/$PID/map on Linux,
presumably with some libdl interface) and decide which part your
address is in. Debuggers have to do this kind of thing, so you might
find helpful source snippets there.

For the second, we've recently got an @llvm.experimental.stackmap
intrinsic (http://llvm.org/docs/StackMaps.html), which can provide the
information in a separate area for use by JITs and so on. Its support
may be limited at the moment though (x86 Darwin I'm fairly sure of,
possibly Linux too by now).

Cheers.

Tim.



More information about the llvm-dev mailing list