-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chapter1: Frame pointer #2
Comments
To be honest, I was quite confused about this whole affair myself, and was secretly hoping for somebody to hop along and say something that would make me tick.. and you did! Thank you. What really drove me mad here is this excerpt from the documentation that I quoted in the first chapter and which goes like this:
Now unless I'm missing something blaringly obvious here, something doesn't add up. Frame-pointer support for In any case, how could the compiler refer to a register that wasn't even maintained back then? And which is only supported for very few platforms anyway, even to this day? So here's what I think is happening here: What we end up with is a situation where the compiler does insert a function-preamble in order to properly maintain the frame-pointer, on some platforms, but still doesn't rely on it for anything. It's only there as a gift for external tooling. This story is kinda driving me mad tbh, so I'm not sure that I'm still making much sense at this point. |
The /doc/asm page could probably use updating if that's the case. Maybe file a bug? |
Yes, there's two different "frame pointer registers" going on here. The one output by the compiler's pseudoassembly, called FP, is a fake register, like TLS and SB, it doesn't exist and the assembler translates it into whatever it wants (specifically, the stack pointer with a different offset). The other "frame pointer" is the actual architecture register, for example BP in amd64. I think they have the same value, but I've never checked. I don't know why the pseudoassembly uses FP instead of using SP directly, it could be a holdover from plan9 or it could be to leave an opening to support |
PS. technically the documentation isn't wrong just confusing. |
But that's the thing: AFAICT, the compiler uses neither the virtual one nor the hardware one (although the documentation states differently). :/ I think @dgryski is right; I'll file an issue when I get a minute or two, and hopefully we'll get some valuable insights straight from the source. |
I've added a link to this discussion in the relevant part of chapter 1; and will be closing this now. Hopefully I'll take the time to update chapter 1 with all these learnings some day. |
This has finally been elucidated, as far as I'm concerned; see #21 (comment) for a detailed explanation. TL;DR: All of this confusion (at least on my part) stemmed from the fact that I was looking for something that simply doesn't exist, except that the documentation says that it does, except that no, really, it doesn't. There is no such thing as the virtual SP. There is no such thing as the virtual FP. Those don't exist anymore. They are relics of the past and are only mentioned in this documentation because it's outdated. There is indeed support for maintaining the hardware frame-pointer on some architectures in recent versions of the toolchain, to help external debuggers do their job, as you'd expect. I'm pretty sure @aarzilli had it right all along; except I couldn't wrap my head around his explanations as I was desperately looking for this virtual FP that keeps being mentioned but actually doesn't exist anywhere outside of the outdated documentation. |
Also, I really, really need to update that chapter. |
My earlier comment (#2 (comment)) is misleading: what I mean when I say that these virtual registers don't exist anymore is that they won't ever be shown to you in assembly outputs generated by the standard go tools ( Once again, I'd suggest having a look at the discussion I've had with @cch123 in #21 for the nitty gritty details. |
But it doesn't, starting with 1.8 (or was it 1.7 or 1.9?) the compiler emits instructions to use the frame pointer for its intended purpose, to help dtrace-like debugging tools. Just like you say later in the chapter. Maybe I'm misunderstanding.
The text was updated successfully, but these errors were encountered: