Fix reading of relocation sections when endianness mismatches
authorDodji Seketeli <dodji@redhat.com>
Mon, 23 Sep 2019 13:55:08 +0000 (15:55 +0200)
committerDodji Seketeli <dodji@redhat.com>
Mon, 23 Sep 2019 13:55:08 +0000 (15:55 +0200)
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>
src/abg-dwarf-reader.cc

index dbac01b65f20c061e9d303ba7ea8aad06d173011..1e6d8012f1d8f35bb77c2d8981b870e84f7df70b 100644 (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;