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

Our binaries are not stripped #76

Open
Metallion opened this issue Jan 13, 2017 · 3 comments
Open

Our binaries are not stripped #76

Metallion opened this issue Jan 13, 2017 · 3 comments

Comments

@Metallion
Copy link
Contributor

Metallion commented Jan 13, 2017

Problem

Our binaries aren't stripped. This means unnecessary symbols and debug information is still in there. We should strip them to save space.

[kemumaki@executor bin]$ file openvdc
openvdc: ELF 64-bit LSB executable .... not stripped
[kemumaki@executor bin]$ file openvdc-executor
openvdc-executor: ELF 64-bit LSB executable .... not stripped

Solution

Run the strip command on them before packaging. It's just a small difference but we should still do it.

Read the blog @unakatsuo posted below. :)

@unakatsuo
Copy link
Contributor

unakatsuo commented Jan 13, 2017

https://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/

Go binaries are their own thing and they don't play well with the standard strip utility, so don't use that.

@Metallion
Copy link
Contributor Author

Interesting.

Instead, we can use the -s and -w linker flags like this:

$ GOOS=linux go build cmd/go
$ ls -l go
-rwxr-xr-x  1 filippo  staff  12493536 Apr 16 16:58 go
$ GOOS=linux go build -ldflags="-s -w" cmd/go
$ ls -l go
-rwxr-xr-x  1 filippo  staff  8941952 Apr 16 17:08 go

@unakatsuo
Copy link
Contributor

https://blog.golang.org/go1.7-binary-size

Typical programs, ranging from tiny toys to large production programs, are about 30% smaller when built with Go 1.7.

The canonical hello world program goes from 2.3MB to 1.6MB:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants