Bug 24145

Summary: GDB 8.2 crashes while loading symbols of an LTO application
Product: gdb Reporter: Liviu Ionescu <ilg>
Component: gdbAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: alan.hayward, keiths, ramana
Priority: P2    
Version: 8.2   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: The project that crashes with segmentation fault
The project that trows the assert

Description Liviu Ionescu 2019-01-28 14:05:02 UTC
The problem was observed with the Arm Embedded GCC toolchain gcc-arm-none-eabi-8-2018-q4-major; the previous Arm release gcc-arm-none-eabi-7-2017-q4-major seems ok, so the bug was introduced in this interval.


While investigating, I used two projects (both in the attached archive). 

The initial project (f4b-lto) was created by the GNU MCU Eclipse STM32F4 blinky template.

The f4b-lto/Debug/f4b-lto.elf crashes GDB early while loding the symbols:

$ /Users/ilg/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gdb /Users/ilg/Desktop/eclipse-workspace-2018-12/f4b-lto/Debug/f4b-lto.elf 
GNU gdb (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.50.20181213-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
/Users/ilg/.gdbinit:1: Error in sourced command file:
No symbol table is loaded.  Use the "file" command.
Reading symbols from /Users/ilg/Desktop/eclipse-workspace-2018-12/f4b-lto/Debug/f4b-lto.elf...
Segmentation fault: 11
ilg-mbp:~ ilg$ 


The second project (f4b-lto-test) was a progressive simplification of the first, until it no longer crashed GDB. 

Unfortunately it still did not work, it trew an assert while GDB was trying to start the GDB debug session:


551,953 &"symbol-file /Users/ilg/Desktop/eclipse-workspace-2018-12/f4b-lto-test/Debug/f4b-lto-test.e\
 lf\n"
 551,953 ~"Reading symbols from /Users/ilg/Desktop/eclipse-workspace-2018-12/f4b-lto-test/Debug/f4b-l\
 to-test.elf...\n"
 551,962 30^done
 551,962 (gdb) 
 551,964 &"load /Users/ilg/Desktop/eclipse-workspace-2018-12/f4b-lto-test/Debug/f4b-lto-test.elf\n"
 551,964 ~"Loading section .isr_vector, size 0x3bc lma 0x8000000\n"
 551,966 31+download,{section=".isr_vector",section-size="956",total-size="934014"}
 551,966 31+download,{section=".isr_vector",section-sent="956",section-size="956",total-sent="956",to\
 tal-size="934014"}
 551,966 ~"Loading section .inits, size 0x28 lma 0x80003bc\n"
 551,968 31+download,{section=".inits",section-size="40",total-size="934014"}
 551,968 ~"Loading section .text, size 0xcf3 lma 0x80003f0\n"
 551,968 31+download,{section=".text",section-size="3315",total-size="934014"}
 551,968 ~"Loading section .data, size 0x74 lma 0x80010e4\n"
 551,969 31+download,{section=".data",section-size="116",total-size="934014"}
 551,969 ~"Start address 0x80002a4, load size 4427\n"
 552,406 ~"Transfer rate: 864 KB/sec, 1106 bytes/write.\n"

 552,407 ~"/tmp/jenkins-GCC-8-build-toolchain-mac_cluster-128_20181216_1544945247/src/gdb/gdb/dwarf2r\
 ead.c:9809: internal-error: void dw2_add_symbol_to_list(struct symbol *, struct pending **): Asserti\
 on `(*listhead) == NULL || (SYMBOL_LANGUAGE ((*listhead)->symbol[0]) == SYMBOL_LANGUAGE (symbol))' f\
 ailed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable.\nQuit \
 this debugging session? "
 552,408 ~"(y or n) [answered Y; input not from terminal]\n"
 552,408 &"\nThis is a bug, please report it."
 552,408 &"  For instructions, see:\n<http://www.gnu.org/software/gdb/bugs/>."
 552,408 &"\n\n"
 552,408 ~"/tmp/jenkins-GCC-8-build-toolchain-mac_cluster-128_20181216_1544945247/src/gdb/gdb/dwarf2r\
 ead.c:9809: internal-error: void dw2_add_symbol_to_list(struct symbol *, struct pending **): Asserti\
 on `(*listhead) == NULL || (SYMBOL_LANGUAGE ((*listhead)->symbol[0]) == SYMBOL_LANGUAGE (symbol))' f\
 ailed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable.\nCreat\
 e a core file of GDB? "
 552,409 ~"(y or n) [answered Y; input not from terminal]\n"



In both cases the project was compiled with -Og.

To identify if the problem is in the compiler vs the debugger, I tried to debug the executable created by GCC 8 with the debugger from the GCC 7 distribution and it was ok, so this is the reason why I suspected GDB.
Comment 1 Liviu Ionescu 2019-01-28 14:07:33 UTC
Created attachment 11577 [details]
The project that crashes with segmentation fault
Comment 2 Liviu Ionescu 2019-01-28 14:08:05 UTC
Created attachment 11578 [details]
The project that trows the assert
Comment 3 Liviu Ionescu 2019-01-28 14:09:34 UTC
> The project that trows the assert

throws
Comment 4 Liviu Ionescu 2019-01-28 14:24:47 UTC
For cross reference, this is the original launchpad bug report:

https://bugs.launchpad.net/gcc-arm-embedded/+bug/1813553
Comment 5 Liviu Ionescu 2019-01-29 19:04:18 UTC
One more detail that might help: the problem apparently affects only C++ projects, since I tried a similar C project generated by my Eclipse templates and GDB no longer crashed. 

It looks like GDB gets confused by the C++ debug information generated by the linker LTO code.
Comment 6 Keith Seitz 2019-01-29 20:15:48 UTC
Both reported problems have been fixed. The first reported problem is the NULL builder patch, fixed by the patch for gdb/23773:

commit c24bdb023c8e1fa969d6eb945059fa8ed0d490c7
Author: Keith Seitz <keiths@redhat.com>
Date:   Wed Jan 16 11:38:06 2019 -0800

    Introduce dwarf2_cu::get_builder

The second one, the assertion failure, was fixed by the patch for 23010,
23712, and more:

commit d3cb68081112a4976979df3f8eae7ca926e76519
Author: Keith Seitz <keiths@redhat.com>
Date:   Thu Jan 10 13:57:08 2019 -0800

    gdb/23712: Remove dw2_add_symbol_to_list

I have confirmed that the attached f4b-lto.elf file loads successfully into
gdb built off HEAD:

$ gdb -v
GNU gdb (GDB) 8.2.50.20190116-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ gdb ~/Downloads/f4b-lto/Debug/f4b-lto.elf  -readnow
Reading symbols from /home/keiths/Downloads/f4b-lto/Debug/f4b-lto.elf...
Expanding full symbols from /home/keiths/Downloads/f4b-lto/Debug/f4b-lto.elf...
(gdb)

*** This bug has been marked as a duplicate of bug 23712 ***
Comment 7 Liviu Ionescu 2019-01-29 20:30:16 UTC
Thank you, Keith, for the quick reply.

I'll build a new toolchain and confirm if everything is ok.
Comment 8 Ramana.Radhakrishnan 2019-01-29 22:30:56 UTC
What's the policy with respect to backports of bugs / regression fixes to release branches  ? 

Ramana

-----Original Message-----
From: keiths at redhat dot com <sourceware-bugzilla@sourceware.org> 
Sent: 29 January 2019 14:46
To: ramana@sourceware.org
Subject: [Bug gdb/24145] GDB 8.2 crashes while loading symbols of an LTO application

https://sourceware.org/bugzilla/show_bug.cgi?id=24145

Keith Seitz <keiths at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |keiths at redhat dot com
         Resolution|---                         |DUPLICATE

--- Comment #6 from Keith Seitz <keiths at redhat dot com> --- Both reported problems have been fixed. The first reported problem is the NULL builder patch, fixed by the patch for gdb/23773:

commit c24bdb023c8e1fa969d6eb945059fa8ed0d490c7
Author: Keith Seitz <keiths@redhat.com>
Date:   Wed Jan 16 11:38:06 2019 -0800

    Introduce dwarf2_cu::get_builder

The second one, the assertion failure, was fixed by the patch for 23010, 23712, and more:

commit d3cb68081112a4976979df3f8eae7ca926e76519
Author: Keith Seitz <keiths@redhat.com>
Date:   Thu Jan 10 13:57:08 2019 -0800

    gdb/23712: Remove dw2_add_symbol_to_list

I have confirmed that the attached f4b-lto.elf file loads successfully into gdb built off HEAD:

$ gdb -v
GNU gdb (GDB) 8.2.50.20190116-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ gdb ~/Downloads/f4b-lto/Debug/f4b-lto.elf  -readnow Reading symbols from /home/keiths/Downloads/f4b-lto/Debug/f4b-lto.elf...
Expanding full symbols from /home/keiths/Downloads/f4b-lto/Debug/f4b-lto.elf...
(gdb)

*** This bug has been marked as a duplicate of bug 23712 ***

--
You are receiving this mail because:
You are on the CC list for the bug.
Comment 9 Liviu Ionescu 2019-01-30 08:16:06 UTC
I confirm that with the latest commit from 20190129 I can debug my test projects. So far, so good.

Thank you again, Keith!