supporting the stripping of Go binaries

1,708 views
Skip to first unread message

Michael Hudson-Doyle

unread,
Mar 13, 2016, 7:48:36 PM3/13/16
to golang-dev
Hi,

Currently it is the case that running 'strip' on Go binaries is not
supported, so there are bits and pieces all over Debian and Ubuntu
that disable the default stripping. But my understanding is that
currently stripping binaries does not cause any actual problems --
it's not not tested in any way by the Go project. What would it take
to "support" stripping? Add some kind of testing to ./all.bash that
stripping the binaries doesn't break things? Some kind of commitment
to look at bug reports about stripping and do something to fix them? I
can put my hand up for this last bit...

Cheers,
mwh

(AIUI gccgo is different and stripping gccgo binaries results in them
not working at all and I'm not proposing to change that)

Dave Cheney

unread,
Mar 13, 2016, 8:00:25 PM3/13/16
to Michael Hudson-Doyle, golang-dev

Stripping arm binaries has always generated a broken binary.


--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Keith Randall

unread,
Mar 13, 2016, 8:11:26 PM3/13/16
to Dave Cheney, Michael Hudson-Doyle, golang-dev
I feel like stripping the binaries should work, and if it doesn't that's a bug.  Is Go really reading the symbol table from its own binary?
Stripping works fine on a simple amd64 binary.

Michael Hudson-Doyle

unread,
Mar 13, 2016, 8:12:14 PM3/13/16
to Dave Cheney, golang-dev
Still? I thought that got fixed in 2010:
https://codereview.appspot.com/994044 and a stripped hello world works
for me (in a armhf chroot on an arm64 system but I doubt that
matters).

Cheers,
mwh

Dave Cheney

unread,
Mar 13, 2016, 8:15:30 PM3/13/16
to Michael Hudson-Doyle, golang-dev
I honestly don't know, I've not tried it for a few years -- which I
guess is the point of your issue. The first step to supporting
stripping binaries is to add a test to ./all.bash to know what's
missing today.

Matthew Dempsky

unread,
Mar 13, 2016, 8:16:48 PM3/13/16
to Michael Hudson-Doyle, golang-dev
I agree with Keith.  From my understanding of ELF and the gc toolchain, there shouldn't be any fundamental reason for stripped binaries to not work.  The last time I checked (in response to the Reddit AMA a few weeks ago), I couldn't find any open issues about it not working either.

(gccgo on the other hand does depend on the DWARF debugging info.)

Russ Cox

unread,
Mar 13, 2016, 9:25:26 PM3/13/16
to Michael Hudson-Doyle, golang-dev
Works fine for me.

$ cp $(which go) /tmp/zz
$ ls -l /tmp/zz
-rwxr-x--- 1 rsc eng 12598320 Mar 13 21:24 /tmp/zz
$ strip /tmp/zz
$ ls -l /tmp/zz
-rwxr-x--- 1 rsc eng 8637088 Mar 13 21:24 /tmp/zz
$ /tmp/zz
Go is a tool for managing Go source code.

Usage:

go command [arguments]

The commands are:

build       compile packages and dependencies
clean       remove object files
doc         show documentation for package or symbol
env         print Go environment information
fix         run go tool fix on packages
fmt         run gofmt on package sources
generate    generate Go files by processing source
get         download and install packages and dependencies
install     compile and install packages and dependencies
list        list packages
run         compile and run Go program
test        test packages
tool        run specified go tool
version     print Go version
vet         run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

c           calling between Go and C
buildmode   description of build modes
filetype    file types
gopath      GOPATH environment variable
environment environment variables
importpath  import path syntax
packages    description of package lists
testflag    description of testing flags
testfunc    description of testing functions

Use "go help [topic]" for more information about that topic.

$

Russ Cox

unread,
Mar 13, 2016, 9:28:18 PM3/13/16
to Michael Hudson-Doyle, golang-dev
To answer the original question, I don't think we have to do anything to "support" this, any more than we "support" readelf or objdump or anything else. We don't intentionally do anything that would make stripping a binary not OK, and strip has worked for the past five years or so. What didn't work was using -s with the linker (that is very different from invoking strip), and even that has worked for the past five years or so.

I don't believe a test in all.bash is needed.

Russ

Michael Hudson-Doyle

unread,
Mar 13, 2016, 9:54:36 PM3/13/16
to Russ Cox, golang-dev
Well, I did this anyway:
https://go-review.googlesource.com/#/c/20584/3. Something very bad
happens on darwin but I don't know what the 'strip' program does there
I guess. Otherwise, all the things that one would expect to work seem
to work. So I think I'll get to work on dispelling this superstition
from our packaging...

Cheers,
mwh

Shahin

unread,
Mar 14, 2016, 10:27:14 AM3/14/16
to golang-dev
I strip my arm binaries (http://www.nanodlp.com) since 1.4 without any problem.
Reply all
Reply to author
Forward
0 new messages