Skip to content
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

cmd/objdump: confusing disassembly of arm64 BL instruction #53117

Open
kevinGC opened this issue May 27, 2022 · 3 comments
Open

cmd/objdump: confusing disassembly of arm64 BL instruction #53117

kevinGC opened this issue May 27, 2022 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@kevinGC
Copy link

kevinGC commented May 27, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18.2 linux/arm64

This also happens in bazel with go version 1.17.6.

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/parallels/.cache/go-build"
GOENV="/home/parallels/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/parallels/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/parallels/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/parallels/gvisor/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4026508879=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Ran go tool objdump on a binary.

What did you expect to see?

There are many lines that look like:

  iptables.go:320       0x211214                97f9b198                CALL -413288(PC)

However, the offset displayed should be -1653152. Objdump appears to be incorrectly parsing the offset from the instruction 0x97f9b198.

What did you see instead?

-413288. This is because the 2 trailing 0 bits described by the arm documentation appear not to be accounted for.

@cherrymui
Copy link
Member

Thanks for the report. In Go assembly (at least as input for the Go assembler), the n(PC) relative addressing counts the number of instructions, instead of the byte offset. So to some extent this makes sense. But I agree that this is somewhat confusing. Perhaps we should just compute the target's absolute address, instead of relative offset.

@cherrymui cherrymui changed the title cmd/objdump: incorrect disassembly of arm64 BL instruction cmd/objdump: confusing disassembly of arm64 BL instruction May 27, 2022
@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 27, 2022
@cherrymui cherrymui added this to the Backlog milestone May 27, 2022
@kevinGC
Copy link
Author

kevinGC commented May 27, 2022

Ah that makes sense now -- counting instruction offset is the same as (byte_offset >> 2). In that case I don't have a strong opinion anymore, but I agree that an absolute address would disambiguate.

@mengzhuo
Copy link
Contributor

cc @golang/arm

copybara-service bot pushed a commit to google/gvisor that referenced this issue May 31, 2022
`go tool objdump` produces relative offsets for BL instructions as a number of
instructions rather than a number of bytes. Calculate the byte offset ourselves.

Example passing run on ARM machine:
https://buildkite.com/gvisor/pipeline/builds/14732#018106ac-ac8e-4636-9a5a-bde1641b1175

Filed bug upstream about confusing output here:
golang/go#53117

PiperOrigin-RevId: 451425266
copybara-service bot pushed a commit to google/gvisor that referenced this issue May 31, 2022
`go tool objdump` produces relative offsets for BL instructions as a number of
instructions rather than a number of bytes. Calculate the byte offset ourselves.

Example passing run on ARM machine:
https://buildkite.com/gvisor/pipeline/builds/14732#018106ac-ac8e-4636-9a5a-bde1641b1175

Filed bug upstream about confusing output here:
golang/go#53117

PiperOrigin-RevId: 451425266
copybara-service bot pushed a commit to google/gvisor that referenced this issue May 31, 2022
`go tool objdump` produces relative offsets for BL instructions as a number of
instructions rather than a number of bytes. Calculate the byte offset ourselves.

Example passing run on ARM machine:
https://buildkite.com/gvisor/pipeline/builds/14732#018106ac-ac8e-4636-9a5a-bde1641b1175

Filed bug upstream about confusing output here:
golang/go#53117

PiperOrigin-RevId: 452137751
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants