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: document -trimpath #8999

Closed
gopherbot opened this issue Oct 25, 2014 · 10 comments
Closed

cmd/compile: document -trimpath #8999

gopherbot opened this issue Oct 25, 2014 · 10 comments
Milestone

Comments

@gopherbot
Copy link

by chetan.hs:

Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What does 'go version' print?
go version go1.3.3 linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Build any go program with ldflags -s option. Ex: go build -ldflags="-s" foo
-o foo.out
2. Extract the strings from the resulting binary and check for the current username,
build path etc. Ex: strings foo.out | grep <current_username>

What happened?
  - The debug symbols are still present in the output binary.

What should have happened instead?
  - This information should have been stripped out from the output binary.

Please provide any additional information below.
  - This option used to work in go v1.1
@ianlancetaylor
Copy link
Contributor

Comment 1:

The -s option does work, in the sense that it removes the debug info read by gdb.
Stripping the file name information means that stack traces and functions like
runtime.Caller do not work, meaning that basic packages like log do not work.  Doing
that amounts to a way to silently break Go programs.  See issue #6245.
What is the actual problem you are trying to solve?  The pack program used to have an
option to remove prefixes from file names, but we may have lost that feature when we
added the -pack option to gc and rewrote the pack program in Go.  Would restoring that
feature fix your problem?

Labels changed: added repo-main, release-none.

@gopherbot
Copy link
Author

Comment 2 by czapkofan:

Quoting the original poster's comments from the original thread:
> I ship my binary to users and I use the -s option to strip out information like the
full path of my build environment, the home directory, unix username etc. I'm still
using go 1.1 specifically for this reason. I feel being able to strip this information
is important to anyone who is distributing their binaries to other people.
https://groups.google.com/d/msg/golang-nuts/d-t_CfWFxhQ/F83J-Oyde-AJ
>> A workaround is just to build in a VM with generic username and home directory.
> It's not just the username and home directory. The path for different packages are
also inserted which may leak some of the project names and internal package names.
https://groups.google.com/d/msg/golang-nuts/d-t_CfWFxhQ/esLu0TIndYMJ

@ianlancetaylor
Copy link
Contributor

Comment 3:

If the actual problem is defined as "leaking project names and internal package names"
then I'm not particularly sympathetic.  If it were harmless, sure, but it is not.
I'm certainly open to compromise solutions that do not break runtime.Caller, which is
why I mentioned the old pack option.

@gopherbot
Copy link
Author

Comment 4 by chetan.hs:

Thanks for updating this issue with my comments form the thread.
Yes, restoring the pack feature would solve my problem as long as it strips out $GOPATH
file prefixes. Leaking project/package names is not the biggest concern (although
preventing it is desirable).

@ianlancetaylor
Copy link
Contributor

Comment 5:

In Go 1.2 the P option to pack was documented as
    [P prefix]
    The new option 'P' causes pack to remove the given prefix
    from file names in the line number information in object files
    that are already stored in or added to the archive.

Labels changed: added release-go1.5, removed release-none.

@gopherbot
Copy link
Author

Comment 6 by czapkofan:

Sorry if that's not on topic, but just wanted to comment, that with regards to "leaking
project/package names", a "solution" could be probably an external "source code mangler"
(probably utilizing the AST tools).

@gopherbot
Copy link
Author

Comment 7 by chetan.hs:

How is this pack tool supposed to work? I was trying it in go v1.2.2 but couldn't figure
out how it works.
$ go version
go version go1.2.2 linux/amd64
$ go tool pack -P $GOPATH pkg/linux_amd64/foo.a
pack: bad option `-'
> with regards to "leaking project/package names", a "solution" could be probably an
external "source code mangler"
Thanks for the suggestion. I'll check if any such tools exist.

@ianlancetaylor
Copy link
Contributor

Comment 8:

The Go 1.2 pack program, unlike the Go 1.3 pack program, works like the Unix ar program.
 You need to write something like "go tool pack rP $GOPATH foo.a".

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed the repo-main label Apr 14, 2015
@rsc rsc changed the title cmd/pack: Restore P option cmd/link: provide a way to strip file name information Jun 29, 2015
@rsc rsc modified the milestones: Go1.6Early, Go1.5 Jun 29, 2015
@rsc
Copy link
Contributor

rsc commented Nov 4, 2015

There is a -trimpath option to cmd/compile already. You just need to use it (go build -gcflags '-trimpath prefix' your-targets). It's documented in the output of go tool compile -help but not go doc compile. I'll fix the latter. If you have assembly in your packages you also need to pass -trimpath to the assembler, with -asflags.

There is no option in the linker: it's too late by then.

@rsc rsc changed the title cmd/link: provide a way to strip file name information cmd/compile: document -trimpath Nov 4, 2015
@rsc rsc modified the milestones: Go1.6, Go1.6Early Nov 4, 2015
@gopherbot
Copy link
Author

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

@rsc rsc closed this as completed in f2eb3de Nov 16, 2015
@golang golang locked and limited conversation to collaborators Nov 16, 2016
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

4 participants