From 1952384626b44b0323472381347e08612cecf93a Mon Sep 17 00:00:00 2001 From: Ying Li Date: Tue, 15 Nov 2016 15:43:36 -0800 Subject: [PATCH] Pass the netgo tag when building static binaries: - When building static binaries with CGO, cgo unix network segfaults - When building dynamically linked binaries with CGO, everything is fine https://github.com/prometheus/alertmanager/issues/304 https://github.com/golang/go/issues/7857 Signed-off-by: Ying Li --- Makefile | 6 +++--- buildscripts/cross.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 875788b56e..66d1cfa228 100644 --- a/Makefile +++ b/Makefile @@ -78,15 +78,15 @@ ${PREFIX}/bin/static/notary: else ${PREFIX}/bin/static/notary-server: NOTARY_VERSION $(shell find . -type f -name '*.go') @echo "+ $@" - @(export CGO_ENABLED=0; go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-server) + @(export CGO_ENABLED=0; go build -tags "${NOTARY_BUILDTAGS} netgo" -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-server) ${PREFIX}/bin/static/notary-signer: NOTARY_VERSION $(shell find . -type f -name '*.go') @echo "+ $@" - @(export CGO_ENABLED=0; go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-signer) + @(export CGO_ENABLED=0; go build -tags "${NOTARY_BUILDTAGS} netgo" -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-signer) ${PREFIX}/bin/static/notary: @echo "+ $@" - @go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary + @go build -tags "${NOTARY_BUILDTAGS} netgo" -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary endif diff --git a/buildscripts/cross.sh b/buildscripts/cross.sh index 500ecb7460..a73e6a8f4a 100755 --- a/buildscripts/cross.sh +++ b/buildscripts/cross.sh @@ -40,7 +40,7 @@ for os in "$@"; do go build \ -o "${NOTARYDIR}/cross/${GOOS}/${GOARCH}/${OUTFILE}" \ -a \ - -tags "${BUILDTAGS}" \ + -tags "${BUILDTAGS} netgo" \ -ldflags "-w ${CTIMEVAR} ${LDFLAGS}" \ ./cmd/notary; set +x;