-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/objdump: order of CMP's arguments doesn't match go tool compile #60920
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
Comments
Change https://go.dev/cl/505375 mentions this issue: |
That way it matches what the compiler's -S flag generates, and what we write in assembly. CMP AX, $16 JLE foo should get to foo if AX <= 16. Without this CL, the disassembly looks like CMP $16, AX JLE foo which reads like we should get to foo if 16 <= AX, which is not what these two instructions actually do. It was originally this way because the CMP instruction parallels the SUB instruction, except it throws away the non-flags result. We write that subtraction as SUB $16, AX // AX <- AX-16 but we don't need to match the SUB's disassembly order, as CMP is not writing to a register output. Update golang/go#60920 (This fixes the underlying issue, but the actual "fixes" comment needs to go on the CL that vendors x/arch containing this CL into the main branch.) Change-Id: Ifa8d3878453d6e33ae144bfdb01b34171c2106a1 Reviewed-on: https://go-review.googlesource.com/c/arch/+/505375 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
The fix has been submitted to x/arch. I think at this point it is best to wait for 1.22 to vendor it into the stdlib. |
The fix has been pulled into the stdlib, so closing. |
CL 505375 fixed this in x/arch and its footer said:
The fix was pulled into the main Go repo in CL 509099, which was included in Go 1.21 starting with RC 3. So moving this to Go1.21 milestone. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Consider this Go code:
I compile this code and emit assembly using two approaches:
go tool compile -S
go build
followed bygo tool objdump
What did you expect to see?
The same order of arguments in CMP instructions
What did you see instead?
In the output of
go tool compile -S
I see:In the output of
go tool objdump
I see:The order of arguments is different. In assembly input (for example https://cs.opensource.google/go/go/+/master:src/hash/crc32/crc32_amd64.s), the order matches what
go tool compile -S
produces:it seems like the issue is with
go tool objdump
The text was updated successfully, but these errors were encountered: