]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Use signedness of subrange type to determine array bounds
authorMark Wielaard <mark@klomp.org>
Wed, 6 Oct 2021 20:41:29 +0000 (22:41 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 18 Oct 2021 11:37:08 +0000 (13:37 +0200)
When calculating the array size check if the subrange has an associate
type, if it does then check the type to determine whether the upper
and lower values need to be interpreted as signed of unsigned
values. We default to signed because that is what the testcase
run-aggregate-size.sh testfile-size4 expects (this is an hardwritten
testcase, we could have chosen a different default).

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

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

index b707bbfe63b7e659f57622c050a3befa5cd24dca..4275b830f5ab856e23bd47bb74714f4f867d2e3b 100644 (file)
@@ -1,3 +1,9 @@
+2021-10-06  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_aggregate_size.c (array_size): Check signedness of child DIE
+       type. Use dwarf_formsdata or dwarf_formudata to get the lower and
+       upper bounds.
+
 2021-09-08  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_begin_elf.c (valid_p): Identify ELF class and use this to set
index 75105e4d1fcc8de455749554997f1c4ff6668af9..96023d69db10fc6ff99de9f3bd3e45ba4979ce29 100644 (file)
@@ -83,19 +83,51 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
            }
          else
            {
+             bool is_signed = true;
+             if (INTUSE(dwarf_attr) (get_type (&child, attr_mem, &type_mem),
+                                     DW_AT_encoding, attr_mem) != NULL)
+               {
+                 Dwarf_Word encoding;
+                 if (INTUSE(dwarf_formudata) (attr_mem, &encoding) == 0)
+                   is_signed = (encoding == DW_ATE_signed
+                                || encoding == DW_ATE_signed_char);
+               }
+
              Dwarf_Sword upper;
              Dwarf_Sword lower;
-             if (INTUSE(dwarf_formsdata) (INTUSE(dwarf_attr_integrate)
-                                          (&child, DW_AT_upper_bound,
-                                           attr_mem), &upper) != 0)
-               return -1;
+             if (is_signed)
+               {
+                 if (INTUSE(dwarf_formsdata) (INTUSE(dwarf_attr_integrate)
+                                              (&child, DW_AT_upper_bound,
+                                               attr_mem), &upper) != 0)
+                   return -1;
+               }
+             else
+               {
+                 Dwarf_Word unsigned_upper;
+                 if (INTUSE(dwarf_formudata) (INTUSE(dwarf_attr_integrate)
+                                              (&child, DW_AT_upper_bound,
+                                               attr_mem), &unsigned_upper) != 0)
+                   return -1;
+                 upper = unsigned_upper;
+               }
 
              /* Having DW_AT_lower_bound is optional.  */
              if (INTUSE(dwarf_attr_integrate) (&child, DW_AT_lower_bound,
                                                attr_mem) != NULL)
                {
-                 if (INTUSE(dwarf_formsdata) (attr_mem, &lower) != 0)
-                   return -1;
+                 if (is_signed)
+                   {
+                     if (INTUSE(dwarf_formsdata) (attr_mem, &lower) != 0)
+                       return -1;
+                   }
+                 else
+                   {
+                     Dwarf_Word unsigned_lower;
+                     if (INTUSE(dwarf_formudata) (attr_mem, &unsigned_lower) != 0)
+                       return -1;
+                     lower = unsigned_lower;
+                   }
                }
              else
                {