[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] abg-dwarf-reader: stricter checking for kernel modules
In addition to .modinfo, kernel modules reliably have a
.gnu.linkonce.this_module section that can be used in addition to
identify a kernel module. Hence, factor out the section check and use it
to more thoroughly check for kernel modules.
* src/abg-dwarf-reader.cc(has_section): new function
(is_linux_kernel_binary): make use of has_section and be more
strict when identifying kernel modules
Suggested-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
src/abg-dwarf-reader.cc | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index ab3f8e3b2525..5875f7fad21e 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -8343,6 +8343,10 @@ public:
load_in_linux_kernel_mode(bool f)
{options_.load_in_linux_kernel_mode = f;}
+ bool
+ has_section(const char* section) const
+ {return find_section(elf_handle(), section, SHT_PROGBITS);}
+
/// Guess if the current binary is a Linux Kernel or a Linux Kernel module.
///
/// To guess that, the function looks for the presence of the
@@ -8351,8 +8355,9 @@ public:
bool
is_linux_kernel_binary() const
{
- return find_section(elf_handle(), "__ksymtab_strings", SHT_PROGBITS)
- || find_section(elf_handle(), ".modinfo", SHT_PROGBITS);
+ return has_section("__ksymtab_strings") // vmlinux (or kernel modules)
+ || ( has_section(".modinfo") // kernel modules
+ && has_section(".gnu.linkonce.this_module"));
}
/// Getter of the "show_stats" flag.
--
2.22.0.657.g960e92d24f-goog