abg-dwarf-reader: resolve relocation sections by index
authorMatthias Maennich <maennich@google.com>
Mon, 11 Nov 2019 21:48:10 +0000 (21:48 +0000)
committerMatthias Maennich <maennich@google.com>
Tue, 7 Jan 2020 09:21:30 +0000 (09:21 +0000)
commit189b318caec975875fec13bc03c718773cf34890
tree91c9ff930e0a17989d082066faaf65320b03ca9a
parent777ffc12811ab9ab2c796cb1785cd67836cb944e
abg-dwarf-reader: resolve relocation sections by index

Looking up relocation sections by name introduces a dependency to the
linker in use. Relocation sections might be named differently. For
instance, linking kernel modules with the bfd linker leads to a
.rela__ksymtab section corresponding to the __ksymtab section. Using lld
as a linker leads to .rela___ksymtab as section name. Both are valid.
When the kernel loads these, it simply applies all relocations from all
sections it finds. Tools should not depend on the concrete name (even
though I would prefer consistency among them). Libabigail hit an
assertion when trying to extract the ABI from a kernel module linked
with lld.

Hence, resolve the relocation sections for __ksymtab and __ksymtab_gpl
by iterating over the ELF sections, searching for relocation sections
and identifying the one that points to the respective ksymtab.

* src/abg-dwarf-reader.cc (find_relocation_section): New function.
(find_ksymtab_reloc_section): Use find_relocation_section to
resolve the ksymtab's relocation section.
(find_ksymtab_gpl_reloc_section): Likewise.

Fixes: e6870326e01a ("Support pre and post v4.19 ksymtabs for Linux kernel modules")
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Android Kernel Team <kernel-team@android.com>
Reviewed-by: Dodji Seketeli <dodji@seketeli.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
src/abg-dwarf-reader.cc