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/compile: full go file paths produced in .a and bin files even with -trimpath #21720

Closed
wak-google opened this issue Aug 31, 2017 · 10 comments

Comments

Projects
None yet
6 participants
@wak-google
Copy link

commented Aug 31, 2017

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

go1.9

Does this issue reproduce with the latest release?

Yes

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

linux/amd64

What did you do?

set GOPATH=/tmp/my-go-build/go
set CGO_CFLAGS="-fdebug-prefix-map=/tmp/my-go-build=/no-such-path"
go get -d leb.io/hashland
go build "-asmflags" "-trimpath=/tmp/my-go-build" "-gcflags" "-trimpath=/tmp/my-go-build" -v "leb.io/hashland/keccak"

What did you expect to see?

No references to my-go-build. This is the case on go1.8.3 and older

What did you see instead?

This produces a /tmp/my-go-build/go/pkg/linux_amd64/leb.io/hashland/keccak.a that contains a full path reference to /tmp/my-go-build even when the -trimpath flag was specified.

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Aug 31, 2017

@mholt was looking at the same thing.

@mdempsky mdempsky changed the title Full go file paths produced in .a and bin files even with -trimpath cmd/compile: full go file paths produced in .a and bin files even with -trimpath Aug 31, 2017

@mdempsky mdempsky self-assigned this Aug 31, 2017

@mdempsky

This comment has been minimized.

Copy link
Member

commented Aug 31, 2017

I think using -trimpath in this manner is unsupported anyway. Currently, we only support setting -trimpath once, and cmd/go already sets it when invoking the compiler and assembler.

Moreover, I believe it's supported for the purpose of trimming temporary directories that are generated during the build, so that repeat builds that use different temporary directories will still produce the same output.

Your intended use case appears to be to hide your $GOPATH directory. I don't think that's a supported use case currently.

/cc @rsc for input on whether this is something we want to support.

@mdempsky mdempsky removed their assignment Aug 31, 2017

@rsc

This comment has been minimized.

Copy link
Contributor

commented Aug 31, 2017

Why did Go 1.8 vs Go 1.9 change? I agree that it's not something I intended to support but I'm curious why it stopped "working".

@mdempsky

This comment has been minimized.

Copy link
Member

commented Aug 31, 2017

I see the same behavior with Go 1.8.3:

mdempsky@bento-glaptop3:/tmp/my-go-build$ echo $GOPATH
/tmp/my-go-build/go
mdempsky@bento-glaptop3:/tmp/my-go-build$ go version
go version go1.8.3 linux/amd64
mdempsky@bento-glaptop3:/tmp/my-go-build$ go build -a -o keccak.a "-asmflags" "-trimpath=/tmp/my-go-build" "-gcflags" "-trimpath=/tmp/my-go-build -v" leb.io/hashland/keccak
mdempsky@bento-glaptop3:/tmp/my-go-build$ strings keccak.a | grep /tmp/my-go-build
/tmp/my-go-build/go/src/leb.io/hashland/keccak
/tmp/my-go-build/go/src/leb.io/hashland/keccak
/tmp/my-go-build/go/src/leb.io/hashland/keccak
/tmp/my-go-build/go/src/leb.io/hashland/keccak
/tmp/my-go-build/go/src/leb.io/hashland/keccak
/tmp/my-go-build/go/src/leb.io/hashland/keccak
/tmp/my-go-build/go/src/leb.io/hashland/keccak/KeccakF-1600-opt64.c
/tmp/my-go-build/go/src/leb.io/hashland/keccak/KeccakNISTInterface.c
/tmp/my-go-build/go/src/leb.io/hashland/keccak/KeccakSponge.c
@mdempsky

This comment has been minimized.

Copy link
Member

commented Aug 31, 2017

@wak-google I just tested with Go 1.6, Go 1.7, and Go 1.8.3, and they all appear to behave the same as Go 1.9 with regards to "/tmp/my-go-build" appearing in the compiled .a file. Do you mind double checking this?

@wak-google

This comment has been minimized.

Copy link
Author

commented Sep 1, 2017

@mdempsky My understanding is that all of the strings in the go1.8 case are coming from the c compiler. I forgot to mention in the initial report that I have CGO_CFLAGS="-fdebug-prefix-map=/tmp/my-go-build=/no-such-path". If you set that environment variable or pass the CFLAGS in some other way all references to my-go-build go away in 1.8. In the 1.9 case you still get

my-go-build
gofile../tmp/my-go-build/go/src/leb.io/hashland/keccak/keccak.go
@mdempsky

This comment has been minimized.

Copy link
Member

commented Sep 1, 2017

@wak-google Thanks, I can repro your issue now. I'll figure out what changed.

@mdempsky mdempsky self-assigned this Sep 1, 2017

codyopel referenced this issue in triton/triton Sep 3, 2017

@gopherbot

This comment has been minimized.

Copy link

commented Sep 15, 2017

Change https://golang.org/cl/63693 mentions this issue: cmd/compile: replace GOROOT in //line directives

@gopherbot gopherbot closed this in 27e80f7 Sep 15, 2017

@Ei5enheim

This comment has been minimized.

Copy link

commented Sep 28, 2017

@mdempsky @rsc
I'm facing the same issue.

What version of Go are you using (go version)?
go version go1.8 linux/amd64

Does this issue reproduce with the latest release?
I don't know

What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN="/home/dev/Documents/iox/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dev/Documents/iox/proj/"
GORACE=""
GOROOT="/home/dev/Documents/iox/go"
GOTOOLDIR="/home/dev/Documents/iox/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build694052321=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?
go build -x -v -gcflags "-trimpath=$GOPATH" -asmflags "-trimpath=$GOPATH"

What did you expect to see?
No $GOPATH in my stack trace, but I do see that.
panic: assignment to entry in nil map

goroutine 1 [running]:
main.main()
/home/dev/Documents/iox/proj/src/ioxclient/ioxclient.go:2193 +0x59

I also noticed that go is creating a temp directory for build process and the command used to compile the binary starts with

/home/dev/Documents/iox/go/pkg/tool/linux_amd64/compile -o $WORK/ioxclient.a -trimpath $WORK -trimpath=/home/dev/Documents/iox/proj/

Is it failing because trimpath can only be used once to remove $WORK?

@gopherbot

This comment has been minimized.

Copy link

commented Oct 15, 2017

Change https://golang.org/cl/70975 mentions this issue: [release-branch.go1.9] cmd/compile: replace GOROOT in //line directives

gopherbot pushed a commit that referenced this issue Oct 25, 2017

[release-branch.go1.9] cmd/compile: replace GOROOT in //line directives
The compiler replaces any path of the form /path/to/goroot/src/net/port.go
with GOROOT/src/net/port.go so that the same object file is
produced if the GOROOT is moved. It was skipping this transformation
for any absolute path into the GOROOT that came from //line directives,
such as those generated by cmd/cgo.

Fixes #21373
Fixes #21720
Fixes #21825

Change-Id: I2784c701b4391cfb92e23efbcb091a84957d61dd
Reviewed-on: https://go-review.googlesource.com/63693
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-on: https://go-review.googlesource.com/70975
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

@golang golang locked and limited conversation to collaborators Oct 15, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.