Fix reading of relocation sections when endianness mismatches

When the endianness of the ELF binary differs from the endianness of
the host, some byte swapping needs to happen when we read the reloc
section to either determine the format of the kernel symbol table or
to get the set of symbols referenced by the kernel symbol table.

So we need to use elf_getdata rather than elf_rawdata to read the data
from the reloc section, because the former handles the proper byte
swapping for us.

This patch does just that and thus fixes the build breakage that is
occuring when running the testreaddwarf test on s390x (big endian),
especially when trying to read the AARCH64 little endian binary
data/test-read-dwarf/PR25007-sdhci.ko.

	* src/abg-dwarf-reader.cc
	(read_context::{get_ksymtab_format_module,
	populate_symbol_map_from_ksymtab_reloc}): Use elf_getdata rather
	than elf_rawdata.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2019-09-23 15:55:08 +02:00
parent 583bc40deb
commit 4fba6bea17

View File

@ -7676,8 +7676,8 @@ public:
// what format the ksymtab is in depending on what types of relocs it
// contains.
int type;
Elf_Data *section_data = elf_rawdata(section, 0);
uint64_t type;
Elf_Data *section_data = elf_getdata(section, 0);
if (is_relasec)
{
GElf_Rela rela;
@ -7977,7 +7977,7 @@ public:
size_t reloc_count =
reloc_section_shdr->sh_size / reloc_section_shdr->sh_entsize;
Elf_Data *reloc_section_data = elf_rawdata(reloc_section, 0);
Elf_Data *reloc_section_data = elf_getdata(reloc_section, 0);
bool is_relasec = (reloc_section_shdr->sh_type == SHT_RELA);
elf_symbol_sptr symbol;