public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/113183] New: LTO crashes with Segmentation fault
@ 2023-12-30 19:35 sebunger44 at gmail dot com
  2023-12-30 19:40 ` [Bug lto/113183] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 19:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

            Bug ID: 113183
           Summary: LTO crashes with Segmentation fault
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebunger44 at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 56968
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56968&action=edit
Contains the LD and CPP files

I'm in the process of creating a tool-chain and porting FreeRTOS to our Leon2
based platform and ran into this with GCC 13.2. However, after reducing it to a
near trivial example, I can now also reproduce it on GCC 11.4 as shipped by
Ubuntu  22.04. So it probably has nothing to do with how I compiled my GCC etc.

Output:

$ gcc -nostartfiles -O2 -flto -T link.ld tt.cpp -o tt
‘
Segmentation fault
0x7f23ac64251f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f23ac629d8f __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x7f23ac629e3f __libc_start_main_impl
        ../csu/libc-start.c:392
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

Note that I do not expect this example to run in any way. I have cut out all
the target specific stuff so only plain old C++ remained.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
@ 2023-12-30 19:40 ` pinskia at gcc dot gnu.org
  2023-12-30 19:43 ` pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 19:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC trunk fails with:
```
[apinski@xeond2 tt]$ ~/upstream-gcc/bin/gcc -nostartfiles -O2 -flto -T link.ld
tt.cpp -o tt
tt.cpp:18:90: warning: ‘retain’ attribute ignored [-Wattributes]
   18 | static void const * const leon_init __attribute__((section
(".init_array"), retain, used)) = (void*)leon_initialise;
      |                                                                        
                 ^
tt.cpp:18:27: error: ‘leon_init’ causes a section type conflict
   18 | static void const * const leon_init __attribute__((section
(".init_array"), retain, used)) = (void*)leon_initialise;
      |                           ^
lto-wrapper: fatal error: /home/apinski/upstream-gcc/bin/gcc returned 1 exit
status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
```

RedHat's GCC 11.3.1 fails with the same:
```
[apinski@xeond2 tt]$ gcc -nostartfiles -O2 -flto -T link.ld tt.cpp -o tt
tt.cpp:18:90: warning: ‘retain’ attribute ignored [-Wattributes]
   18 | static void const * const leon_init __attribute__((section
(".init_array"), retain, used)) = (void*)leon_initialise;
      |                                                                        
                 ^
tt.cpp:18:27: error: ‘leon_init’ causes a section type conflict
   18 | static void const * const leon_init __attribute__((section
(".init_array"), retain, used)) = (void*)leon_initialise;
      |                           ^
lto-wrapper: fatal error: gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

```

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
  2023-12-30 19:40 ` [Bug lto/113183] " pinskia at gcc dot gnu.org
@ 2023-12-30 19:43 ` pinskia at gcc dot gnu.org
  2023-12-30 19:44 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 19:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
But changing env to Ubuntu, upstream GCC produces an ICE:
```
Segmentation fault
0xf370cf crash_signal
        /home/apinski/src/upstream-gcc/gcc/gcc/toplev.cc:316
0x7f1bac5a351f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xf940b6 default_tree_printer(pretty_printer*, text_info*, char const*, int,
bool, bool, bool, bool*, char const**)
        /home/apinski/src/upstream-gcc/gcc/gcc/tree-diagnostic.cc:274
0xf940b6 default_tree_printer(pretty_printer*, text_info*, char const*, int,
bool, bool, bool, bool*, char const**)
        /home/apinski/src/upstream-gcc/gcc/gcc/tree-diagnostic.cc:251
0x21d2ef4 pp_format(pretty_printer*, text_info*, urlifier const*)
        /home/apinski/src/upstream-gcc/gcc/gcc/pretty-print.cc:1602
0x21ad9cb diagnostic_context::report_diagnostic(diagnostic_info*)
        /home/apinski/src/upstream-gcc/gcc/gcc/diagnostic.cc:1604
0x21b1dd7 diagnostic_impl
        /home/apinski/src/upstream-gcc/gcc/gcc/diagnostic.cc:1767
0x21b1dd7 warning(int, char const*, ...)
        /home/apinski/src/upstream-gcc/gcc/gcc/diagnostic.cc:1900
0x12bdd17 switch_to_section(section*, tree_node*)
        /home/apinski/src/upstream-gcc/gcc/gcc/varasm.cc:7935
0x12c9cd2 assemble_variable(tree_node*, int, int, int)
        /home/apinski/src/upstream-gcc/gcc/gcc/varasm.cc:2407
0x12ce2f9 varpool_node::assemble_decl()
        /home/apinski/src/upstream-gcc/gcc/gcc/varpool.cc:596
0x12cee6e varpool_node::assemble_decl()
        /home/apinski/src/upstream-gcc/gcc/gcc/varpool.cc:568
0x12cee6e symbol_table::output_variables()
        /home/apinski/src/upstream-gcc/gcc/gcc/varpool.cc:764
0xa4865a symbol_table::compile()
        /home/apinski/src/upstream-gcc/gcc/gcc/cgraphunit.cc:2402
0x9951d1 lto_main()
        /home/apinski/src/upstream-gcc/gcc/gcc/lto/lto.cc:685
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
lto-wrapper: fatal error: /home/apinski/upstream-gcc/bin/gcc returned 1 exit
status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

```

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
  2023-12-30 19:40 ` [Bug lto/113183] " pinskia at gcc dot gnu.org
  2023-12-30 19:43 ` pinskia at gcc dot gnu.org
@ 2023-12-30 19:44 ` pinskia at gcc dot gnu.org
  2023-12-30 19:45 ` sebunger44 at gmail dot com
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 19:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
LD that causes the crash:
```
GNU ld (GNU Binutils for Ubuntu) 2.38
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
```

LD that works and gives an error:
```
GNU ld version 2.35.2-37.el9
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
```

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-12-30 19:44 ` pinskia at gcc dot gnu.org
@ 2023-12-30 19:45 ` sebunger44 at gmail dot com
  2023-12-30 19:46 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 19:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #4 from Sebastian Unger <sebunger44 at gmail dot com> ---
I should have mentioned that for my TC I use binutils 2.41.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-12-30 19:45 ` sebunger44 at gmail dot com
@ 2023-12-30 19:46 ` pinskia at gcc dot gnu.org
  2023-12-30 19:48 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 19:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I get the crash with a cross to aarch64 where both gcc and ld are from the
trunk.  So this does look like the crash was introduced by a ld change ...

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-12-30 19:46 ` pinskia at gcc dot gnu.org
@ 2023-12-30 19:48 ` pinskia at gcc dot gnu.org
  2023-12-30 19:48 ` sebunger44 at gmail dot com
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 19:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I suspect this part of the code example you gave:
```
static void const * const leon_init __attribute__((section (".init_array"),
retain, used)) = (void*)leon_initialise;
```

Is broken and should be rewritten anyways.
It is also what is causing the error and ICE (which is during the warning about
it) happening.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-12-30 19:48 ` pinskia at gcc dot gnu.org
@ 2023-12-30 19:48 ` sebunger44 at gmail dot com
  2023-12-30 19:49 ` sebunger44 at gmail dot com
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 19:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #7 from Sebastian Unger <sebunger44 at gmail dot com> ---
How is it broken and how should it be rewritten?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (6 preceding siblings ...)
  2023-12-30 19:48 ` sebunger44 at gmail dot com
@ 2023-12-30 19:49 ` sebunger44 at gmail dot com
  2023-12-30 19:49 ` sebunger44 at gmail dot com
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 19:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #8 from Sebastian Unger <sebunger44 at gmail dot com> ---
Not that on my target everything compiles and runs fine without -flto!

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-12-30 19:49 ` sebunger44 at gmail dot com
@ 2023-12-30 19:49 ` sebunger44 at gmail dot com
  2023-12-30 19:54 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 19:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #9 from Sebastian Unger <sebunger44 at gmail dot com> ---
(In reply to Sebastian Unger from comment #8)
> Not that on my target everything compiles and runs fine without -flto!

Not -> Note

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-12-30 19:49 ` sebunger44 at gmail dot com
@ 2023-12-30 19:54 ` pinskia at gcc dot gnu.org
  2023-12-30 20:00 ` sebunger44 at gmail dot com
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 19:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Changing it into:
static void leon_initialise(void) __attribute__((constructor));

Fixes the ICE and fixes the code to be better and not depened on init_array
there either ...

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (9 preceding siblings ...)
  2023-12-30 19:54 ` pinskia at gcc dot gnu.org
@ 2023-12-30 20:00 ` sebunger44 at gmail dot com
  2023-12-30 20:20 ` pinskia at gcc dot gnu.org
  2023-12-30 20:25 ` sebunger44 at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 20:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #11 from Sebastian Unger <sebunger44 at gmail dot com> ---
I see. It was the SORT_BY_INIT_PRIORITY with the section name used not actually
having a priority that triggered it, was it?! If I change the section name to
.init_array.1 then it works.

But, yes, you suggestion using the constructor attribute is even better.

Thank you very much.

I suspect it would still be better to not crash though. ;-)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (10 preceding siblings ...)
  2023-12-30 20:00 ` sebunger44 at gmail dot com
@ 2023-12-30 20:20 ` pinskia at gcc dot gnu.org
  2023-12-30 20:25 ` sebunger44 at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Sebastian Unger from comment #11)
> I see. It was the SORT_BY_INIT_PRIORITY with the section name used not
> actually having a priority that triggered it, was it?! If I change the
> section name to .init_array.1 then it works.
> 
> But, yes, you suggestion using the constructor attribute is even better.
> 
> Thank you very much.
> 
> I suspect it would still be better to not crash though. ;-)

Changing the linker script to:
```
  .preinit_array : { KEEP(*(SORT_BY_INIT_PRIORITY(".preinit_array.*"))) KEEP
(*(.preinit_array)) } >"LOADER_REGION"
  __preinit_array_start = ADDR(.preinit_array);
  __preinit_array_end = ADDR(.preinit_array) + SIZEOF(.preinit_array);

  .init_array : { KEEP(*(SORT_BY_INIT_PRIORITY(".init_array.*"))) KEEP
(*(.init_array))  } >"LOADER_REGION"

```

Also fixes the ICE if you don't want to change to use the constructor
attribute.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug lto/113183] LTO crashes with Segmentation fault
  2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
                   ` (11 preceding siblings ...)
  2023-12-30 20:20 ` pinskia at gcc dot gnu.org
@ 2023-12-30 20:25 ` sebunger44 at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: sebunger44 at gmail dot com @ 2023-12-30 20:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183

--- Comment #13 from Sebastian Unger <sebunger44 at gmail dot com> ---
No worries, the constructor attribute is much better. I was aware of that, but
at the time had already several examples using .preinit_array and couldn't be
bothered to look it up. I later added the sort by priority and added priorities
to  the *init_array symbols that needed them, but not this one. Interestingly,
that was not when LTO started crashing (or I might have made the connection).
LTO only started crashing once I added the static global object NonTrivial!
Weird.

In any case, I have changed to the constructor attribute and learned my lesson
and am all good.

I'll leave this issue open in case someone wants to fix the crash in LD (or
wherever it comes from) so people running into this in the future will get a
nicer error message.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-12-30 20:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-30 19:35 [Bug lto/113183] New: LTO crashes with Segmentation fault sebunger44 at gmail dot com
2023-12-30 19:40 ` [Bug lto/113183] " pinskia at gcc dot gnu.org
2023-12-30 19:43 ` pinskia at gcc dot gnu.org
2023-12-30 19:44 ` pinskia at gcc dot gnu.org
2023-12-30 19:45 ` sebunger44 at gmail dot com
2023-12-30 19:46 ` pinskia at gcc dot gnu.org
2023-12-30 19:48 ` pinskia at gcc dot gnu.org
2023-12-30 19:48 ` sebunger44 at gmail dot com
2023-12-30 19:49 ` sebunger44 at gmail dot com
2023-12-30 19:49 ` sebunger44 at gmail dot com
2023-12-30 19:54 ` pinskia at gcc dot gnu.org
2023-12-30 20:00 ` sebunger44 at gmail dot com
2023-12-30 20:20 ` pinskia at gcc dot gnu.org
2023-12-30 20:25 ` sebunger44 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).