From d497c47dbb0c22ad99e4d7f99b41a5bd57eb1fcb Mon Sep 17 00:00:00 2001 From: Daniel P. Berrangé Date: Sep 18 2019 15:57:57 +0000 Subject: macros: remove arch conditional for setting pie flag The use of the %ifnarch conditional to control use of the '-buildmode pie' flag presents a problem for future patches which aim to allow Go build flags to be assigned to an shell env variable. There is no way to get rid of the leading and trailing newlines as %ifnarch must be on a separate line from the %{expand: clause. To eliminate this conditional, create two new files, macros.go-compilers-golang-{pie,nopie} which both define a %gocompilerflags macro. Only one of the two files should be installed, depending on whether the build architecture supports pie or not. Signed-off-by: Daniel P. Berrangé --- diff --git a/rpm/macros.d/macros.go-compilers-golang b/rpm/macros.d/macros.go-compilers-golang index 5b421d3..b928068 100644 --- a/rpm/macros.d/macros.go-compilers-golang +++ b/rpm/macros.d/macros.go-compilers-golang @@ -25,17 +25,12 @@ %gobuild(o:) %{expand: # https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12 %global _dwz_low_mem_die_limit 0 - %ifnarch ppc64 %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} GO111MODULE=off \\ - go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; - %else - %{?gobuilddir:GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"} GO111MODULE=off \\ - go build -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; - %endif + go build %{?gocompilerflags} -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; } ${workroot}${GOPATH:+:${GOPATH}} # Define commands for testing -%gotestflags -buildmode pie -compiler gc +%gotestflags %{gocompilerflags} %gotestextldflags %__global_ldflags %{?__golang_extldflags} %gotest() GO111MODULE=off go test %{gotestflags} -ldflags "${LDFLAGS:-}%{?currentgoldflags} -extldflags '%{gotestextldflags}'" %{?**}; diff --git a/rpm/macros.d/macros.go-compilers-golang-nopie b/rpm/macros.d/macros.go-compilers-golang-nopie new file mode 100644 index 0000000..a221a7c --- /dev/null +++ b/rpm/macros.d/macros.go-compilers-golang-nopie @@ -0,0 +1,2 @@ + +%gocompilerflags -compiler gc diff --git a/rpm/macros.d/macros.go-compilers-golang-pie b/rpm/macros.d/macros.go-compilers-golang-pie new file mode 100644 index 0000000..a190dea --- /dev/null +++ b/rpm/macros.d/macros.go-compilers-golang-pie @@ -0,0 +1,2 @@ + +%gocompilerflags -buildmode pie -compiler gc