From 4fba6bea177ffa1981b8252f7f1967814b3ecf94 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 23 Sep 2019 15:55:08 +0200 Subject: [PATCH] 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 --- src/abg-dwarf-reader.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index dbac01b6..1e6d8012 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -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;