Bug 24431 - ELF reader fails to determine __ksymtab format
This is a fallout from this commit:
ad8c253 Bug 24431 - ELF reader can't interpret ksymtab with Kernel 4.19+
The problem is that the method used to determine if the format of the
__ksymtab section is pre or post v4.19. In that commit, we assumed
that a kernel without relocations for the __ksymtab section implies a
v4.19 format, because in that format, we don't need relocations for
that section. But then it can happen that the entire kernel be built
without relocations, in the case a non relocatable kernels. So just
looking a the presence of relocations is not a good enough
discriminant to determine the format of the __ksymtab section.
This patch rather tries to read the first entry of the __ksymtab
section assuming a pre v4.19 format, comes up with an address, and
then looks the .symtab section up with that address. If the lookup
succeeds and we find a symbol, then we can reasonably assume that the
__ksymtab section is in the v4.19 format. Otherwise, we do the same
assuming a v4.19 format, etc.
Tested on v4.9, v4.16 and v4.16 kernels in 32 and 64 bits.
* src/abg-dwarf-reader.cc
(read_context::{try_reading_first_ksymtab_entry_using_pre_v4_19_format,
try_reading_first_ksymtab_entry_using_v4_19_format}): Define new
member functions.
(read_context::maybe_adjust_sym_address_from_v4_19_ksymtab): Make
member function this const.
(read_context::get_ksymtab_format): Implement the new heuristic
here, using try_reading_first_ksymtab_entry_using_pre_v4_19_format
and try_reading_first_ksymtab_entry_using_v4_19_format, rather
than assuming that if we have no relocations, then we are in the
v4.19 format.
(maybe_adjust_sym_address_from_v4_19_ksymtab): When on a 64 bits
architecture, ensure the 32 bits address read from the v4.19
format __ksymtab section is converted into a 64 bits address.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>