How to get functions’s start address using the unsafe package?

266 Views Asked by At

I need to get the first cpu instruction of a go function (not assembly or cgo), but in golang, &dummy of func dummy() {} doesn’t lead to the function start address, but to the variable start address on the stack representing the function.

So in my example, &dummy doesn’t lead to a pointer, but to an obscure structure which I failed to find description in golang source code…

1

There are 1 best solutions below

0
Bryce On

Try this:

functionLocation := **(**uintptr)(unsafe.Pointer(&orig))