]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/dwarf: sort units when writing index
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Jul 2025 15:35:12 +0000 (11:35 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 1 Aug 2025 04:25:54 +0000 (00:25 -0400)
commitcb208105eb5674fcc0fa2a4999ea0cc4f06bc8c6
tree7d8af3dc06a6ab979edad13d902738dbcce34a00
parent52f0642b075c9f81c63f554203cee84cbc1f5bf8
gdb/dwarf: sort units when writing index

The order of all_units can't be relied on when writing the CU and TU
lists to .gdb_index or .debug_names.

Both the .gdb_index and .debug_names writers expect that all_units
contains comp units followed by type units.  As of this commit, when
reading a DWARF 5 .debug_info, the all_units vector is ordered based on
the order the units appear in .debug_info, where type units can be
interleaved with comp units.

It probably worked fine with DWARF 4, where type units were in a section
of their own (.debug_types).  They were read after comp units, and
therefore after them in the all_units vector.

Change the writers to use a common function that splits the units in two
lists (comp units and type units).  Sort both lists by section offset.
This is more than required, but it should help produce a stable and
predictable output.

Change-Id: I5a22e2e354145e3d6b5b2822dc2a3af2f9d6bb76
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/index-write.c