aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/objfile/disasm.go
AgeCommit message (Collapse)Author
2024-12-11cmd/internal/objfile: break out dissassemblers to another packageCherry Mui
Currently, cmd/internal/objfile provides dissassembly routines for various architectures, which depend on dissassemblers from x/arch. cmd/internal/objfile is imported in tools that need dissassembly (objdump, pprof) and tools that don't need dissassembly (nm, addr2line). Adding/improving disassembly support for more architectures can cause binary size increase, and for some tools (nm, addr2line) it is not necessary. This CL breaks out dissassembly routines to a different package, which is only imported in tools that need dissassembly. Other tools can depend on cmd/internal/objfile without the disassembly code from x/arch. This reduces binary sizes for those tools. On darwin/arm64, old new cmd/addr2line 4554418 3648882 -20% cmd/addr2line (-ldflags=-w) 3464626 2641650 -24% cmd/nm 4503874 3616722 -20% cmd/nm (-ldflags=-w) 3430594 2609490 -24% For #70699. Change-Id: Ie45d5d5c5500c5f3882e8b3c4e6eb81f0d815292 Reviewed-on: https://go-review.googlesource.com/c/go/+/634916 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2024-11-21all: fix some function names and typos in commentcuishuang
Change-Id: I07e7c8eaa5bd4bac0d576b2f2f4cd3f81b0b77a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/630055 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-11-06cmd/objdump: add s390x plan9 disasm supportSrinivas Pokala
This CL provides vendor support for s390x disassembler plan9 syntax. cd $GOROOT/src/cmd go get golang.org/x/arch@master go mod tidy go mod vendor For #15255 Change-Id: I20c87510a1aee2d1cf2df58feb535974c4c0e3ef Reviewed-on: https://go-review.googlesource.com/c/go/+/623075 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Vishwanatha HD <vishwanatha.hd@ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-10-29cmd/internal/objfile,cmd/objdump: add disassembly support for riscv64Joel Sing
Add support to `go tool objdump` for disassembling riscv64 binaries. Revendor to bring in cmd/vendor/golang.org/x/arch/riscv64/riscv64asm, which provides the actual disassembly implementation. Fixes #36738 Change-Id: I0f29968509041c0c5698fc2d6910a6a0bea9d3c0 Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64 Reviewed-on: https://go-review.googlesource.com/c/go/+/622257 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2024-09-19cmd/objdump: add loong64 disassembler supportGuoqi Chen
This CL provides vendor support for loong64 disassembler gnu and plan9 syntax. cd $GOROOT/src/cmd go get golang.org/x/arch@master go mod tidy go mod vendor Change-Id: Ic8b888de0aa11cba58cbf559f8f69337d1d69309 Reviewed-on: https://go-review.googlesource.com/c/go/+/609015 Reviewed-by: Meidan Li <limeidan@loongson.cn> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
2024-08-21cmd/objdump: add s390x GNU disasm supportSrinivas Pokala
This CL provides vendor support for s390x disassembler gnu syntax. go get golang.org/x/arch@master go mod tidy go mod vendor For #15255 Change-Id: Ia75fa515e7ea7d56913a28147c65650a7ab3062c Reviewed-on: https://go-review.googlesource.com/c/go/+/581015 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Vishwanatha HD <vishwanatha.hd@ibm.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Auto-Submit: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bill O'Farrell <billotosyr@gmail.com>
2022-09-20all: replace package ioutil with os and io in srcAndy Pan
For #45557 Change-Id: I56824135d86452603dd4ed4bab0e24c201bb0683 Reviewed-on: https://go-review.googlesource.com/c/go/+/426257 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2020-03-30cmd/objdump: add support for -gnu option on Go objdumpLynn Boger
This adds support for the -gnu option on Go objdump. When this option is used, then output will include gnu assembly in comments alongside the Go assembly. The objdump test was updated to test this new option. This option is supported for the arches found in golang.org/x that provide the GNUsyntax function. Updates #34372 Change-Id: I9e60e1691526607dda3c857c4564dcef408b8391 Reviewed-on: https://go-review.googlesource.com/c/go/+/225459 Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-03-12cmd/objdump: guard against out-of-range lines from directives.David Chase
//line bogo.go:9999999 will cause 'go tool objdump' to crash unless bogo.go has that many lines. Guard the array index and return innocuous values (nil, nil) from the file cache. Fixes #36683 Change-Id: I4a9f8444dc611654d270cc876e8848dfd2f84770 Reviewed-on: https://go-review.googlesource.com/c/go/+/223081 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-10-10all: remove nacl (part 3, more amd64p32)Brad Fitzpatrick
Part 1: CL 199499 (GOOS nacl) Part 2: CL 200077 (amd64p32 files, toolchain) Part 3: stuff that arguably should've been part of Part 2, but I forgot one of my grep patterns when splitting the original CL up into two parts. This one might also have interesting stuff to resurrect for any future x32 ABI support. Updates #30439 Change-Id: I2b4143374a253a003666f3c69e776b7e456bdb9c Reviewed-on: https://go-review.googlesource.com/c/go/+/200318 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-12-06cmd/internal/objfile: provide consistent output in objdump on ppc64xLynn Boger
This makes a change to disasm.go so it provides consistent output with the recent updates to arch/ppc64. Change-Id: I812e5da2423fd1a84406032fd91ddf9cc86b7c69 Reviewed-on: https://go-review.googlesource.com/c/152761 Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-18cmd/internal/objfile: emit trailing tab outside of Disasm.DecodeJosh Bleecher Snyder
Disasm.Decode currently always appends a tab to the formatted instruction, although not to any relocations after it. Decode has two clients: objdump and pprof. pprof emits plain text, so it would be better not to have a trailing tab. objdump wants the trailing tab for text/tabwriter, but it is easy to add that to the Fprintf call. Shifting the responsibility for the trailing tab to the caller simplifies the code, increases correctness, and slightly improves performance by reducing and coalescing string concatenations. Change-Id: I0c85518ee185949e385de819e2e703bce757eba9 Reviewed-on: https://go-review.googlesource.com/106983 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-13cmd/internal/objfile: reuse tabwriter across symbols when disassemblingJosh Bleecher Snyder
Since the tabwriter is flushed at every symbol, it can be re-used with no impact on the output. This cuts allocated space when objdump-ing the compiler by almost 40%, and enables further upcoming improvements. It also speeds up objdump. name old time/op new time/op delta ObjdumpCompile 9.22s ± 3% 8.77s ± 3% -4.79% (p=0.000 n=10+9) Change-Id: Ief114d6c2680a4e762b5f439d3ca8dc7a89b9b27 Reviewed-on: https://go-review.googlesource.com/106978 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-12cmd/internal/objfile: clean up some commentsJosh Bleecher Snyder
Change-Id: Iba6feea74d65a961f30c12fb6c677ccd3b2c3591 Reviewed-on: https://go-review.googlesource.com/106695 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-06cmd: some semi-automated cleanupsDaniel Martí
* Remove some redundant returns * Replace HasPrefix with TrimPrefix * Remove some obviously dead code Passes toolstash -cmp on std cmd. Change-Id: Ifb0d70a45cbb8a8553758a8c4878598b7fe932bc Reviewed-on: https://go-review.googlesource.com/105017 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-29cmd/internal/objfile: make lookupFunc an alias typeCherry Zhang
In the x/arch repo, CL 45098 introduced SymLookup type, replacing the unnamed function type for lookup functions. This affects the signature of x86asm.GoSyntax. In particular, it cannot convert one named type, namely lookupFunc, to the other without an explicit cast. Make lookupFunc unnamed to fix. Change-Id: I973300d29ef1dbfdbd7fc2429e89c5849e6a7329 Reviewed-on: https://go-review.googlesource.com/80842 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-10cmd/objdump: pass the correct execution mode to x86asm.Decode in disasm_x86 ↵Hiroshi Ioka
on 386 Fixes #22093 Fixes #19988 Change-Id: Ibd8ec89e091fd527f363999e484676931d7aa6e2 Reviewed-on: https://go-review.googlesource.com/67450 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-02cmd/internal/objfile: allow disassemble amd64p32 binariesCherry Zhang
Change-Id: Ifa7701e97c0ec7d113e952b2b366edf422d6df2f Reviewed-on: https://go-review.googlesource.com/69351 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-09-21cmd/nm: handle cgo archiveHiroshi Ioka
This CL also make cmd/nm accept PE object file. Fixes #21706 Change-Id: I4a528b7d53da1082e61523ebeba02c4c514a43a7 Reviewed-on: https://go-review.googlesource.com/64890 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-28cmd/internal/objfile: add arm64 disassembler supportWei Xiao
Fixes #19157 Change-Id: Ieea286e8dc03929c3645f3113c33df569f8e26f3 Reviewed-on: https://go-review.googlesource.com/58930 Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-04-05cmd/objdump: print Go code alongside assemblyLorenzo Masini
Added -S flag to print go source file line above corresponding disassembly: $ go tool objdump -S -s main.main fmthello TEXT main.main(SB) /home/rugginoso/Documents/src/go/src/cmd/objdump/testdata/fmthello.go func main() { 0x47d450 64488b0c25f8ffffff FS MOVQ FS:0xfffffff8, CX 0x47d459 483b6110 CMPQ 0x10(CX), SP 0x47d45d 7631 JBE 0x47d490 0x47d45f 4883ec18 SUBQ $0x18, SP 0x47d463 48896c2410 MOVQ BP, 0x10(SP) 0x47d468 488d6c2410 LEAQ 0x10(SP), BP Println("hello, world") 0x47d46d 488d0563b00200 LEAQ 0x2b063(IP), AX 0x47d474 48890424 MOVQ AX, 0(SP) 0x47d478 48c74424080c000000 MOVQ $0xc, 0x8(SP) 0x47d481 e81a000000 CALL main.Println(SB) } 0x47d486 488b6c2410 MOVQ 0x10(SP), BP 0x47d48b 4883c418 ADDQ $0x18, SP 0x47d48f c3 RET func main() { 0x47d490 e8ebf1fcff CALL runtime.morestack_noctxt(SB) 0x47d495 ebb9 JMP main.main(SB) Execution time: $ time go tool objdump testdata/fmthello > /dev/null real 0m0.430s user 0m0.440s sys 0m0.000s $ time go tool objdump -S testdata/fmthello > /dev/null real 0m0.471s user 0m0.476s sys 0m0.012s Fixes #18245 Change-Id: I9b2f8338f9ee443c1352efd270d3ba85e3dd9b78 Reviewed-on: https://go-review.googlesource.com/37953 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2016-10-24cmd/internal/objfile: remove debugging printRuss Cox
Crept into CL 9682, committed last week. Change-Id: I5b8e9119dbfeb0bc3005623ab74dbd29311d17ae Reviewed-on: https://go-review.googlesource.com/31814 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-13cmd/internal/objfile: add ppc64/ppc64le disassembler supportShenghou Ma
Change-Id: I7d213b4f8e4cda73ea7687fb97dbd22e58163948 Reviewed-on: https://go-review.googlesource.com/9682 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2016-08-24cmd/objdump: implement objdump of .o filesKeith Randall
Update goobj reader so it can provide all the information necessary to disassemble .o (and .a) files. Grab architecture of .o files from header. .o files have relocations in them. This CL also contains a simple mechanism to disassemble relocations and add relocation info as an extra column in the output. Fixes #13862 Change-Id: I608fd253ff1522ea47f18be650b38d528dae9054 Reviewed-on: https://go-review.googlesource.com/24818 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-14cmd/vendor: move cmd/internal/unvendor packages to cmd/vendorKonstantin Shaposhnikov
Updates #14047 Change-Id: I4b150533393bfb90e840497095ac32bcca4f04c2 Reviewed-on: https://go-review.googlesource.com/23114 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-21cmd/internal/objfile: add s390x supportMichael Munday
Change-Id: I39aa6569c9a6f327f7aaa01f8b4ace814fd5b766 Reviewed-on: https://go-review.googlesource.com/20943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-09build: mv cmd/vendor cmd/internal/unvendorRuss Cox
And update two imports in cmd/internal/objfile/disasm.go. This makes GO15VENDOREXPERIMENT=0 ./make.bash work. For Go 1.7 we will move it back. Fixes #14236. Change-Id: I429c9af4baff8496f83d113b1b03b90e309f4f48 Reviewed-on: https://go-review.googlesource.com/19384 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-28cmd/internal/objfile: use golang.org/x/arch instead of rsc.ioRuss Cox
Change-Id: I5348774ff01a5f0f706a1dba4aa9500661841f47 Reviewed-on: https://go-review.googlesource.com/14020 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-05all: power64 is now ppc64Russ Cox
Fixes #8654. LGTM=austin R=austin CC=golang-codereviews https://golang.org/cl/180600043
2014-11-09cmd/internal/objfile: minor editsRuss Cox
Follow-up in response to comments on TBR'ed CL 171260043. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/172080043
2014-11-06cmd/internal/objfile: add DisasmRuss Cox
This was missing from CL 167320043. Happy to apply comments in a followup. TBR to fix build. TBR=r CC=golang-codereviews https://golang.org/cl/171260043