[ +khr ]
On Wed, Jul 3, 2019 at 4:46 PM Mohit Verma <vmoh...@gmail.com> wrote:
>
> Hi All,
>
> I am trying to change the ssa phase of Go compiler to do extra work during memory stores.
> For example whenever there is a memory store, I want to make a function call to one of my Go packages instead of the store.
> So, far I have some working changes and I can see the new SSA nodes when I dump SSA using GOSSAFUNC.
>
> I have a couple of questions:
>
> 1. Is there a tool which can covert the SSA nodes back to some version of Go code?
> 2. How does Go team/others develop/make changes to Go compiler? So, far I have been adding prints in the Go compiler (cmd/compile/internal/syntax, gc, & ssa packages) to understand the code flow. But, this is very time consuming. I am sure a better way exists.
Thanks Keith, Ian.Specifically, I am trying to catch all the memory stores/moves during the build SSA phase, and instead call a function that can do things like record the old/new values in a journal.So I changed the methods like (*state).assign, (*state).storeType in gc/ssa.go and injected equivalent SSA nodes to make the function call. I can see the modified SSA code when I generate ssa.html using GOSSAFUNC. This is why I was looking for a tool that could convert SSA form back to Go code so I could see if I caught all the stores.Right now, I am running up against something like this:Escape analysis didn't see the function call, it saw normal assignments & marked variables in stack. Now I inject a function call during buildSSA. Now, before the function call, runtime decided that stack should migrate, and now I get a seg fault.
Thanks Keith.Yes, the function call takes a variadic interface argument, so it would cause the variables to escape if it existed before. To take care of this, I allocate space for the interface during buildSSA & then call runtime.convT2E* functions.1. How do I turn off escape analysis with command-line flag? I couldn't find this option anywhere.
2. Why would having calls to functions marked nosplit, be a problem?The function I am adding would internally call runtime.spanOfHeap() function which is marked nosplit. Will this be a problem?I haven't gone through the stack migration code yet, but this blog by Dave Cheney mentioned that compiler maintains a 768-byte redzone to make sure there is no memory corruption.
I had one other question.3. Is the stack check & runtime.morestack() code inserted by the linker?I see stacksplit code in cmd/internal/obj/ directory which is invoked during compileSSA() in gc/pgen.go.