d5298b
From 856a7f524b63f9033c47a8169fbf8a1cfdf69683 Mon Sep 17 00:00:00 2001
d5298b
From: Debarshi Ray <rishi@fedoraproject.org>
d5298b
Date: Mon, 29 Jun 2020 17:57:47 +0200
d5298b
Subject: [PATCH] build: Make the build flags match RHEL's %{gobuild}
d5298b
d5298b
The Go toolchain doesn't play well with passing compiler and linker
d5298b
flags via environment variables. The linker flags require a second
d5298b
level of quoting, which leaves the build system without a quote level
d5298b
to assign the flags to an environment variable like GOFLAGS.
d5298b
d5298b
This is one reason why RHEL doesn't have a RPM macro with only the
d5298b
flags. The %{gobuild} RPM macro includes the entire 'go build ...'
d5298b
invocation.
d5298b
d5298b
The Go toolchain also doesn't like the LDFLAGS environment variable as
d5298b
exported by RHEL's %{meson} RPM macro, and RHEL's RPM toolchain doesn't
d5298b
like the compressed DWARF data generated by the Go toolchain.
d5298b
d5298b
Note that these flags are meant for every CPU architecture other than
d5298b
PPC64, and should be kept updated to match RHEL's Go guidelines. Use
d5298b
'rpm --eval "%{gobuild}"' to expand the %{gobuild} macro.
d5298b
---
d5298b
 src/go-build-wrapper | 3 ++-
d5298b
 1 file changed, 2 insertions(+), 1 deletion(-)
d5298b
d5298b
diff --git a/src/go-build-wrapper b/src/go-build-wrapper
d5298b
index 515e1d8a0670..453b4cfa872b 100755
d5298b
--- a/src/go-build-wrapper
d5298b
+++ b/src/go-build-wrapper
d5298b
@@ -27,5 +27,6 @@ if ! cd "$1"; then
d5298b
     exit 1
d5298b
 fi
d5298b
 
d5298b
-go build -trimpath -ldflags "-extldflags '-Wl,--wrap,pthread_sigmask $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
d5298b
+unset LDFLAGS
d5298b
+go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -compressdwarf=false -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--wrap,pthread_sigmask $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -a -v -x -o "$2/toolbox"
d5298b
 exit "$?"
d5298b
-- 
d5298b
2.29.2
d5298b