]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix crash when loading dwp files
authorJordan Rupprecht <rupprecht@google.com>
Mon, 25 Feb 2019 20:21:01 +0000 (12:21 -0800)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 25 Feb 2019 20:51:39 +0000 (15:51 -0500)
commit0a0f4c0179106ee4b8e56649c549f4175ebba994
tree2abb9f2013dd7d69b0f1c4c289fc9412d0718678
parentcd5a152cebb201e98f3dbeca510aa39e838a1f62
Fix crash when loading dwp files

When loading dwp files, we create an array of ELF sections indexed by the ELF
section index in the dwp file. The size of this array is calculated by
section_count, as returned by bfd_count_sections, plus 1 (to account for the
null section at index 0). However, when loading the bfd file, strtab/symtab
sections are not added to the list, nor do they increment section_count, so
section_count is actually smaller than the number of ELF sections.

This happens to work when using GNU dwp, which lays out .debug section first,
with sections like .shstrtab coming at the end. Other tools, like llvm-dwp, put
.strtab first, and gdb crashes when loading those dwp files.

For instance, with the current state of gdb, loading a file like this:
$ readelf -SW <file.dwp>
[ 0] <empty>
[ 1] .debug_foo PROGBITS ...
[ 2] .strtab    STRTAB ...

... results in section_count = 2 (.debug is the only thing placed into
bfd->sections, so section_count + 1 == 2), and sectp->this_idx = 1 when mapping
over .debug_foo in dwarf2_locate_common_dwp_sections, which passes the
assertion that 1 < 2.

However, using a dwp file produced by llvm-dwp:
$ readelf -SW <file.dwp>
[ 0] <empty>
[ 1] .strtab    STRTAB ...
[ 2] .debug_foo PROGBITS ...

... results in section_count = 2 (.debug is the only thing placed into
bfd->sections, so section_count + 1 == 2), and sectp->this_idx = 2 when mapping
over .debug_foo in dwarf2_locate_common_dwp_sections, which fails the assertion
that 2 < 2.

The assertion hit is:

gdb/dwarf2read.c:13009: internal-error: void dwarf2_locate_common_dwp_sections(bfd*, asection*, void*): Assertion `elf_section_nr < dwp_file->num_sections' failed.

This patch changes the calculation of section_count to use elf_numsections,
which should return the actual number of ELF sections.
gdb/ChangeLog
gdb/dwarf2read.c