Bug 104333 - [11/12 Regression] ICE with -flto -Wl,-plugin-opt=debug
Summary: [11/12 Regression] ICE with -flto -Wl,-plugin-opt=debug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 12.0
: P2 normal
Target Milestone: 11.3
Assignee: Martin Liška
URL:
Keywords: ice-on-invalid-code, lto
Depends on:
Blocks:
 
Reported: 2022-02-01 18:28 UTC by Jakub Jelinek
Modified: 2022-02-02 15:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-02-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2022-02-01 18:28:04 UTC
extern int printf (const char *, ...);
int foo (int arg) { return printf ("hello %d\n", arg); }
int main (int argc) { return foo (argc); }

./xgcc -B ./ -flto -Wl,-plugin-opt=debug rh2048551.c
ICEs
lto1: internal compiler error: in read_cgraph_and_symbols, at lto/lto-common.cc:2740
0xab4035 read_cgraph_and_symbols(unsigned int, char const**)
	../../gcc/lto/lto-common.cc:2740
0xa88d99 lto_main()
	../../gcc/lto/lto.cc:625
in GCC 11 and 12, while it correctly complains:
xgcc: error: debug: No such file or directory
in GCC 10.
The reporter meant -Wl,-plugin-opt=-debug which works in all cases, but we shouldn't ICE even on bad arguments.
Comment 1 Martin Liška 2022-02-02 09:41:23 UTC
Started with r11-6855-g4804de453e7f5f90. I can work on that.
Comment 2 Martin Liška 2022-02-02 10:01:18 UTC
I think the proper fix is reversion of the commit.
What do you think Nathan?
Comment 3 Martin Liška 2022-02-02 13:11:40 UTC
Oh, the commit is needed in order to prevent:

g++ hello.cc -fmodules-ts -std=c++20 -x c++-system-header string_view
g++: error: string_view: No such file or directory

Let me prepare a patch.
Comment 4 GCC Commits 2022-02-02 15:06:10 UTC
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:9a92e46c0e9a75cd14125493b8826d3e33dd0f67

commit r12-7002-g9a92e46c0e9a75cd14125493b8826d3e33dd0f67
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Feb 2 14:21:51 2022 +0100

    lto: fix error handling for -Wl,-plugin-opt=debug
    
    When one uses something like: -Wl,-plugin-opt=debug,
    we end up with lto1 WPA invocation that has 'debug'
    on command line. We interpret that as input filename.
    
    The patch moves resolution checking later so that we end up with
    a reasonable error message:
    
    lto1: fatal error: open debug failed: No such file or directory
    compilation terminated.
    
            PR lto/104333
    
    gcc/lto/ChangeLog:
    
            * lto-common.cc (read_cgraph_and_symbols): Move resolution
            checking for number of files later and report a reasonable
            error message.
            * lto-object.cc (lto_obj_file_open): Make error fatal.
Comment 5 GCC Commits 2022-02-02 15:10:22 UTC
The releases/gcc-11 branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

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

commit r11-9533-gfb812e0417adc20cac72986df3bf422ed007743c
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Feb 2 14:21:51 2022 +0100

    lto: fix error handling for -Wl,-plugin-opt=debug
    
    When one uses something like: -Wl,-plugin-opt=debug,
    we end up with lto1 WPA invocation that has 'debug'
    on command line. We interpret that as input filename.
    
    The patch moves resolution checking later so that we end up with
    a reasonable error message:
    
    lto1: fatal error: open debug failed: No such file or directory
    compilation terminated.
    
            PR lto/104333
    
    gcc/lto/ChangeLog:
    
            * lto-common.c (read_cgraph_and_symbols): Move resolution
            checking for number of files later and report a reasonable
            error message.
            * lto-object.c (lto_obj_file_open): Make error fatal.
    
    (cherry picked from commit 9a92e46c0e9a75cd14125493b8826d3e33dd0f67)
Comment 6 Martin Liška 2022-02-02 15:10:31 UTC
Fixed.