Bug 47785 - GCC with -flto does not pass -Wa/-Xassembler options to the assembler
Summary: GCC with -flto does not pass -Wa/-Xassembler options to the assembler
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 8.0.1
: P3 normal
Target Milestone: 9.4
Assignee: Not yet assigned to anyone
URL: https://gcc.gnu.org/ml/gcc-patches/20...
Keywords: lto, patch
: 61168 68788 70415 78353 84230 88250 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-02-17 16:49 UTC by Dmitry Gorbachev
Modified: 2021-07-15 17:48 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.5.3, 4.6.0
Last reconfirmed: 2018-02-06 00:00:00


Attachments
Testcase (219 bytes, text/plain)
2011-02-17 16:49 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2011-02-17 16:49:33 UTC
Created attachment 23384 [details]
Testcase
Comment 1 Richard Biener 2011-02-18 12:00:41 UTC
Confirmed.
Comment 2 Richard Biener 2011-11-02 15:01:09 UTC
For this to be fixed we'd need something similar to COLLECT_GCC_OPTIONS,
COLLECT_AS_OPTIONS for example, and lto-wrapper passing those on via
-Wa to the link-time driver.
Comment 3 m8r-540gv7 2014-06-12 18:01:11 UTC
This causes compilation of AVX code using GCC 4.9 to fail on OS X Mavericks; any plans to fix?
Comment 4 Dominique d'Humieres 2014-06-12 18:18:30 UTC
*** Bug 61168 has been marked as a duplicate of this bug. ***
Comment 5 Dominique d'Humieres 2014-06-12 18:20:04 UTC
> This causes compilation of AVX code using GCC 4.9 to fail on OS X Mavericks; ...

Exactly why I have opened pr61168!-(still not fixed).
Comment 6 Ray Kinsella 2015-07-17 14:01:31 UTC
Confirmed as still not fixed in 4.9.1 (with Yocto 1.8)
Comment 7 Dominique d'Humieres 2015-09-23 12:11:18 UTC
Another instance on x86_64-apple-darwin14 with Xcode 7

[Book15] f90/bug% gcc6 /opt/gcc/_clean/gcc/testsuite/gcc.dg/debug/pr41893-1.c -gstabs1 -Wa,-Q -flto -fwhole-program -O /opt/gcc/_clean/gcc/testsuite/gcc.dg/debug/pr41893-2.c
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:1:9: error: unsupported directive '.stabs'
        .stabs  "/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccnRWDSD.ltrans0.o",100,0,0,Ltext0
                ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:4:9: error: unsupported directive '.stabs'
        .stabs  "gcc2_compiled.",60,0,0,0
                ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:8:9: error: unsupported directive '.stabs'
        .stabs  "/opt/gcc/_clean/gcc/testsuite/gcc.dg/debug/pr41893-1.c",132,0,0,Ltext1
                ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:10:2: error: unknown directive
        .stabd  68,0,16
        ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:13:2: error: unknown directive
        .stabd  68,0,16
        ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:17:9: error: unsupported directive '.stabs'
        .stabs  "main:F(0,1)=r(0,1);-2147483648;2147483647;",36,0,0,_main
                ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:22:2: error: unknown directive
        .stabd  68,0,12
        ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:27:9: error: unsupported directive '.stabs'
        .stabs  "func1:F(0,2)=(0,2)",36,0,0,_func1
                ^
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccJ7keUF.s:72:9: error: unsupported directive '.stabs'
        .stabs  "",100,0,0,Letext0
                ^
lto-wrapper: fatal error: gcc6 returned 1 exit status
compilation terminated.
collect2: fatal error: lto-wrapper returned 1 exit status
compilation terminated.
Comment 8 Dominique d'Humieres 2015-12-08 10:35:26 UTC
*** Bug 68788 has been marked as a duplicate of this bug. ***
Comment 9 Richard Biener 2016-03-29 09:01:17 UTC
*** Bug 70415 has been marked as a duplicate of this bug. ***
Comment 10 Drea Pinski 2016-11-14 22:56:45 UTC
*** Bug 78353 has been marked as a duplicate of this bug. ***
Comment 11 Georg-Johann Lay 2018-02-06 12:07:05 UTC
*** Bug 84230 has been marked as a duplicate of this bug. ***
Comment 12 Drea Pinski 2018-11-28 19:11:49 UTC
*** Bug 88250 has been marked as a duplicate of this bug. ***
Comment 13 Richard Biener 2018-11-29 09:42:04 UTC
Note the proposed solution only works for uniform -Wa options across all TUs
participating in the optimizing link.  Otherwise partitioning can merge parts of TUs with different flags and there is (IIRC) no way to annotate parts of
an assembly file with different assembler flags.  Supporting non-uniform -Wa
flags would require either adjusting partitioning according to flags
(disliked by some folks but also would help in other cases), or emitting
multiple object files (assembler files) from a single LTRANS CU.

Note there's the question if it is valid to inline across -Wa flag differences
as well.

For the specific case of -Wa,-msse2avx target maintainers might consider
adding a -msse2avx compiler flag triggering the assembler flag via specs
processing.
Comment 14 kugan 2019-10-22 06:44:20 UTC
A patch for this is posted at
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01471.html
Comment 15 H.J. Lu 2019-10-29 16:13:36 UTC
We need to also handle -Xassembler? Since -Wa, doesn't work with comma in
assembler options, like -mfoo=foo1,foo2, one needs to use

-Xassembler -mfoo=foo1,foo2

to pass -mfoo=foo1,foo2 to assembler.
Comment 16 H.J. Lu 2019-10-29 21:54:48 UTC
(In reply to H.J. Lu from comment #15)
> We need to also handle -Xassembler? Since -Wa, doesn't work with comma in
> assembler options, like -mfoo=foo1,foo2, one needs to use
> 
> -Xassembler -mfoo=foo1,foo2
> 
> to pass -mfoo=foo1,foo2 to assembler.

We may also have

-Xassembler -mfoo=foo1,foo2 -Wa,-mbar
Comment 17 GCC Commits 2020-02-24 06:27:41 UTC
The master branch has been updated by Prathamesh Kulkarni <prathamesh3492@gcc.gnu.org>:

https://gcc.gnu.org/g:f1a681a174cdfb82e62c246d6f4add9a25fc2e43

commit r10-6807-gf1a681a174cdfb82e62c246d6f4add9a25fc2e43
Author: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Date:   Mon Feb 24 11:55:45 2020 +0530

    PR47785: Add support for handling Xassembler/Wa options with LTO.
    
    2020-02-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
    	    Kugan Vivekandarajah  <kugan.vivekanandarajah@linaro.org>
    
    	PR driver/47785
    	* gcc.c (putenv_COLLECT_AS_OPTIONS): New function.
    	(driver::main): Call putenv_COLLECT_AS_OPTIONS.
    	* opts-common.c (parse_options_from_collect_gcc_options): New function.
    	(prepend_xassembler_to_collect_as_options): Likewise.
    	* opts.h (parse_options_from_collect_gcc_options): Declare prototype.
    	(prepend_xassembler_to_collect_as_options): Likewise.
    	* lto-opts.c (lto_write_options): Stream assembler options
    	in COLLECT_AS_OPTIONS.
    	* lto-wrapper.c (xassembler_options_error): New static variable.
    	(get_options_from_collect_gcc_options): Move parsing options code to
    	parse_options_from_collect_gcc_options and call it.
    	(merge_and_complain): Validate -Xassembler options.
    	(append_compiler_options): Handle OPT_Xassembler.
    	(run_gcc): Append command line -Xassembler options to
    	collect_gcc_options.
    	* doc/invoke.texi: Add documentation about using Xassembler
    	options with LTO.
    
    testsuite/
    	* gcc.target/arm/pr78353-1.c: New test.
    	* gcc.target/arm/pr78353-2.c: Likewise.
Comment 18 Mark Wielaard 2020-07-16 22:19:20 UTC
Since this patch has been included in gcc10 (I verified it works now, but fails with gcc9) can this issue be closed? Or does it need backporting to earlier versions?
Comment 19 H.J. Lu 2021-04-09 16:56:33 UTC
I'd like to backport it to GCC 9.
Comment 20 GCC Commits 2021-04-12 12:29:59 UTC
The releases/gcc-9 branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:ecdb697389b284a0f3912932e0a440c1071fbadd

commit r9-9344-gecdb697389b284a0f3912932e0a440c1071fbadd
Author: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Date:   Mon Feb 24 11:55:45 2020 +0530

    PR47785: Add support for handling Xassembler/Wa options with LTO.
    
    Skip the test if arm7a is not supported at link time. This is the case
    if the toolchain targets an M-profile CPU by default and does not have
    A-profile multilib: the link step fails because it tries to mix
    M-profile startup files with A-profile testcase.
    
    gcc/
    
    2020-02-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
                Kugan Vivekandarajah  <kugan.vivekanandarajah@linaro.org>
    
            PR driver/47785
            * gcc.c (putenv_COLLECT_AS_OPTIONS): New function.
            (driver::main): Call putenv_COLLECT_AS_OPTIONS.
            * opts-common.c (parse_options_from_collect_gcc_options): New function.
            (prepend_xassembler_to_collect_as_options): Likewise.
            * opts.h (parse_options_from_collect_gcc_options): Declare prototype.
            (prepend_xassembler_to_collect_as_options): Likewise.
            * lto-opts.c (lto_write_options): Stream assembler options
            in COLLECT_AS_OPTIONS.
            * lto-wrapper.c (xassembler_options_error): New static variable.
            (get_options_from_collect_gcc_options): Move parsing options code to
            parse_options_from_collect_gcc_options and call it.
            (merge_and_complain): Validate -Xassembler options.
            (append_compiler_options): Handle OPT_Xassembler.
            (run_gcc): Append command line -Xassembler options to
            collect_gcc_options.
            * doc/invoke.texi: Add documentation about using Xassembler
            options with LTO.
    
    gcc/testsuite/
    
    2020-02-24  Christophe Lyon  <christophe.lyon@linaro.org>
    
            PR lto/78353
            * gcc.target/arm/pr78353-1.c: Add arm_arch_v7a_multilib effective
            target.
            * gcc.target/arm/pr78353-2.c: Likewise.
    
    2020-02-24  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
                Kugan Vivekandarajah  <kugan.vivekanandarajah@linaro.org>
    
            * gcc.target/arm/pr78353-1.c: New test.
            * gcc.target/arm/pr78353-2.c: Likewise.
    
    (cherry picked from commit f1a681a174cdfb82e62c246d6f4add9a25fc2e43)
Comment 21 Thomas Weißschuh 2021-06-19 07:46:22 UTC
The commited fix produces false positives for assembler options that do not influence the compilation output directly.
For example "-a=$FILE" to create assembler listings. (Whose target files have to differ between different input files by design.)
Comment 22 H.J. Lu 2021-07-15 17:48:37 UTC
Fix for GCC 10 and GCC 9.4.