[PATCH 1/2] elf_helpers: new utility function find_strtab_for_symtab_section
Jose E. Marchesi
jose.marchesi@oracle.com
Wed Nov 10 12:50:49 GMT 2021
This patch adds a new utility function that, given a section
containing a symbol table, returns the corresponding string table
section.
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
* src/abg-elf-helpers.h: Prototype for find_strtab_for_symtab_section.
* src/abg-elf-helpers.cc (find_strtab_for_symtab_section): New function.
---
src/abg-elf-helpers.cc | 23 +++++++++++++++++++++++
src/abg-elf-helpers.h | 4 ++++
2 files changed, 27 insertions(+)
diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc
index 998675a6..ee631831 100644
--- a/src/abg-elf-helpers.cc
+++ b/src/abg-elf-helpers.cc
@@ -649,6 +649,29 @@ find_relocation_section(Elf* elf_handle, Elf_Scn* target_section)
return NULL;
}
+/// Return the string table used by the given symbol table.
+///
+/// @param elf_handle the elf handle to use.
+///
+/// @param symtab_section section containing a symbol table.
+///
+/// @return the string table linked by the symtab, if it is not NULL.
+Elf_Scn*
+find_strtab_for_symtab_section(Elf* elf_handle, Elf_Scn* symtab_section)
+{
+ Elf_Scn *strtab_section = NULL;
+
+ if (symtab_section)
+ {
+ GElf_Shdr symtab_shdr_mem, *symtab_shdr;
+
+ symtab_shdr = gelf_getshdr(symtab_section, &symtab_shdr_mem);
+ strtab_section = elf_getscn(elf_handle, symtab_shdr->sh_link);
+ }
+
+ return strtab_section;
+}
+
/// Get the version definition (from the SHT_GNU_verdef section) of a
/// given symbol represented by a pointer to GElf_Versym.
///
diff --git a/src/abg-elf-helpers.h b/src/abg-elf-helpers.h
index 59ea0a74..718ce9c1 100644
--- a/src/abg-elf-helpers.h
+++ b/src/abg-elf-helpers.h
@@ -112,6 +112,10 @@ find_ksymtab_strings_section(Elf *elf_handle);
Elf_Scn*
find_relocation_section(Elf* elf_handle, Elf_Scn* target_section);
+Elf_Scn*
+find_strtab_for_symtab_section(Elf* elf_handle,
+ Elf_Scn* symtab_section);
+
//
// Helpers for symbol versioning
//
--
2.11.0
More information about the Libabigail
mailing list