Make more uniform GO build options.

Avoid building any of the GO stuff:

   make GOLANG=no ...

Build with a specific build of GO:

   make GO=~/sdk/go1.16rc1/bin/go ...

Also, now https://github.com/golang/go/issues/43149 is resolved in the
go1.16rc1 build (it does not work in the go1.16beta1 but we don't support
that one any more), remove the forced CGO use for the go/psx-signals build.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
This commit is contained in:
Andrew G. Morgan 2021-02-04 21:13:27 -08:00
parent ea1f4bf0d8
commit 068edb7265
4 changed files with 28 additions and 15 deletions

View File

@ -103,16 +103,21 @@ PAM_CAP ?= $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo $(SH
PTHREADS ?= yes
ifeq ($(PTHREADS),yes)
GO := go
GOLANG := $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
GO ?= go
GOLANG ?= $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
ifeq ($(GOLANG),yes)
GOROOT := $(shell $(GO) env GOROOT)
GOCGO := $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
GOOSARCH := $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
GOROOT ?= $(shell $(GO) env GOROOT)
GOCGO ?= $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
GOOSARCH ?= $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh $(GO))
ifeq ($(CGO_REQUIRED),1)
# Strictly speaking go1.15 doesn't need this, but 1.16 is when the
# real golang support arrives for non-cgo support, so drop the last
# vestige of legacy workarounds then.
CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]*
endif
CGO_CFLAGS := -I$(topdir)/libcap/include
CGO_LDFLAGS := -L$(topdir)/libcap
CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]*
CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh)
endif
endif

1
go/.gitignore vendored
View File

@ -3,6 +3,7 @@ compare-cap
try-launching
try-launching-cgo
psx-signals
psx-signals-cgo
b210613
mknames
web

View File

@ -76,12 +76,11 @@ ifeq ($(CGO_REQUIRED),0)
GO111MODULE=off CGO_ENABLED="1" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" GOPATH=$(GOPATH) $(GO) build -o $@-cgo $<
endif
# Bug reported issues:
# https://bugzilla.kernel.org/show_bug.cgi?id=210533 (cgo - fixed)
# https://github.com/golang/go/issues/43149 (nocgo - not fixed yet)
# When the latter is fixed we can replace CGO_ENABLED=1 with ="$(CGO_REQUIRED)"
psx-signals: psx-signals.go $(PSXGOPACKAGE)
GO111MODULE=off CGO_ENABLED=1 CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPATH=$(GOPATH) $(GO) build $<
psx-signals: psx-signals.go $(PSXGOPACKAGE)
GO111MODULE=off CGO_ENABLED="$(CGO_REQUIRED)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPATH=$(GOPATH) $(GO) build $<
ifeq ($(CGO_REQUIRED),0)
GO111MODULE=off CGO_ENABLED="1" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPATH=$(GOPATH) $(GO) build -o $@-cgo $<
endif
b210613: b210613.go $(CAPGOPACKAGE)
GO111MODULE=off CGO_ENABLED="$(CGO_REQUIRED)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPATH=$(GOPATH) $(GO) build $<
@ -91,6 +90,9 @@ test: all
GO111MODULE=off CGO_ENABLED="$(CGO_REQUIRED)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" GOPATH="$(GOPATH)" $(GO) test $(IMPORTDIR)/cap
LD_LIBRARY_PATH=../libcap ./compare-cap
./psx-signals
ifeq ($(CGO_REQUIRED),0)
./psx-signals-cgo
endif
./setid --caps=false
./gowns -- -c "echo gowns runs"
@ -122,5 +124,5 @@ clean:
rm -f web setid gowns
rm -f compare-cap try-launching try-launching-cgo
rm -f $(topdir)/cap/*~ $(topdir)/psx/*~
rm -f psx-signals b210613
rm -f b210613 psx-signals psx-signals-cgo
rm -fr pkg src

View File

@ -4,8 +4,13 @@
# available to the working go runtime or not. If it isn't we always
# have to use libcap/psx to get POSIX semantics for syscalls that
# change security state.
if [ -n "$1" ]; then
export GO="${1}"
else
export GO=go
fi
if [ -z "$(go doc syscall 2>/dev/null|grep AllThreadsSyscall)" ]; then
if [ -z "$(${GO} doc syscall 2>/dev/null|grep AllThreadsSyscall)" ]; then
echo "1"
else
echo "0"