symtab: fix getting CRC in relocatable modules

Message ID 20230128000818.1605970-1-vvvvvv@google.com
State New
Headers
Series symtab: fix getting CRC in relocatable modules |

Commit Message

Aleksei Vetrov via Libabigail Jan. 28, 2023, 12:08 a.m. UTC
  From: Aleksei Vetrov <vvvvvv@google.com>

In ELF with ET_REL type symbol value holds not absolute but relative to
section value. This patch applies adjustment to the address, used in CRC
value extraction.

	* src/abg-elf-helpers.cc (get_crc_for_symbol): Rename
	crc_symbol_value to crc_symbol_address and adjust it for
	relocatable ELF types.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
---
 src/abg-elf-helpers.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Comments

Dodji Seketeli Jan. 31, 2023, 10:09 a.m. UTC | #1
Hello Aleksei,

Aleksei Vetrov via Libabigail <libabigail@sourceware.org> a écrit:

> From: Aleksei Vetrov <vvvvvv@google.com>
>
> In ELF with ET_REL type symbol value holds not absolute but relative to
> section value. This patch applies adjustment to the address, used in CRC
> value extraction.
>
> 	* src/abg-elf-helpers.cc (get_crc_for_symbol): Rename
> 	crc_symbol_value to crc_symbol_address and adjust it for
> 	relocatable ELF types.
>
> Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>

Applied to mainline, thanks!

[...]

Cheers,
  

Patch

diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc
index 5d8e3188..d61114bf 100644
--- a/src/abg-elf-helpers.cc
+++ b/src/abg-elf-helpers.cc
@@ -920,10 +920,11 @@  bool
 get_crc_for_symbol(Elf* elf_handle, GElf_Sym* crc_symbol, uint32_t& crc_value)
 {
   size_t crc_section_index = crc_symbol->st_shndx;
-  uint64_t crc_symbol_value = crc_symbol->st_value;
+  GElf_Addr crc_symbol_address =
+      maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle, crc_symbol);
   if (crc_section_index == SHN_ABS)
     {
-      crc_value = crc_symbol_value;
+      crc_value = crc_symbol_address;
       return true;
     }
 
@@ -940,10 +941,10 @@  get_crc_for_symbol(Elf* elf_handle, GElf_Sym* crc_symbol, uint32_t& crc_value)
   if (kcrctab_data == NULL)
     return false;
 
-  if (crc_symbol_value < sheader->sh_addr)
+  if (crc_symbol_address < sheader->sh_addr)
     return false;
 
-  size_t offset = crc_symbol_value - sheader->sh_addr;
+  size_t offset = crc_symbol_address - sheader->sh_addr;
   if (offset + sizeof(uint32_t) > kcrctab_data->d_size
       || offset + sizeof(uint32_t) > sheader->sh_size)
     return false;