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/go: -n and -x do not print all commands when using shared or c-shared buildmode #22565

Closed
ghost opened this issue Nov 3, 2017 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ghost
Copy link

ghost commented Nov 3, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/brice/go"
GORACE=""
GOROOT="/usr/local/go-1.9.2"
GOTOOLDIR="/usr/local/go-1.9.2/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build204618450=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

Create a simple go file with a non-main package, for example:

package foo

func bar() {}

Build it with -buildmode=shared and -n or -x to see the build commands.

What did you expect to see?

All of the build commands used to build the shared library.

What did you see instead?

Only the link command:

$ go build -buildmode=shared -linkshared -n a.go
cd .
/usr/local/go-1.9.2/pkg/tool/linux_amd64/link -o $WORK/libcommand-line-arguments.so -L $WORK -installsuffix dynlink -buildmode=shared -linkshared -w -extld=gcc
$
$ go build -buildmode=shared -linkshared -x a.go
WORK=/tmp/go-build709785197
cd .
/usr/local/go-1.9.2/pkg/tool/linux_amd64/link -o $WORK/libcommand-line-arguments.so -L $WORK -installsuffix dynlink -buildmode=shared -linkshared -w -extld=gcc
$
@ianlancetaylor ianlancetaylor changed the title -n and -x do not print all commands when using shared or c-shared buildmode cmd/go: -n and -x do not print all commands when using shared or c-shared buildmode Nov 3, 2017
@ianlancetaylor
Copy link
Contributor

This is behaving as expected, though perhaps there is some way we can change the behavior. The go tool is printing all the commands that it is executing. The command you are looking for is actually being executed by the linker. You can see it (along with other output) by running go build -ldflags=-v .... Perhaps we could arrange for go build -x to pass an option to the linker that tells it to output the external link command. Or perhaps that would be more confusing, I'm not sure.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 3, 2017
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Nov 3, 2017
@ghost
Copy link
Author

ghost commented Nov 3, 2017

Actually, what I was expecting to see was the compile commands before the link command, not the linker commands.

@ianlancetaylor
Copy link
Contributor

Ah, sorry, I misunderstood.

I do see those commands myself. Are you sure the package wasn't already installed, and therefore did not need to be recompiled? Did you run go install -buildmode=shared at any point? What do you see in $GOPATH/pkg/linux_amd64_shared?

@ghost
Copy link
Author

ghost commented Nov 3, 2017

I don't have $GOPATH/pkg/linux_amd64_shared, but I do have a linux_amd64_dynlink directory. I just emptied it and got the same result.

@ianlancetaylor
Copy link
Contributor

I have no explanation. I can't recreate this at all. I don't know what is happening.

@ghost
Copy link
Author

ghost commented Nov 6, 2017

Ok sorry, I'm not sure what was happening before, but in a clean environment, I do see the compile command. Thanks Ian.

@ghost ghost closed this as completed Nov 6, 2017
@golang golang locked and limited conversation to collaborators Nov 6, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants