std::unordered_set<std::string> exported_kernel_symbols;
std::unordered_map<std::string, uint64_t> crc_values;
- const bool is_arm32 = elf_helpers::architecture_is_arm32(elf_handle);
- const bool is_ppc64 = elf_helpers::architecture_is_ppc64(elf_handle);
-
for (size_t i = 0; i < number_syms; ++i)
{
GElf_Sym *sym, sym_mem;
}
else if (symbol_sptr->is_defined())
{
- GElf_Addr symbol_value =
- elf_helpers::maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle,
- sym);
-
- // See also symtab::add_alternative_address_lookups.
- if (symbol_sptr->is_function())
- {
- if (is_arm32)
- // Clear bit zero of ARM32 addresses as per "ELF for the Arm
- // Architecture" section 5.5.3.
- // https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
- symbol_value &= ~1;
- else if (is_ppc64)
- update_function_entry_address_symbol_map(elf_handle, sym,
- symbol_sptr);
- }
-
+ const GElf_Addr symbol_value =
+ get_symbol_value(elf_handle, sym, symbol_sptr);
const auto result =
addr_symbol_map_.emplace(symbol_value, symbol_sptr);
if (!result.second)
addr_symbol_map_[addr] = new_main;
}
+/// Various adjustments and bookkeeping may be needed to provide a correct
+/// interpretation (one that matches DWARF addresses) of raw symbol values.
+///
+/// @param elf_handle the ELF handle
+///
+/// @param elf_symbol the ELF symbol
+///
+/// @param symbol_sptr the libabigail symbol
+///
+/// @return a possibly-adjusted symbol value
+GElf_Addr
+symtab::get_symbol_value(Elf* elf_handle,
+ GElf_Sym* elf_symbol,
+ const elf_symbol_sptr& symbol_sptr)
+{
+ const bool is_arm32 = elf_helpers::architecture_is_arm32(elf_handle);
+ const bool is_ppc64 = elf_helpers::architecture_is_ppc64(elf_handle);
+
+ GElf_Addr symbol_value =
+ elf_helpers::maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle,
+ elf_symbol);
+
+ if (symbol_sptr->is_function())
+ {
+ if (is_arm32)
+ // Clear bit zero of ARM32 addresses as per "ELF for the Arm
+ // Architecture" section 5.5.3.
+ // https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
+ symbol_value &= ~1;
+ else if (is_ppc64)
+ update_function_entry_address_symbol_map(elf_handle, elf_symbol,
+ symbol_sptr);
+ }
+
+ return symbol_value;
+}
+
/// Update the function entry symbol map to later allow lookups of this symbol
/// by entry address as well. This is relevant for ppc64 ELFv1 binaries.
///
void
symtab::add_alternative_address_lookups(Elf* elf_handle)
{
- const bool is_arm32 = elf_helpers::architecture_is_arm32(elf_handle);
- const bool is_ppc64 = elf_helpers::architecture_is_ppc64(elf_handle);
-
Elf_Scn* symtab_section = elf_helpers::find_symtab_section(elf_handle);
if (!symtab_section)
return;
if (symbols.size() == 1)
{
const auto& symbol_sptr = symbols[0];
- GElf_Addr symbol_value =
- elf_helpers::maybe_adjust_et_rel_sym_addr_to_abs_addr(
- elf_handle, sym);
-
- // See also symtab::load_.
- if (symbol_sptr->is_function())
- {
- if (is_arm32)
- // Clear bit zero of ARM32 addresses as per "ELF for the Arm
- // Architecture" section 5.5.3.
- // https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
- symbol_value &= ~1;
- else if (is_ppc64)
- update_function_entry_address_symbol_map(elf_handle, sym,
- symbol_sptr);
- }
-
+ const GElf_Addr symbol_value =
+ get_symbol_value(elf_handle, sym, symbol_sptr);
addr_symbol_map_.emplace(symbol_value, symbol_sptr);
}
}