[v2,4/8] abg-elf-helpers: move some kernel helpers from abg-dwarf-reader

Message ID 20200421063551.222511-5-maennich@google.com
State Committed
Headers
Series Refactor dwarf-reader: split out ELF helpers |

Commit Message

Matthias Männich April 21, 2020, 6:35 a.m. UTC
  Move some definitions from abg-dwarf-reader to abg-elf-helpers that are
strictly only related to ELF.

        * abg-dwarf-reader.cc(binary_is_linux_kernel): Move function out.
	(binary_is_linux_kernel_module): Likewise.
	(find_ksymtab_strings_section): Likewise.
        * abg-elf-helpers.cc(binary_is_linux_kernel): Move function in.
	(binary_is_linux_kernel_module): Likewise.
	(find_ksymtab_strings_section): Likewise.
        * abg-elf-helpers.h(binary_is_linux_kernel): Add declaration.
	(binary_is_linux_kernel_module): Likewise.
	(find_ksymtab_strings_section): Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-dwarf-reader.cc | 46 -----------------------------------------
 src/abg-elf-helpers.cc  | 45 ++++++++++++++++++++++++++++++++++++++++
 src/abg-elf-helpers.h   | 14 +++++++++++++
 3 files changed, 59 insertions(+), 46 deletions(-)
  

Comments

Dodji Seketeli April 22, 2020, 9:47 a.m. UTC | #1
Matthias Maennich <maennich@google.com> a ?crit:

> Move some definitions from abg-dwarf-reader to abg-elf-helpers that are
> strictly only related to ELF.
>
>         * abg-dwarf-reader.cc(binary_is_linux_kernel): Move function out.
> 	(binary_is_linux_kernel_module): Likewise.
> 	(find_ksymtab_strings_section): Likewise.
>         * abg-elf-helpers.cc(binary_is_linux_kernel): Move function in.
> 	(binary_is_linux_kernel_module): Likewise.
> 	(find_ksymtab_strings_section): Likewise.
>         * abg-elf-helpers.h(binary_is_linux_kernel): Add declaration.
> 	(binary_is_linux_kernel_module): Likewise.
> 	(find_ksymtab_strings_section): Likewise.

Likewise, re-indenting this and inserting a white space between the file
name and the changed interface name.

Applying to master.  Thanks!

Cheers,
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 303c1f8df4c2..3adb978b784b 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -542,52 +542,6 @@  compare_dies(const read_context& ctxt,
 	     bool update_canonical_dies_on_the_fly);
 
 
-/// Test if the ELF binary denoted by a given ELF handle is a Linux
-/// Kernel Module.
-///
-/// @param elf_handle the ELF handle to consider.
-///
-/// @return true iff the binary denoted by @p elf_handle is a Linux
-/// kernel module.
-static bool
-binary_is_linux_kernel_module(Elf *elf_handle)
-{
-  return (find_section(elf_handle, ".modinfo", SHT_PROGBITS)
-	  && find_section(elf_handle,
-			  ".gnu.linkonce.this_module",
-			  SHT_PROGBITS));
-}
-
-/// Test if the ELF binary denoted by a given ELF handle is a Linux
-/// Kernel binary (either vmlinux or a kernel module).
-///
-/// @param elf_handle the ELF handle to consider.
-///
-/// @return true iff the binary denoted by @p elf_handle is a Linux
-/// kernel binary
-static bool
-binary_is_linux_kernel(Elf *elf_handle)
-{
-  return (find_section(elf_handle,
-		       "__ksymtab_strings",
-		       SHT_PROGBITS)
-	  || binary_is_linux_kernel_module(elf_handle));
-}
-
-/// Find the __ksymtab_strings section of a Linux kernel binary.
-///
-///
-/// @return the find_ksymtab_strings_section of the linux kernel
-/// binary denoted by @p elf_handle, or nil if such a section could
-/// not be found.
-static Elf_Scn*
-find_ksymtab_strings_section(Elf *elf_handle)
-{
-  if (binary_is_linux_kernel(elf_handle))
-    return find_section(elf_handle, "__ksymtab_strings", SHT_PROGBITS);
-  return 0;
-}
-
 /// Get the address at which a given binary is loaded in memory?
 ///
 /// @param elf_handle the elf handle for the binary to consider.
diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc
index b7b868a332ec..ff0941dc6536 100644
--- a/src/abg-elf-helpers.cc
+++ b/src/abg-elf-helpers.cc
@@ -548,6 +548,21 @@  get_symbol_versionning_sections(Elf*		elf_handle,
   return false;
 }
 
+/// Find the __ksymtab_strings section of a Linux kernel binary.
+///
+/// @param elf_handle the elf handle to use.
+///
+/// @return the find_ksymtab_strings_section of the linux kernel
+/// binary denoted by @p elf_handle, or nil if such a section could
+/// not be found.
+Elf_Scn*
+find_ksymtab_strings_section(Elf *elf_handle)
+{
+  if (binary_is_linux_kernel(elf_handle))
+    return find_section(elf_handle, "__ksymtab_strings", SHT_PROGBITS);
+  return 0;
+}
+
 /// Get the version definition (from the SHT_GNU_verdef section) of a
 /// given symbol represented by a pointer to GElf_Versym.
 ///
@@ -750,7 +765,37 @@  get_version_for_symbol(Elf*			elf_handle,
   return false;
 }
 
+/// Test if the ELF binary denoted by a given ELF handle is a Linux
+/// Kernel Module.
+///
+/// @param elf_handle the ELF handle to consider.
+///
+/// @return true iff the binary denoted by @p elf_handle is a Linux
+/// kernel module.
+bool
+binary_is_linux_kernel_module(Elf *elf_handle)
+{
+  return (find_section(elf_handle, ".modinfo", SHT_PROGBITS)
+	  && find_section(elf_handle,
+			  ".gnu.linkonce.this_module",
+			  SHT_PROGBITS));
+}
 
+/// Test if the ELF binary denoted by a given ELF handle is a Linux
+/// Kernel binary (either vmlinux or a kernel module).
+///
+/// @param elf_handle the ELF handle to consider.
+///
+/// @return true iff the binary denoted by @p elf_handle is a Linux
+/// kernel binary
+bool
+binary_is_linux_kernel(Elf *elf_handle)
+{
+  return (find_section(elf_handle,
+		       "__ksymtab_strings",
+		       SHT_PROGBITS)
+	  || binary_is_linux_kernel_module(elf_handle));
+}
 
 } // end namespace elf_helpers
 } // end namespace abigail
diff --git a/src/abg-elf-helpers.h b/src/abg-elf-helpers.h
index 7e1c231ccc4e..33348126028c 100644
--- a/src/abg-elf-helpers.h
+++ b/src/abg-elf-helpers.h
@@ -102,6 +102,9 @@  get_symbol_versionning_sections(Elf*		elf_handle,
 				Elf_Scn*&	verdef_section,
 				Elf_Scn*&	verneed_section);
 
+Elf_Scn*
+find_ksymtab_strings_section(Elf *elf_handle);
+
 //
 // Helpers for symbol versioning
 //
@@ -124,6 +127,17 @@  get_version_for_symbol(Elf*			elf_handle,
 		       bool			get_def_version,
 		       elf_symbol::version&	version);
 
+//
+// Helpers for Linux Kernel Binaries
+//
+
+bool
+binary_is_linux_kernel_module(Elf *elf_handle);
+
+bool
+binary_is_linux_kernel(Elf *elf_handle);
+
+
 } // end namespace elf_helpers
 } // end namespace abigail