[Bug lto/113183] New: LTO crashes with Segmentation fault
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 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.
[Bug lto/113183] LTO crashes with Segmentation fault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183 --- Comment #4 from Sebastian Unger --- I should have mentioned that for my TC I use binutils 2.41.
[Bug lto/113183] LTO crashes with Segmentation fault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183 --- Comment #7 from Sebastian Unger --- How is it broken and how should it be rewritten?
[Bug lto/113183] LTO crashes with Segmentation fault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183 --- Comment #8 from Sebastian Unger --- Not that on my target everything compiles and runs fine without -flto!
[Bug lto/113183] LTO crashes with Segmentation fault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183 --- Comment #9 from Sebastian Unger --- (In reply to Sebastian Unger from comment #8) > Not that on my target everything compiles and runs fine without -flto! Not -> Note
[Bug lto/113183] LTO crashes with Segmentation fault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183 --- Comment #11 from Sebastian Unger --- 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. ;-)
[Bug lto/113183] LTO crashes with Segmentation fault
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113183 --- Comment #13 from Sebastian Unger --- 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.