What are the consequences of go install -ldflags "-s"

1,244 views
Skip to first unread message

Nick Craig-Wood

unread,
Nov 4, 2016, 10:40:20 AM11/4/16
to golang-nuts
I know I can build go binaries passing the `-s` flag to the linker to
strip them and make them smaller. In my tests (with rclone) it makes it
60% of the size so a significant saving. I'd like to enable this for
binaries I distribute to end users.

go install -ldflags "-s"

However what are the consequences? The link docs say what it does but
not what the consequences are.

https://golang.org/cmd/link/

-s
Omit the symbol table and debug information.

I can see that I still get source code lines in my backtraces which is
very important to me but what am I losing? Why wouldn't I want to do this?

Any insight much appreciated.

--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick

Ian Lance Taylor

unread,
Nov 4, 2016, 10:55:52 AM11/4/16
to Nick Craig-Wood, golang-nuts
On Fri, Nov 4, 2016 at 7:39 AM, Nick Craig-Wood <ni...@craig-wood.com> wrote:
> I know I can build go binaries passing the `-s` flag to the linker to
> strip them and make them smaller. In my tests (with rclone) it makes it
> 60% of the size so a significant saving. I'd like to enable this for
> binaries I distribute to end users.
>
> go install -ldflags "-s"
>
> However what are the consequences? The link docs say what it does but
> not what the consequences are.
>
> https://golang.org/cmd/link/
>
> -s
> Omit the symbol table and debug information.
>
> I can see that I still get source code lines in my backtraces which is
> very important to me but what am I losing? Why wouldn't I want to do this?

You won't be able to run gdb or various other non-Go-specific tools.

Ian

Nick Craig-Wood

unread,
Nov 4, 2016, 11:13:59 AM11/4/16
to Ian Lance Taylor, golang-nuts
Thanks. If that is the only consequence than I'm good with that.
Anyone who wants to run gdb can compile their own binary.
Reply all
Reply to author
Forward
0 new messages