cschwan / sage-on-gentoo

(Unofficial) Gentoo Overlay for Sage- and Sage-related ebuilds
84 stars 26 forks source link

Fix sci-mathematics/maxima using LDFLAGS incorrectly #619

Closed WGH- closed 3 years ago

WGH- commented 3 years ago

In ebuilds, LDFLAGS contain the compiler flags, and usually gcc is invoked instead of ld directly.

However, some packages invoke ld with LDFLAGS, and thus break. The workaround is to filter LDFLAGS before passing it to the package.

[1] discusses the similar problem where LDFLAGS are being passed to ld directly, and how to fix it.

[2] describes how the non-linker flags should be filtered out by $(raw-ldflags) altogether.

In my case, I have

CFLAGS="${CFLAGS} -flto=24 -fno-fat-lto-objects"
CXXFLAGS="${CXXFLAGS} -flto=24 -fno-fat-lto-objects"
LDFLAGS="${LDFLAGS} -flto=24 -fuse-linker-plugin"

Which leads to

/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognized option '--as-needed -flto=24 -fuse-linker-plugin'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

[1] https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed#Failure_in_compile.2C_unrecognized_option [2] https://bugs.gentoo.org/441808

kiwifb commented 3 years ago

I wasn't aware of this very useful flag-o-matic function. As for the PR, I would like you to move LDFLAGS=... after econf, it should still work and has the advantage of being recorded in config.log. I will be away until Monday in a few hours.

WGH- commented 3 years ago

Hm, I just noticed that in the original error message the set of unrecognized flags is --as-needed -flto=24 -fuse-linker-plugin. However, the original LDFLAGS is -Wl,-O1 -Wl,--as-needed -flto=24 -fuse-linker-plugin. Which means something converted -Wl,--as-needed to --as-needed, but, unlike raw-ldflags, left -flto=24 -fuse-linker-plugin flag as is. I wonder what that something is.

kiwifb commented 3 years ago

I think the error message means that it took the whole "--as-needed -flto=24 -fuse-linker-plugin" as one option, spaces and all.

WGH- commented 3 years ago

I think the error message means that it took the whole "--as-needed -flto=24 -fuse-linker-plugin" as one option, spaces and all.

If this's really true, then my reasoning is wrong, and the fix works only accidentally.

kiwifb commented 3 years ago

I think it has to be the block thing, otherwise there should have been separate errors for each options. If raw-LDFLAGS helps with breaking up strings by replacing it by bash array or something, that's a valid solution. May be not the best one but still valid.

After that there is inspecting maxima's configure.ac to see if anything is done wrong in it.

WGH- commented 3 years ago

The error actually happens during the ebuild install step, and the full error message is as follows:

(EXT:RUN-PROGRAM "x86_64-pc-linux-gnu-gcc" ("-o" "binary-ecl/maxima.fas" "-L/usr/lib64/" "/var/tmp/portage/sci-mathematics/maxima-5.44.0/temp/eclinitc0fJeN.o" "binary-ecl/maxima-package.o" "binary-ecl/ecl-port.o" "binary-ecl/autoconf-variables.o" "binary-ecl/intl.o" "binary-ecl/nregex.o" "binary-ecl/cl-info.o" "binary-ecl/sloop.o" "binary-ecl/lmdcls.o" "binary-ecl/letmac.o" "binary-ecl/generr.o" "binary-ecl/clmacs.o" "binary-ecl/defmfun-check.o" ...)):
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognized option '--as-needed -flto=24 -fuse-linker-plugin'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

Available restarts:

1. (CONTINUE) Continues anyway.
2. (RESTART-TOPLEVEL) Go back to Top-Level REPL.

Broken at BUILD-MAXIMA-LIB. In: #<process TOP-LEVEL 0x7ff52d816f80>.
 File: #P"/var/tmp/portage/sci-mathematics/maxima-5.44.0/work/maxima-5.44.0/src/maxima.system" (Position #2068)
kiwifb commented 3 years ago

Yes. This may be actually part of my sage additions :) But it looks to me like autoconf/automake extract raw ldflags to be used by ld, but they are badly parsed and it doesn't expect stuff that doesn't have -Wl in front of it. Which means that everything after the last -Wl is considered one block. Your fix actually pre-digest the LDFLAGS for the system avoiding the need for pre-parsing. While whatever autoconf/automake does should be looked at, the fix should be adequate.

And this should be my last message on github in 2020.