Blame SOURCES/elfutils-0.170-dwarf_aggregate_size.patch

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