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

hack/build: Strip compiled binaries #1158

Merged
merged 1 commit into from
Jan 31, 2019

Conversation

wking
Copy link
Member

@wking wking commented Jan 30, 2019

I'm not sure how portable this is, but for the GNU linker this is:

  -s
  --strip-all
     Omit all symbol information from the output file.

With this change, our compiled Linux binary (without libvirt) drops from ~240 MB to ~130 MB. Alex was concerned about panic support, but with:

$ git diff -U1
diff --git a/cmd/openshift-install/main.go b/cmd/openshift-install/main.go
index 37f7f96..fbd9889 100644
--- a/cmd/openshift-install/main.go
+++ b/cmd/openshift-install/main.go
@@ -69,2 +69,4 @@ func newRootCmd() *cobra.Command {
 func runRootCmd(cmd *cobra.Command, args []string) {
+       panic("testing, testing")
+
        logrus.SetOutput(ioutil.Discard)

panics still produce useful tracebacks:

$ openshift-install create install-config
panic: testing, testing

goroutine 1 [running]:
main.runRootCmd(0x8575360, 0x85d4390, 0x0, 0x0)
  /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:70 +0x39
github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).execute(0x8575360, 0x85d4390, 0x0, 0x0, 0x8575360, 0x85d4390)
  /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:746 +0x237
github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42044f180, 0x0, 0xc4209cc500, 0xc42044f2d0)
  /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:852 +0x30a
github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42044f180, 0xc420983ec0, 0x1)
  /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:800 +0x2b
main.installerMain()
  /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:50 +0x132
main.main()
  /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:34 +0x39

which looks fine.

Suggested-by: @pamoedom

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 30, 2019
@wking wking force-pushed the strip-binaries branch 2 times, most recently from 4490fb7 to 0ee413d Compare January 31, 2019 00:00
Docs for these settings in [1].

With this change, our compiled Linux binary (without libvirt) drops
from ~240 MB to ~130 MB.  Alex was concerned about panic support, but
with:

  $ git diff -U1
  diff --git a/cmd/openshift-install/main.go b/cmd/openshift-install/main.go
  index 37f7f96..fbd9889 100644
  --- a/cmd/openshift-install/main.go
  +++ b/cmd/openshift-install/main.go
  @@ -69,2 +69,4 @@ func newRootCmd() *cobra.Command {
   func runRootCmd(cmd *cobra.Command, args []string) {
  +       panic("testing, testing")
  +
          logrus.SetOutput(ioutil.Discard)

panics still produce useful tracebacks:

  $ openshift-install create install-config
  panic: testing, testing

  goroutine 1 [running]:
  main.runRootCmd(0x8575360, 0x85d4390, 0x0, 0x0)
    /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:70 +0x39
  github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).execute(0x8575360, 0x85d4390, 0x0, 0x0, 0x8575360, 0x85d4390)
    /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:746 +0x237
  github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42044f180, 0x0, 0xc4209cc500, 0xc42044f2d0)
    /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:852 +0x30a
  github.com/openshift/installer/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42044f180, 0xc420983ec0, 0x1)
    /.../go/src/github.com/openshift/installer/vendor/github.com/spf13/cobra/command.go:800 +0x2b
  main.installerMain()
    /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:50 +0x132
  main.main()
    /.../go/src/github.com/openshift/installer/cmd/openshift-install/main.go:34 +0x39

which looks fine.

I've left dev builds unstripped, because [2]:

  Generally speaking we do not recommend stripping debug info (it's
  useful, after all)...

There's also some stripping discussion in [3].

[1]: https://golang.org/cmd/link/
[2]: golang/go#6853 (comment)
[3]: golang/go#19226

Suggested-by: Pedro Jose Amoedo Martinez
@wking
Copy link
Member Author

wking commented Jan 31, 2019

Update, this is probably using Go's built-in linker, so I've updated my commit message and started setting -w too (with or without -w gives 130 MB Linux binaries either way). I've also adjusted to only strip release builds (MODE=dev hack/build.sh remains unstripped).

@crawford
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 31, 2019
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: crawford, wking

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit c69f25c into openshift:master Jan 31, 2019
@wking wking deleted the strip-binaries branch January 31, 2019 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants