Is it possible to make the go executable even smaller?

2,984 views
Skip to first unread message

ChrisLu

unread,
Aug 21, 2012, 1:20:57 PM8/21/12
to golan...@googlegroups.com
Maybe the idea is too wild. Is it possible to make the go executable even smaller?

The go executable is pretty small. Usually 3M or so. But a simple gzip can compress it to about 1M.

So I think maybe a simple compression can be added just before launching the actual executable.

minux

unread,
Aug 21, 2012, 1:27:37 PM8/21/12
to ChrisLu, golan...@googlegroups.com
You can always upx(1) the binary.

Miki Tebeka

unread,
Aug 21, 2012, 1:42:22 PM8/21/12
to golan...@googlegroups.com, ChrisLu

Archos

unread,
Aug 21, 2012, 2:40:43 PM8/21/12
to golan...@googlegroups.com
Build a program to compress/decompress an executable, and execute the binary at decompress it.

Carlos Castillo

unread,
Aug 21, 2012, 3:45:15 PM8/21/12
to golan...@googlegroups.com
Many gzip implementations have a gzexe binary that will do this.

Rob Pike

unread,
Aug 21, 2012, 4:56:17 PM8/21/12
to golan...@googlegroups.com
Write less code.

-rob

minux

unread,
Aug 22, 2012, 2:51:29 AM8/22/12
to Miki Tebeka, golan...@googlegroups.com, ChrisLu
for the record, latest version of upx (3.08) can compress linux/386 binaries produced by go.

On Wednesday, August 22, 2012, Miki Tebeka wrote: 
upx does not work on Go executables, see http://sourceforge.net/tracker/?func=detail&atid=102331&aid=3408066&group_id=2331.
upx can't not handle linux/arm and linux/amd64 binaries produced by go,
and I will look into these problem.

update:
the linux/arm problem should be fixed by CL 6475044,
i'm investigating the linux/amd64 problem now.

the compress rate is pretty good, about 30%, and the execution time penalty is unnoticeable
even on underpowered ARM machines.

tiny_dust

unread,
Aug 22, 2012, 4:20:54 AM8/22/12
to golang-nuts
3M is a extremely small size. :)

I am maintaining one java project, which is in size of 89M , bundled
with many many jars.

Miki Tebeka

unread,
Aug 22, 2012, 12:26:33 PM8/22/12
to golan...@googlegroups.com, Miki Tebeka, ChrisLu
Great news, thanks.

bryanturley

unread,
Aug 22, 2012, 1:23:10 PM8/22/12
to golan...@googlegroups.com
No one mentioned strip?
If you don't care about debugging this could make it smaller I believe.
I haven't used it myself though (with go binaries) so good luck.

Aram Hăvărneanu

unread,
Aug 22, 2012, 1:34:52 PM8/22/12
to bryanturley, golan...@googlegroups.com
If you don't care about debugging your code it doesn't mean an
administrator that debugs his stack doesn't want to debug your failing
code. Stripping symbols is awful.

--
Aram Hăvărneanu

bryanturley

unread,
Aug 22, 2012, 2:10:17 PM8/22/12
to golan...@googlegroups.com, bryanturley
Heh, well i did say "I haven't used it myself though (with go binaries) so good luck."
And I believe with most of the big linux distros you have to install the debug symbols separately.

Kyle Lemons

unread,
Aug 23, 2012, 1:18:44 PM8/23/12
to pw, golan...@googlegroups.com
On Thu, Aug 23, 2012 at 6:49 AM, pw <wang.p...@gmail.com> wrote:
Stripping executable in an embedded production environment is common practice.  Having the user debug production binary, however, is uncommon.  Besides, the symbols can be side-loaded into gdb when the binary image doesn't a set built-in.
I don't think strip or gdb understand Go binaries well enough for either of those things to behave the same way they do with C.
 
When somebody worries about minimizing space, then they're starting down the production binary path.
Not always ;-).  There is always the chance it's someone prematurely optimizing for space.

elij

unread,
Aug 23, 2012, 2:59:02 PM8/23/12
to Kyle Lemons, pw, golan...@googlegroups.com


On Thursday, August 23, 2012 at 10:18 AM, Kyle Lemons wrote:

> On Thu, Aug 23, 2012 at 6:49 AM, pw <wang.p...@gmail.com (mailto:wang.p...@gmail.com)> wrote:
> > Stripping executable in an embedded production environment is common practice. Having the user debug production binary, however, is uncommon. Besides, the symbols can be side-loaded into gdb when the binary image doesn't a set built-in.
>
> I don't think strip or gdb understand Go binaries well enough for either of those things to behave the same way they do with C.


go install -ldflags '-s'

Admittedly, I haven't used it much.

Mike Rosset

unread,
Aug 23, 2012, 6:18:13 PM8/23/12
to Miki Tebeka, golan...@googlegroups.com, ChrisLu
UPX does works last I check, but only on 32bit elf binaries.

Guillermo Estrada

unread,
May 28, 2013, 11:00:10 PM5/28/13
to golan...@googlegroups.com
Posted this on another thread also, just for search result sake.
Issue still open right AFAIK. At least for Windows and Mac (32 and 64 bit) I found this one:
Works wonders with go executables on windows x64 (19% final size on a server) Hope it helps.
I have not tested this on Mac.

On Tuesday, August 21, 2012 12:20:57 PM UTC-5, ChrisLu wrote:
Reply all
Reply to author
Forward
0 new messages