bfd/dwarf: Improve use of previously loaded dwarf information
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 15 Dec 2016 15:22:49 +0000 (15:22 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 16 Feb 2017 13:06:13 +0000 (13:06 +0000)
commit90ed9b8bc136c80116273d1aae5a31fbd415af27
tree057578b7b94660075f4d1cccf9434047d15c7165
parent2bd7f877afeadd6da4c6b1dfc4d0489e9c0efb55
bfd/dwarf: Improve use of previously loaded dwarf information

When parsing DWARF data in order to report file/line type error messages
we perform section placement to make section addresses unique within
relocatable object files.

Currently, if we reuse previously loaded (and cached) dwarf data then we
neglect to perform section placement, the result is that the section
addresses will not be unique, and we might, incorrectly associate an
address with the wrong debug information, and so report an incorrect
file and line number.

Further we neglect to check that that bfd for which we are looking up
debug information is actually the bfd for which the previous debug
information was loaded, it is possible that we will reuse previously
loaded debug information for a different bfd.

And finally, due to following of gnu_debuglink links in one bfd to
another, the process of checking that the cached debug information is
valid requires us to track the original bfd in the cached debug
information.  The original debug information here is either the bfd that
we're interested in, not the bfd we finally load the debug information
from.

bfd/ChangeLog:

* dwarf2.c (struct dwarf2_debug): Add orig_bfd member.
(_bfd_dwarf2_slurp_debug_info): If stashed debug information does
not match current bfd, then reload debug information.  Record bfd
we're loading debug info for in the stash.  If we have debug
informatin in the cache then perform section placement before
returning.

ld/ChangeLog:

* testsuite/ld-elf/dwarf.exp (build_tests): Add new tests.
* testsuite/ld-elf/dwarf2.err: New file.
* testsuite/ld-elf/dwarf2a.c: New file.
* testsuite/ld-elf/dwarf2b.c: New file.
* testsuite/ld-elf/dwarf3.c: New file.
* testsuite/ld-elf/dwarf3.err: New file.
bfd/ChangeLog
bfd/dwarf2.c
ld/ChangeLog
ld/testsuite/ld-elf/dwarf.exp
ld/testsuite/ld-elf/dwarf2.err [new file with mode: 0644]
ld/testsuite/ld-elf/dwarf2a.c [new file with mode: 0644]
ld/testsuite/ld-elf/dwarf2b.c [new file with mode: 0644]
ld/testsuite/ld-elf/dwarf3.c [new file with mode: 0644]
ld/testsuite/ld-elf/dwarf3.err [new file with mode: 0644]