Easily viewing cross-compiled asm output?

49 views
Skip to first unread message

Eli Lindsey

unread,
Oct 2, 2022, 9:46:00 PM10/2/22
to golang-nuts
I’m on arm64 Darwin and wanted to view the asm output for amd64 Darwin.

Using a simple hello world example, this worked and output arm asm:

$ go tool compile -S hello.go

This worked and built a full x86 binary:

$ GOARCH=amd64 go build hello.go

But this failed:

$ GOARCH=amd64 go tool compile -S hello.go
hello.go:4:5: could not import fmt (file not found)

To fix it, I downloaded a binary release for amd64 and pointed go tool to its pkg directory. This now works:

$ GOARCH=amd64 go tool compile -I /path/to/go/release/pkg/darwin_amd64 -S hello.go

My question: is there an easier way that I’ve missed? Presumably go build had built fmt _somehow_ since it successfully made an x86 binary. I read the docs for go build and cmd/compile to see if I could get build to output the packagefiles it produces in a way that cmd/compile can point to or some such, but I didn’t see an obvious way.

-eli

Ian Lance Taylor

unread,
Oct 2, 2022, 10:00:26 PM10/2/22
to Eli Lindsey, golang-nuts
GOARCH=amd64 go build -gcflags=-S hello.go

Ian
Reply all
Reply to author
Forward
0 new messages