Blame SOURCES/elfutils-0.170-dwarf_aggregate_size.patch

8632b8
From a2246aaad96e062eb3bab55af9526aaa70adcfd0 Mon Sep 17 00:00:00 2001
8632b8
From: Dima Kogan <dkogan@debian.org>
8632b8
Date: Fri, 8 Dec 2017 01:45:10 -0800
8632b8
Subject: [PATCH 1/2] libdw: dwarf_aggregate_size() works with
8632b8
 multi-dimensional arrays
8632b8
8632b8
If we have a multidimensional array of dimensions (a,b,c) the number of elements
8632b8
should be a*b*c, but prior to this patch dwarf_aggregate_size() would report
8632b8
a+b+c instead.
8632b8
8632b8
This patch fixes the bug and adds a test that demonstrates the bug (the test
8632b8
fails without the functional part of this patch).
8632b8
8632b8
Fixes: https://sourceware.org/bugzilla/show_bug.cgi?id=22546
8632b8
8632b8
Signed-off-by: Dima Kogan <dima@secretsauce.net>
8632b8
---
8632b8
 libdw/ChangeLog              |   5 +++++
8632b8
 libdw/dwarf_aggregate_size.c |  43 ++++++++++++++++++++++---------------------
8632b8
 tests/ChangeLog              |   6 ++++++
8632b8
 tests/run-aggregate-size.sh  |   2 ++
8632b8
 tests/run-peel-type.sh       |   1 +
8632b8
 tests/testfile-sizes3.o.bz2  | Bin 1147 -> 1208 bytes
8632b8
 6 files changed, 36 insertions(+), 21 deletions(-)
8632b8
8632b8
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
8632b8
index 838468d..3010c0a 100644
8632b8
--- a/libdw/dwarf_aggregate_size.c
8632b8
+++ b/libdw/dwarf_aggregate_size.c
8632b8
@@ -63,7 +63,7 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
8632b8
     return -1;
8632b8
 
8632b8
   bool any = false;
8632b8
-  Dwarf_Word total = 0;
8632b8
+  Dwarf_Word count_total = 1;
8632b8
   do
8632b8
     {
8632b8
       Dwarf_Word count;
8632b8
@@ -134,34 +134,35 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
8632b8
 	  continue;
8632b8
 	}
8632b8
 
8632b8
-      /* This is a subrange_type or enumeration_type and we've set COUNT.
8632b8
-	 Now determine the stride for this array dimension.  */
8632b8
-      Dwarf_Word stride = eltsize;
8632b8
-      if (INTUSE(dwarf_attr_integrate) (&child, DW_AT_byte_stride,
8632b8
-					attr_mem) != NULL)
8632b8
-	{
8632b8
-	  if (INTUSE(dwarf_formudata) (attr_mem, &stride) != 0)
8632b8
-	    return -1;
8632b8
-	}
8632b8
-      else if (INTUSE(dwarf_attr_integrate) (&child, DW_AT_bit_stride,
8632b8
-					     attr_mem) != NULL)
8632b8
-	{
8632b8
-	  if (INTUSE(dwarf_formudata) (attr_mem, &stride) != 0)
8632b8
-	    return -1;
8632b8
-	  if (stride % 8) 	/* XXX maybe compute in bits? */
8632b8
-	    return -1;
8632b8
-	  stride /= 8;
8632b8
-	}
8632b8
+      count_total *= count;
8632b8
 
8632b8
       any = true;
8632b8
-      total += stride * count;
8632b8
     }
8632b8
   while (INTUSE(dwarf_siblingof) (&child, &child) == 0);
8632b8
 
8632b8
   if (!any)
8632b8
     return -1;
8632b8
 
8632b8
-  *size = total;
8632b8
+  /* This is a subrange_type or enumeration_type and we've set COUNT.
8632b8
+     Now determine the stride for this array.  */
8632b8
+  Dwarf_Word stride = eltsize;
8632b8
+  if (INTUSE(dwarf_attr_integrate) (die, DW_AT_byte_stride,
8632b8
+                                    attr_mem) != NULL)
8632b8
+    {
8632b8
+      if (INTUSE(dwarf_formudata) (attr_mem, &stride) != 0)
8632b8
+        return -1;
8632b8
+    }
8632b8
+  else if (INTUSE(dwarf_attr_integrate) (die, DW_AT_bit_stride,
8632b8
+                                         attr_mem) != NULL)
8632b8
+    {
8632b8
+      if (INTUSE(dwarf_formudata) (attr_mem, &stride) != 0)
8632b8
+        return -1;
8632b8
+      if (stride % 8) 	/* XXX maybe compute in bits? */
8632b8
+        return -1;
8632b8
+      stride /= 8;
8632b8
+    }
8632b8
+
8632b8
+  *size = count_total * stride;
8632b8
   return 0;
8632b8
 }
8632b8
 
8632b8
diff --git a/tests/run-aggregate-size.sh b/tests/run-aggregate-size.sh
8632b8
index 42b0742..6d8aa24 100755
8632b8
--- a/tests/run-aggregate-size.sh
8632b8
+++ b/tests/run-aggregate-size.sh
8632b8
@@ -54,6 +54,7 @@
8632b8
 # volatile int ia[32];
8632b8
 # const volatile void * const volatile restrict va[64];
8632b8
 # struct s sa[8];
8632b8
+# double d3d[3][4][5];
8632b8
 #
8632b8
 # typedef const int foo;
8632b8
 # typedef volatile foo bar;
8632b8
@@ -98,6 +99,7 @@ ca size 16
8632b8
 ia size 128
8632b8
 va size 512
8632b8
 sa size 128
8632b8
+d3d size 480
8632b8
 f size 4
8632b8
 b size 4
8632b8
 EOF
8632b8
diff --git a/tests/run-peel-type.sh b/tests/run-peel-type.sh
8632b8
index 7fd96e8..668e316 100755
8632b8
--- a/tests/run-peel-type.sh
8632b8
+++ b/tests/run-peel-type.sh
8632b8
@@ -55,6 +55,7 @@ ca raw type array_type
8632b8
 ia raw type array_type
8632b8
 va raw type array_type
8632b8
 sa raw type array_type
8632b8
+d3d raw type array_type
8632b8
 f raw type base_type
8632b8
 b raw type base_type
8632b8
 EOF
8632b8
8632b8
-- 
8632b8
1.8.3.1
8632b8
8632b8
From c25dc62e59dc42378370602b0d05415a42b051d6 Mon Sep 17 00:00:00 2001
8632b8
From: Mark Wielaard <mark@klomp.org>
8632b8
Date: Mon, 11 Dec 2017 23:58:34 +0100
8632b8
Subject: [PATCH 2/2] libdw: dwarf_aggregate_size should not peel the given
8632b8
 DIE.
8632b8
8632b8
Reserve memory for a new DIE first. The caller might not care, but it
8632b8
isn't really nice to change the DIE the caller gave us.
8632b8
8632b8
See also https://sourceware.org/bugzilla/show_bug.cgi?id=22546#c5
8632b8
8632b8
Signed-off-by: Mark Wielaard <mark@klomp.org>
8632b8
---
8632b8
 libdw/ChangeLog              | 5 +++++
8632b8
 libdw/dwarf_aggregate_size.c | 6 +++---
8632b8
 2 files changed, 8 insertions(+), 3 deletions(-)
8632b8
8632b8
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
8632b8
index 3010c0a..6e50185 100644
8632b8
--- a/libdw/dwarf_aggregate_size.c
8632b8
+++ b/libdw/dwarf_aggregate_size.c
8632b8
@@ -199,12 +199,12 @@ aggregate_size (Dwarf_Die *die, Dwarf_Word *size, Dwarf_Die *type_mem)
8632b8
 int
8632b8
 dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size)
8632b8
 {
8632b8
-  Dwarf_Die type_mem;
8632b8
+  Dwarf_Die die_mem, type_mem;
8632b8
 
8632b8
-  if (INTUSE (dwarf_peel_type) (die, die) != 0)
8632b8
+  if (INTUSE (dwarf_peel_type) (die, &die_mem) != 0)
8632b8
     return -1;
8632b8
 
8632b8
-  return aggregate_size (die, size, &type_mem);
8632b8
+  return aggregate_size (&die_mem, size, &type_mem);
8632b8
 }
8632b8
 INTDEF (dwarf_aggregate_size)
8632b8
 OLD_VERSION (dwarf_aggregate_size, ELFUTILS_0.144)
8632b8
-- 
8632b8
1.8.3.1
8632b8