libdwfl: Calculate addr to read by hand in link_map.c read_addrs.
authorMark Wielaard <mark@klomp.org>
Fri, 24 Dec 2021 01:01:32 +0000 (02:01 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 3 Jan 2022 23:36:52 +0000 (00:36 +0100)
The gcc undefined sanitizer doesn't like the trick we use to calculate
the (possibly) unaligned addresses to read. So calculate them by hand
as unsigned char pointers.

https://sourceware.org/bugzilla/show_bug.cgi?id=28720

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/link_map.c

index 73d8613..149383a 100644 (file)
@@ -1,5 +1,9 @@
 2021-12-23  Mark Wielaard  <mark@klomp.org>
 
+       * link_map.c (read_addrs): Calculate addr to read by hand.
+
+2021-12-23  Mark Wielaard  <mark@klomp.org>
+
        * link_map.c (dwfl_link_map_report): Call memcpy and set in.d_buf to
        out.d_buf before calling xlatetom for unaligned buffers.
 
index f57c558..cd9c504 100644 (file)
@@ -270,26 +270,25 @@ read_addrs (struct memory_closure *closure,
        return true;
     }
 
-  Elf32_Addr (*a32)[n] = vaddr - (*read_vaddr) + (*buffer);
-  Elf64_Addr (*a64)[n] = (void *) a32;
+  unsigned char *addr = vaddr - (*read_vaddr) + (*buffer);
 
   if (elfclass == ELFCLASS32)
     {
       if (elfdata == ELFDATA2MSB)
        for (size_t i = 0; i < n; ++i)
-         addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+         addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (addr + i * 4));
       else
        for (size_t i = 0; i < n; ++i)
-         addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+         addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (addr + i * 4));
     }
   else
     {
       if (elfdata == ELFDATA2MSB)
        for (size_t i = 0; i < n; ++i)
-         addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+         addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (addr + i * 8));
       else
        for (size_t i = 0; i < n; ++i)
-         addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+         addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (addr + i * 8));
     }
 
   return false;