Skip to content

Commit

Permalink
make: strip symbol tables from all binaries by default
Browse files Browse the repository at this point in the history
Strip the symbol tables and debug information from all binaries by
default. This will not remove annotations needed for stack traces, so
panic backtraces will still be readable.

If debug information and symbol tables are needed during debugging, use
`make NOSTRIP=1` to compile.

This reduces the binary sizes (and thus the base memory consumption) as
follows:

before:

    -rwxr-xr-x 1 tklauser tklauser 46M Feb 21 14:05 cilium/cilium
    -rwxr-xr-x 1 tklauser tklauser 21M Feb 21 14:05 cilium-health/cilium-health
    -rwxr-xr-x 1 tklauser tklauser 71M Feb 21 14:05 daemon/cilium-agent
    -rwxr-xr-x 1 tklauser tklauser 74M Feb 21 14:05 operator/cilium-operator
    -rwxr-xr-x 1 tklauser tklauser 46M Feb 21 14:04 plugins/cilium-cni/cilium-cni

after:

    -rwxr-xr-x 1 tklauser tklauser 46M Feb 21 14:08 cilium/cilium
    -rwxr-xr-x 1 tklauser tklauser 15M Feb 21 14:08 cilium-health/cilium-health
    -rwxr-xr-x 1 tklauser tklauser 52M Feb 21 14:08 daemon/cilium-agent
    -rwxr-xr-x 1 tklauser tklauser 55M Feb 21 14:08 operator/cilium-operator
    -rwxr-xr-x 1 tklauser tklauser 34M Feb 21 14:08 plugins/cilium-cni/cilium-cni

summary:

    cilium           0MB (already stripped previously, see 8596bd9)
    cilium-agent    ~19MB
    cilium-health   ~6MB
    cilium-operator ~19MB
    cilium-cni      ~12MB

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

Updates #6099
Updates #10056

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser committed Feb 27, 2020
1 parent b676c4c commit 7f89309
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Makefile.defs
Expand Up @@ -33,6 +33,15 @@ endif
BUILD = $(VERSION) $(GIT_VERSION) $(shell $(GO) version)
GOLDFLAGS = -X "github.com/cilium/cilium/pkg/version.Version=$(BUILD)"

ifeq ($(NOSTRIP),)
# Note: these options will not remove annotations needed for stack
# traces, so panic backtraces will still be readable.
#
# -w: Omit the DWARF symbol table.
# -s: Omit the symbol table and debug information.
GOLDFLAGS += -s -w
endif

CILIUM_ENVOY_SHA=$(shell grep -o "FROM.*cilium/cilium-envoy:[0-9a-fA-F]*" $(ROOT_DIR)/Dockerfile | cut -d : -f 2)
GOLDFLAGS += -X "github.com/cilium/cilium/pkg/envoy.RequiredEnvoyVersionSHA=$(CILIUM_ENVOY_SHA)"

Expand Down
1 change: 0 additions & 1 deletion cilium-docker-plugin.Dockerfile
Expand Up @@ -5,7 +5,6 @@ WORKDIR /go/src/github.com/cilium/cilium/plugins/cilium-docker
ARG LOCKDEBUG
ARG V
RUN make CGO_ENABLED=0 GOOS=linux LOCKDEBUG=$LOCKDEBUG PKG_BUILD=1 EXTRA_GOBUILD_FLAGS="-a -installsuffix cgo"
RUN strip cilium-docker

FROM scratch
LABEL maintainer="maintainer@cilium.io"
Expand Down
1 change: 0 additions & 1 deletion cilium-operator.Dockerfile
Expand Up @@ -5,7 +5,6 @@ WORKDIR /go/src/github.com/cilium/cilium/operator
ARG LOCKDEBUG
ARG V
RUN make CGO_ENABLED=0 GOOS=linux LOCKDEBUG=$LOCKDEBUG PKG_BUILD=1 EXTRA_GOBUILD_FLAGS="-a -installsuffix cgo"
RUN strip cilium-operator

FROM docker.io/library/alpine:3.9.3 as certs
RUN apk --update add ca-certificates
Expand Down
1 change: 0 additions & 1 deletion cilium/Makefile
Expand Up @@ -7,7 +7,6 @@ SOURCES := $(shell find ../api ../daemon ../common ../pkg cmd . \( -name '*.go'
$(TARGET): $(SOURCES)
@$(ECHO_GO)
$(QUIET)$(GO) build $(GOBUILD) -o $(TARGET)
strip $(TARGET)

all: $(TARGET)

Expand Down

0 comments on commit 7f89309

Please sign in to comment.