commit:     f8153b536170f72d88012a48180e1e32ee92091d
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 28 13:53:25 2020 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Sat Jan 30 09:54:37 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f8153b53

haskell-cabal.eclass: filter out -flto|-flto=* flags

`ghc` uses partial linking to glue together object
files produced by `gcc` and `ghc`. In case of -flto*
flags we have a chance to mix IR section incorrectly
due to ld deficiency: https://sourceware.org/PR12291

Let's filter out -flto-related flags until binutils is
ready.

Reported-by: matoro
Closes: https://github.com/gentoo-haskell/gentoo-haskell/issues/1110
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 eclass/haskell-cabal.eclass | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/eclass/haskell-cabal.eclass b/eclass/haskell-cabal.eclass
index 4908e4491e6..8706cc99478 100644
--- a/eclass/haskell-cabal.eclass
+++ b/eclass/haskell-cabal.eclass
@@ -342,10 +342,34 @@ cabal-configure() {
        fi
 
        # currently cabal does not respect CFLAGS and LDFLAGS on it's own (bug 
#333217)
-       # so translate LDFLAGS to ghc parameters (without filtering)
+       # so translate LDFLAGS to ghc parameters (with mild filtering).
        local flag
-       for flag in   $CFLAGS; do cabalconf+=(--ghc-option="-optc$flag"); done
-       for flag in  $LDFLAGS; do cabalconf+=(--ghc-option="-optl$flag"); done
+       for flag in   $CFLAGS; do
+               case "${flag}" in
+                       -flto|-flto=*)
+                               # binutils does not support partial linking yet:
+                               # 
https://github.com/gentoo-haskell/gentoo-haskell/issues/1110
+                               # https://sourceware.org/PR12291
+                               einfo "Filter '${flag}' out of CFLAGS (avoid 
lto partial linking)"
+                               continue
+                               ;;
+               esac
+
+               cabalconf+=(--ghc-option="-optc$flag")
+       done
+       for flag in  $LDFLAGS; do
+               case "${flag}" in
+                       -flto|-flto=*)
+                               # binutils does not support partial linking yet:
+                               # 
https://github.com/gentoo-haskell/gentoo-haskell/issues/1110
+                               # https://sourceware.org/PR12291
+                               einfo "Filter '${flag}' out of LDFLAGS (avoid 
lto partial linking)"
+                               continue
+                               ;;
+               esac
+
+               cabalconf+=(--ghc-option="-optl$flag")
+       done
 
        # disable executable stripping for the executables, as portage will
        # strip by itself, and pre-stripping gives a QA warning.

Reply via email to