Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 333763 - flag-o-matic.eclass: strip-unsupported-flags does not strip '-Wl,...' LDFLAGS
Summary: flag-o-matic.eclass: strip-unsupported-flags does not strip '-Wl,...' LDFLAGS
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 333771 621274
  Show dependency tree
 
Reported: 2010-08-21 08:28 UTC by Dennis Schridde
Modified: 2019-12-24 11:01 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
0001-flag-o-matic.eclass-add-LDFLAGS-testing-against-link.patch (0001-flag-o-matic.eclass-add-LDFLAGS-testing-against-link.patch,4.72 KB, patch)
2019-12-23 11:49 UTC, Sergei Trofimovich (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Schridde 2010-08-21 08:28:59 UTC
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
Comment 1 Dennis Schridde 2010-08-21 09:39:37 UTC
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})
}
Comment 2 Dennis Schridde 2010-08-21 09:45:54 UTC
(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.
Comment 3 SpanKY gentoo-dev 2010-08-22 01:52:07 UTC
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.
Comment 4 Dennis Schridde 2010-08-24 08:15:27 UTC
(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?
Comment 5 Niels Ole Salscheider 2011-04-04 07:45:11 UTC
Are there any news on this bug? I'd really like to see bug 333771 resolved...
Comment 6 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-08-08 19:44:55 UTC
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.
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2019-01-27 11:15:50 UTC
dev-util/mingw64-runtime workaround was added in https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1da0f835568fceb6783247e174ea9dcb32bceac1
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2019-12-23 11:49:48 UTC
Created attachment 600532 [details, diff]
0001-flag-o-matic.eclass-add-LDFLAGS-testing-against-link.patch
Comment 9 Sergei Trofimovich (RETIRED) gentoo-dev 2019-12-23 11:58:21 UTC
Added 'c+ld' flavour of flag testing and sent it for review as:
    https://archives.gentoo.org/gentoo-dev/message/093c738019155c4ed29920b8d62dd89b
Comment 10 Larry the Git Cow gentoo-dev 2019-12-24 11:01:11 UTC
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(-)