public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdwfl: Calculate addr to read by hand in link_map.c read_addrs.
@ 2021-12-24  1:06 Mark Wielaard
  2022-01-03 23:40 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2021-12-24  1:06 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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  |  4 ++++
 libdwfl/link_map.c | 11 +++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 73d8613c..149383ad 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
+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
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index f57c5585..cd9c5042 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -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;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libdwfl: Calculate addr to read by hand in link_map.c read_addrs.
  2021-12-24  1:06 [PATCH] libdwfl: Calculate addr to read by hand in link_map.c read_addrs Mark Wielaard
@ 2022-01-03 23:40 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2022-01-03 23:40 UTC (permalink / raw)
  To: elfutils-devel

On Fri, Dec 24, 2021 at 02:06:08AM +0100, Mark Wielaard wrote:
> 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

Pushed

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-03 23:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24  1:06 [PATCH] libdwfl: Calculate addr to read by hand in link_map.c read_addrs Mark Wielaard
2022-01-03 23:40 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).