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

Can go tool compile run in module-aware mode? #32139

Closed
xujintao opened this issue May 19, 2019 · 3 comments
Closed

Can go tool compile run in module-aware mode? #32139

xujintao opened this issue May 19, 2019 · 3 comments

Comments

@xujintao
Copy link

go version: 1.12

What did you do?

go.mod

module github.com/user/foo

main.go

package main

import "github.com/user/foo/bar"
func main() {
	bar.Hello()
}

bar/bar.go

package bar

func Hello() {
	println(1)
}
# go tool compile -S -l main.go &> main.s

What did you expect to see?

The golang assembly of main.go

What did you see instead?

main.go:3:8: can't find import: "github.com/user/foo/bar"

@ALTree
Copy link
Member

ALTree commented May 19, 2019

The answer is no.

The compile tool is a rather low-level command. From its doc:

Compile, typically invoked as “go tool compile,” compiles a single Go
package comprising the files named on the command line. It then writes a
single object file named for the basename of the first source file with a .o
suffix.

It doesn't know how to find and link multiple packages. build does.

Closing here.

@ALTree ALTree closed this as completed May 19, 2019
@ALTree
Copy link
Member

ALTree commented May 19, 2019

As a side note, you can use the -S flag with go build, like this:

$ go build -gcflags=-S main.go

If what you need is to disassemble from go build.

@xujintao
Copy link
Author

Thanks, go build works.

@golang golang locked and limited conversation to collaborators May 18, 2020
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

3 participants