strip-unsupported-flags strips {C,CXX,F,FC}FLAGS, but not LDFLAGS. I noticed this while crosscompiling: /usr/libexec/gcc/i686-pc-mingw32/ld: unrecognized option '--hash-style=gnu' Reproducible: Always
This code does the job (no, it's not pretty): test-flag-LD() { local flags="$1" [[ -z ${flags} ]] && \ return 1 local PROG=$(tc-getCC) local tmpfile=$(mktemp tmp.test-flag-LD.XXXXXX) echo 'int main(void){}' \ | ${PROG} ${flags} -o "${tmpfile}" -xc - \ > /dev/null 2&>1 local ret=$? rm -f "${tmpfile}" > /dev/null 2&>1 return $ret } test-flags-LD() { test-flags-PROG "LD" "$@"; } strip-unsupported-flags() { export CFLAGS=$(test-flags-CC ${CFLAGS}) export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS}) export FFLAGS=$(test-flags-F77 ${FFLAGS}) export FCFLAGS=$(test-flags-FC ${FCFLAGS}) export LDFLAGS=$(test-flags-LD ${LDFLAGS}) }
(In reply to comment #1) > local PROG=$(tc-getCC) > local tmpfile=$(mktemp tmp.test-flag-LD.XXXXXX) > echo 'int main(void){}' \ > | ${PROG} ${flags} -o "${tmpfile}" -xc - \ > > /dev/null 2&>1 Explanation: LD needs ${LDFLAGS//-Wl,/} instead of plain LDFLAGS. Hence for simplicity I use CC to do the unwrapping (I need it anyway, s.b.). LD does not accept no or empty input files. Thus a minimal program has to be compiled, for which I also have to use CC. LD does neither accept /dev/null as output file (error: "... truncated"), which is why I have to use a temporary file for compilation/linking. To clean these temporary files up I use rm after compilation, which in turn requires me to save the return code of CC.
i think doing a simple link via the compiler driver is fine. then you dont need to strip the flags at all when testing them.
(In reply to comment #3) > i think doing a simple link via the compiler driver is fine. then you dont > need to strip the flags at all when testing them. For lack of further replies I begin to wonder: Is there anything wrong with my code? Do you expect me to do any improvements?
Are there any news on this bug? I'd really like to see bug 333771 resolved...
commit 0e6d20439e89c82fa99bbaefbe2a728efc77631c Author: Michał Górny <mgorny@gentoo.org> AuthorDate: Sat Jul 1 18:14:44 2017 Commit: Michał Górny <mgorny@gentoo.org> CommitDate: Tue Aug 8 21:42:17 2017 flag-o-matic.eclass: Strip LDFLAGS unsupported by the C compiler, #621274 Include LDFLAGS in the variables stripped by strip-unsupported-flags. The code reuses the current functions for testing CC, and so only remove LDFLAGS that are rejected by the C compiler and not the linker. This solves the case of bug #621274 where LDFLAGS contained GCC-specific -flto flag. So it's partially solved now. It doesn't solve the core issue of invalid -Wl flags though.
dev-util/mingw64-runtime workaround was added in https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1da0f835568fceb6783247e174ea9dcb32bceac1
Created attachment 600532 [details, diff] 0001-flag-o-matic.eclass-add-LDFLAGS-testing-against-link.patch
Added 'c+ld' flavour of flag testing and sent it for review as: https://archives.gentoo.org/gentoo-dev/message/093c738019155c4ed29920b8d62dd89b
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=28d6437fc7009002f98f28e8900e994109927726 commit 28d6437fc7009002f98f28e8900e994109927726 Author: Sergei Trofimovich <slyfox@gentoo.org> AuthorDate: 2019-12-23 11:41:20 +0000 Commit: Sergei Trofimovich <slyfox@gentoo.org> CommitDate: 2019-12-24 11:01:01 +0000 flag-o-matic.eclass: add LDFLAGS testing against linker Before the change we tested only compiler driver (gcc flag parser) for LDFLAGS. This does not cover cases when we would really like to filter out unsupported linker flags like -Wl,--hash-style=gnu passed to non-ELF targets. The change adds test-flag-CCLD() helper to perform all of assembly, compilation and linking steps. Helper is used to filter LDFLAGS variable in strip-unsupported-flags(). Closes: https://bugs.gentoo.org/333763 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> eclass/flag-o-matic.eclass | 72 +++++++++++++++++++++++++++++++++++--------- eclass/tests/flag-o-matic.sh | 2 +- 2 files changed, 59 insertions(+), 15 deletions(-)