diff mbox series

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

Message ID 20200420110846.218792-5-maennich@google.com
State Superseded
Headers show
Series Refactor dwarf-reader: split out ELF helpers | expand

Commit Message

Matthias Maennich April 20, 2020, 11:08 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.cc(binary_is_linux_kernel): Add declaration.
	(binary_is_linux_kernel_module): Likewise.
	(find_ksymtab_strings_section): Likewise.

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

Giuliano Procida April 20, 2020, 2:32 p.m. UTC | #1
On Mon, 20 Apr 2020 at 12:09, Matthias Maennich <maennich@google.com> wrote:
>
> 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.

Next one should be .h.

>         * abg-elf-helpers.cc(binary_is_linux_kernel): Add declaration.
>         (binary_is_linux_kernel_module): Likewise.
>         (find_ksymtab_strings_section): Likewise.
>
> 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(-)
>
> 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
>
> --
> 2.26.1.301.g55bc3eb7cb9-goog
>
Giuliano Procida April 20, 2020, 3:30 p.m. UTC | #2
Hi.

On Mon, 20 Apr 2020 at 15:32, Giuliano Procida <gprocida@google.com> wrote:
>
> On Mon, 20 Apr 2020 at 12:09, Matthias Maennich <maennich@google.com> wrote:
> >
> > 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.
>
> Next one should be .h.

But otherwise,
Reviewed-by: Giuliano Procida <gprocida@google.com>

> >         * abg-elf-helpers.cc(binary_is_linux_kernel): Add declaration.
> >         (binary_is_linux_kernel_module): Likewise.
> >         (find_ksymtab_strings_section): Likewise.
> >
> > 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(-)
> >
> > 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
> >
> > --
> > 2.26.1.301.g55bc3eb7cb9-goog
> >
diff mbox series

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