In the DWARF debug info, a C++ class can be represented by pieces
throughout a given binary.
In this picture, a given virtual member function can be represented
several times; each time in one different piece of the C++ class. In
a given piece of the class, a virtual member function can be
represented with its ELF symbol set. In another one, the same virtual
member function can be represented without that ELF symbol set. And
there can also be pieces of the class that don't have a given virtual
function.
To handle this, the DWARF reader constructs one class from all its
pieces scattered around. It adds each virtual member function to the
class as it comes across them while scanning the DWARF.
Then there is a pass at the end of the process that sets ELF symbols
to the (virtual) member functions that need it.
The problem with that pass is that it sometimes sets the same ELF
symbol to more than one virtual member function. Those virtual member
functions all have the same mangled name that correspond to the ELF
symbol; but only one of them is meant to be associated with the ELF
symbol. In essence, that one is the one that is exported by the ELF
binary.
This patch teaches the pass that sets the ELF symbols of function to
avoid setting the same ELF symbol to more than one function.
The patch also avoids build_function_decl to set symbol to a function
if that symbol was already set to an existing function.
This patch thus fixes a class of issues what arise when comparing a
binary against its own ABIXML representation. Those several functions
having the same ELF symbol would cause spurious changes in that
context.
* src/abg-dwarf-reader.cc
(read_context::symbol_already_belongs_to_a_function): Define new
member function.
(read_context::fixup_functions_with_no_symbols): Use the new
symbol_already_belongs_to_a_function function to avoid setting a
symbol that already belongs to a function.
* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
Likewise.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>