From dd15b2ee4d256c4bc6bdd51b16c5c1ac76528328 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Mon, 16 Nov 2020 12:40:24 +0100 Subject: [PATCH] eclass: remove also other optimization flags with -Wl,-O* We need to filter not only `-Wl,-O1`, but also other flags like `-Wl,-O2`, `-Wl,-Og`, `-Wl,-Os`, etc. Otherwise, SDK build would fail, for example, as its default `$LDFLAGS` includes `-Wl,-O2`. We need to manually strip only the optimization element of comma-separated flags, e.g. from `-Wl,-O1,-s` to `-Wl,-s`. To support multiple characters that can follow `-O`, e.g. `-Ofast`, we should use regexp like `[[:alnum:]]*`. --- .../coreos-overlay/eclass/coreos-go-utils.eclass | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass index c0b339d86b..ad8ca1314f 100644 --- a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass +++ b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass @@ -87,7 +87,14 @@ go_export() { # Remove certain flags from $LDFLAGS to fix validation errors in # Go >= 1.15.5 like: # go build runtime/cgo: invalid flag in go:cgo_ldflag: -Wl,-O1 - filter-ldflags "-Wl,-O1" + # + # Note, we need to manually strip only the optimization element of + # comma-separated flags, e.g. from `-Wl,-O1,-s` to `-Wl,-s`. + # To support multiple characters that can follow `-O`, e.g. `-Ofast`, + # we should use regexp like `[[:alnum:]]*`. + # Work-around for https://github.com/golang/go/pull/42631. + export LDFLAGS="$(echo "$LDFLAGS" | sed 's/,-O[[:alnum:]]*//g')" + filter-ldflags "-Wl" export CC=$(tc-getCC) export CXX=$(tc-getCXX)