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/link: external linker generates larger binaries than 6l/8l #5497

Open
gopherbot opened this Issue May 17, 2013 · 8 comments

Comments

Projects
None yet
3 participants
@gopherbot

gopherbot commented May 17, 2013

by unclejacksons:

What steps will reproduce the problem?

Using 6l from Go 1.1:
go build -ldflags '-s -linkmode internal' -tags release
github.com/valyala/ybc/apps/go/memcached
wc -c memcached 
  1562016 memcached

Using Go 1.1 the patch which passes '-s' to ld:
go build -ldflags '-s' -tags release github.com/valyala/ybc/apps/go/memcached
wc -c memcached 
  2096920 memcached

Using Go 1.1 release:
wc -c memcached
  3194317 memcached

What is the expected output?
The resulting binary linked with the external linker should be smaller, its size should
be closer to that of the binary linked with 6l.
Since Go 1.1 defaults to using the external linker because it's more mature, it should
generate smaller binaries.


Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Ubuntu 13.04 amd64

Which version are you using?  (run 'go version')
go version go1.1 linux/amd64 from
https://go.googlecode.com/files/go1.1.linux-amd64.tar.gz


What can be done to make the resulting binaries smaller?
@robpike

This comment has been minimized.

Contributor

robpike commented May 19, 2013

Comment 1:

For a simple case, external does generate a smaller binary:
% cat x.go
package main
import "fmt"
func main() {
    fmt.Printf("hello world\n")
}
% go build -ldflags '-linkmode internal'  x.go
% ls -l x
-rwxr-xr-x  1 r  staff  1525872 May 19 07:38 x
% x
hello world
% go build -ldflags '-linkmode external'  x.go
% ls -l x
-rwxr-xr-x  1 r  staff  1167348 May 19 07:38 x
% x
hello world
% 
So it's not so clear cut. (The -s flag produces similar ratios and slightly smaller
binaries but the programs don't run; that's a different issue.)

Labels changed: added priority-later, removed priority-triage.

Owner changed to @ianlancetaylor.

Status changed to Accepted.

@rsc

This comment has been minimized.

Contributor

rsc commented Jul 30, 2013

Comment 2:

Labels changed: added go1.2maybe.

@rsc

This comment has been minimized.

Contributor

rsc commented Jul 30, 2013

Comment 3:

Labels changed: added feature.

@robpike

This comment has been minimized.

Contributor

robpike commented Aug 30, 2013

Comment 4:

Not for 1.2.

Labels changed: removed go1.2maybe.

@rsc

This comment has been minimized.

Contributor

rsc commented Nov 27, 2013

Comment 5:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Contributor

rsc commented Nov 27, 2013

Comment 6:

Labels changed: removed feature.

@rsc

This comment has been minimized.

Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Contributor

rsc commented Dec 4, 2013

Comment 8:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc changed the title from cmd/ld: external linker generates larger binaries than 6l/8l to cmd/link: external linker generates larger binaries than 6l/8l Jun 8, 2015

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