Skip to content

Commit 068edb7

Browse files
committed
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 golang/go#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 <[email protected]>
1 parent ea1f4bf commit 068edb7

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

Make.Rules

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,21 @@ PAM_CAP ?= $(shell if [ -f /usr/include/security/pam_modules.h ]; then echo $(SH
103103
PTHREADS ?= yes
104104

105105
ifeq ($(PTHREADS),yes)
106-
GO := go
107-
GOLANG := $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
106+
GO ?= go
107+
GOLANG ?= $(shell if [ -n "$(shell $(GO) version 2>/dev/null)" ]; then echo yes ; else echo no ; fi)
108108
ifeq ($(GOLANG),yes)
109-
GOROOT := $(shell $(GO) env GOROOT)
110-
GOCGO := $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
111-
GOOSARCH := $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
109+
GOROOT ?= $(shell $(GO) env GOROOT)
110+
GOCGO ?= $(shell if [ "$(shell $(GO) env CGO_ENABLED)" = 1 ]; then echo yes ; else echo no ; fi)
111+
GOOSARCH ?= $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
112+
CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh $(GO))
113+
ifeq ($(CGO_REQUIRED),1)
114+
# Strictly speaking go1.15 doesn't need this, but 1.16 is when the
115+
# real golang support arrives for non-cgo support, so drop the last
116+
# vestige of legacy workarounds then.
117+
CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]*
118+
endif
112119
CGO_CFLAGS := -I$(topdir)/libcap/include
113120
CGO_LDFLAGS := -L$(topdir)/libcap
114-
CGO_LDFLAGS_ALLOW := -Wl,-?-wrap[=,][^-.@][^,]*
115-
CGO_REQUIRED=$(shell $(topdir)/go/cgo-required.sh)
116121
endif
117122
endif
118123

go/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ compare-cap
33
try-launching
44
try-launching-cgo
55
psx-signals
6+
psx-signals-cgo
67
b210613
78
mknames
89
web

go/Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@ ifeq ($(CGO_REQUIRED),0)
7676
GO111MODULE=off CGO_ENABLED="1" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" GOPATH=$(GOPATH) $(GO) build -o $@-cgo $<
7777
endif
7878

79-
# Bug reported issues:
80-
# https://bugzilla.kernel.org/show_bug.cgi?id=210533 (cgo - fixed)
81-
# https://github.com/golang/go/issues/43149 (nocgo - not fixed yet)
82-
# When the latter is fixed we can replace CGO_ENABLED=1 with ="$(CGO_REQUIRED)"
83-
psx-signals: psx-signals.go $(PSXGOPACKAGE)
84-
GO111MODULE=off CGO_ENABLED=1 CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPATH=$(GOPATH) $(GO) build $<
79+
psx-signals: psx-signals.go $(PSXGOPACKAGE)
80+
GO111MODULE=off CGO_ENABLED="$(CGO_REQUIRED)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" GOPATH=$(GOPATH) $(GO) build $<
81+
ifeq ($(CGO_REQUIRED),0)
82+
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 $<
83+
endif
8584

8685
b210613: b210613.go $(CAPGOPACKAGE)
8786
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
9190
GO111MODULE=off CGO_ENABLED="$(CGO_REQUIRED)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" GOPATH="$(GOPATH)" $(GO) test $(IMPORTDIR)/cap
9291
LD_LIBRARY_PATH=../libcap ./compare-cap
9392
./psx-signals
93+
ifeq ($(CGO_REQUIRED),0)
94+
./psx-signals-cgo
95+
endif
9496
./setid --caps=false
9597
./gowns -- -c "echo gowns runs"
9698

@@ -122,5 +124,5 @@ clean:
122124
rm -f web setid gowns
123125
rm -f compare-cap try-launching try-launching-cgo
124126
rm -f $(topdir)/cap/*~ $(topdir)/psx/*~
125-
rm -f psx-signals b210613
127+
rm -f b210613 psx-signals psx-signals-cgo
126128
rm -fr pkg src

go/cgo-required.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
# available to the working go runtime or not. If it isn't we always
55
# have to use libcap/psx to get POSIX semantics for syscalls that
66
# change security state.
7+
if [ -n "$1" ]; then
8+
export GO="${1}"
9+
else
10+
export GO=go
11+
fi
712

8-
if [ -z "$(go doc syscall 2>/dev/null|grep AllThreadsSyscall)" ]; then
13+
if [ -z "$(${GO} doc syscall 2>/dev/null|grep AllThreadsSyscall)" ]; then
914
echo "1"
1015
else
1116
echo "0"

0 commit comments

Comments
 (0)