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: should be able to disassemble Go .o files #13862

Closed
randall77 opened this issue Jan 7, 2016 · 7 comments
Closed

cmd/objdump: should be able to disassemble Go .o files #13862

randall77 opened this issue Jan 7, 2016 · 7 comments
Milestone

Comments

@randall77
Copy link
Contributor

$go tool compile fib.go
$go tool objdump fib.o
objdump: disassemble fib.o: pcln not available in go object file

It would be nice if this worked. The pcln info is in there somewhere.
"go tool nm fib.o" works.

@randall77 randall77 added this to the Go1.7 milestone Jan 7, 2016
@randall77
Copy link
Contributor Author

@griesemer

@cmarcelo
Copy link
Contributor

Inspected the code a bit. The error comes from cmd/internal/objfile/goobj.go

// pcln does not make sense for Go object files, because each
// symbol has its own individual pcln table, so there is no global
// space of addresses to map.
func (f *goobjFile) pcln() (textStart uint64, symtab, pclntab []byte, err error) {
    return 0, nil, nil, fmt.Errorf("pcln not available in go object file")
}

// text does not make sense for Go object files, because
// each function has a separate section.
func (f *goobjFile) text() (textStart uint64, text []byte, err error) {
    return 0, nil, fmt.Errorf("text not available in go object file")
}

These are used (via rawFile interface) in Disasm(). The common disassemble code expects a single table and a single slice of text, and operate on that. But these are not directly available in goobj files.

What would be the direction to go here: change Disasm side to be able to consume data in a more flexible way, or collect and construct data in goobj.go to fulfill the existing interfaces (e.g. build a gosym.Table)? Or neither?

/cc @rsc (since he reworked a bit Disasm back then, might have opinion)

@minux minux changed the title go tool objdump should be able to disassemble .o files cmd/objdump: should be able to disassemble Go .o files Mar 27, 2016
@jacobsa
Copy link
Contributor

jacobsa commented Apr 11, 2016

I've landed on this issue because I'm trying to do the same thing (disassemble a .a file in this case). Is there a workaround that would let me do so in another way?

@ianlancetaylor
Copy link
Contributor

@jacobsa There is no direct workaround as far as I know. One approach is to use the compiler's -S option. Or, of course, link the program and use the system objdump tool.

@jacobsa
Copy link
Contributor

jacobsa commented Apr 11, 2016

Thanks. I was looking for pre-link output, so -S did it for me.

@randall77
Copy link
Contributor Author

See https://go-review.googlesource.com/c/22685/ for a quick, bad pass at this.

@rsc rsc modified the milestones: Go1.8, Go1.7 May 18, 2016
@gopherbot
Copy link

CL https://golang.org/cl/24818 mentions this issue.

@golang golang locked and limited conversation to collaborators Aug 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants