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