cmd/internal/obj/x86: correct pcsp for ADJSP
cmd/internal/obj/x86: correct pcsp for ADJSP

The x86 assembler supports an "ADJSP" pseudo-op that compiles to an
ADD/SUB from SP. Unfortunately, while this seems perfect for an
instruction that would allow obj to continue to track the SP/FP delta,
obj currently doesn't do that. As a result, FP-relative references
won't work and, perhaps worse, the pcsp table will have the wrong
frame size.

We don't currently use this instruction in any assembly or generate it
in the compiler, but this is a perfect instruction for solving a
problem in #24543.

This CL makes ADJSP useful by incorporating it into the SP delta
logic.

One subtlety is that we do generate ADJSP in obj itself to open a
function's stack frame. Currently, when preprocess enters the loop to
compute the SP delta, it may or may not start at this ADJSP
instruction depending on various factors. We clean this up by instead
always starting the SP delta at 0 and always starting this loop at the
entry to the function.

Why not just recognize ADD/SUB of SP? The danger is that could change
the meaning of existing code. For example, walltime1 in
sys_linux_amd64.s saves SP, SUBs from it, and aligns it. Later, it
restores the saved copy and then does a few FP-relative references.
Currently obj doesn't know any of this is happening, but that's fine
once it gets to the FP-relative references. If we taught obj to
recognize the SUB, it would start to miscompile this code. An
alternative would be to recognize unknown instructions that write to
SP and refuse subsequent FP-relative references, but that's kind of
annoying.

This passes toolstash -cmp for std on both amd64 and 386.

Change-Id: Ic6c6a7cbf980bca904576676c07b44c0aaa9c82d
Reviewed-on: https://go-review.googlesource.com/c/go/+/200877
Run-TryBot: Austin Clements <7ea35d812706d9213868749011af1ed4fa2f6aa0@google.com>
TryBot-Result: Gobot Gobot <66cb808b70d30c07676d5e946fee83fd561249e5@golang.org>
Reviewed-by: David Chase <ae171625adc8645b8b79b7e405a6da5aba5341e0@google.com>

golang/go,golang/go,nawawi/go,golang/go,CAFxX/go,cloudflare/go,nawawi/go,cloudflare/go,cloudflare/go,golang/go,nawawi/go,cloudflare/go,CAFxX/go,CAFxX/go,CAFxX/go,golang/go,CAFxX/go,akutz/go,cloudflare/go,CAFxX/go,akutz/go,akutz/go,cloudflare/go,cloudflare/go,nawawi/go,CAFxX/go,nawawi/go,akutz/go,akutz/go,golang/go,golang/go,nawawi/go,akutz/go,cloudflare/go,nawawi/go,akutz/go,akutz/go,golang/go,nawawi/go,CAFxX/go