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: -trimpath build flag has no effect in gccgo #32162

Closed
cespare opened this issue May 21, 2019 · 5 comments

Comments

@cespare
Copy link
Contributor

commented May 21, 2019

Go 1.13 is adding a new -trimpath flag (see 7469564).

The documentation says

        -trimpath
                remove all file system paths from the resulting executable.
                Instead of absolute file system paths, the recorded file names
                will begin with either "go" (for the standard library),
                or a module path@version (when using modules),
                or a plain import path (when using GOPATH).

This works with gc, but the flag has no effect in gccgo. Demo:

$ mkdir /tmp/xyz123
$ cd /tmp/xyz123/
$ cat > hello.go
package main
func main() { println("hello") }
$ out=gc.out && gotip clean -cache && gotip build -o $out hello.go && strings $out | grep xyz123 | head -3
/tmp/xyz123/hello.go
$ out=gc.trimpath.out && gotip clean -cache && gotip build -trimpath -o $out hello.go && strings $out | grep xyz123 | head -3
$ out=gccgo.out && gotip clean -cache && gotip build -compiler gccgo -o $out hello.go && strings $out | grep xyz123 | head -3
/tmp/xyz123
/tmp/xyz123/hello.go
GNU Go 8.3.0 -m64 -mtune=generic -march=x86-64 -g -fgo-relative-import-path=_/tmp/xyz123
$ out=gccgo.trimpath.out && gotip clean -cache && gotip build -trimpath -compiler gccgo -o $out hello.go && strings $out | grep xyz123 | head -3
/tmp/xyz123
/tmp/xyz123/hello.go
GNU Go 8.3.0 -m64 -mtune=generic -march=x86-64 -g -fgo-relative-import-path=_/tmp/xyz123
$ diff gccgo.out gccgo.trimpath.out

(This came up in CL 176112.)

Here are some things we could do to improve the situation:

  • Hook up -trimpath to the appropriate gcc flags so that the option works as advertised (if that's possible).
  • Reject -trimpath if it's being used with a compiler where that isn't implemented.
  • Document that -trimpath only works with gc.

Marking for 1.13 since this is a new feature and we should at least document the interaction.

@cespare cespare added this to the Go1.13 milestone May 21, 2019
@cespare

This comment has been minimized.

Copy link
Contributor Author

commented May 21, 2019

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2019

The GCC/LLVM option to use to implement -trimpath is -ffile-prefix-map, which implies -fdebug-prefix-map and -fmacro-prefix-map. See https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html. This was added to LLVM in mid-2018 (https://reviews.llvm.org/D49466).

@bcmills bcmills added the NeedsFix label Jun 4, 2019
@gopherbot gopherbot removed the NeedsDecision label Jun 4, 2019
@bcmills bcmills self-assigned this Jun 28, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 16, 2019
@cespare

This comment has been minimized.

Copy link
Contributor Author

commented Jul 31, 2019

@bcmills should we document that -trimpath only works with gc for 1.13?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2019

https://golang.org/cl/187824, which is out for review for 1.13, will affect this.

@gopherbot

This comment has been minimized.

Copy link

commented Sep 17, 2019

Change https://golang.org/cl/196023 mentions this issue: cmd/go: support -trimpath with gccgo

@gopherbot gopherbot closed this in eb6ce1c Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.