]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf, libdw: blocks aren't expressions for DWARF version 4
authorMark Wielaard <mark@klomp.org>
Fri, 12 Feb 2021 15:28:50 +0000 (16:28 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 17 Feb 2021 15:52:57 +0000 (16:52 +0100)
For DWARF version 4 or higher a block form really encodes a block,
not an expression location. Also constant offsets can be expressed
as DW_FORM_implicit_const in DWARF version 5.

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

index b8038f0021a5d8c85159c90d518830825dfbadf7..f01bee392ab0023cda1fb09d53eeca0a463763ba 100644 (file)
@@ -1,3 +1,9 @@
+2021-02-12  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_getlocation.c (attr_ok): For DWARF version 4 or higher
+       block forms are not expression locations.
+       (is_constant_offset): DW_FORM_implicit_const is also a constant.
+
 2020-12-20  Dmitry V. Levin  <ldv@altlinux.org>
 
        * .gitignore: New file.
index 4e582db201f7d449d9e2fb91fb37f254d385ffdf..5db3cf97e235e51dffb06df0fa649a1ee4d268a4 100644 (file)
@@ -48,6 +48,22 @@ attr_ok (Dwarf_Attribute *attr)
   if (dwarf_whatform (attr) == DW_FORM_exprloc)
     return true;
 
+  if (attr->cu->version >= 4)
+    {
+      /* Must be an exprloc (or constant), just not any block form.  */
+      switch (dwarf_whatform (attr))
+       {
+       case DW_FORM_block:
+       case DW_FORM_block1:
+       case DW_FORM_block2:
+       case DW_FORM_block4:
+         __libdw_seterrno (DWARF_E_NO_LOC_VALUE);
+         return false;
+       default:
+         break;
+       }
+    }
+
   /* Otherwise must be one of the attributes listed below.  Older
      DWARF versions might have encoded the exprloc as block, and we
      cannot easily distinguish attributes in the loclist class because
@@ -186,6 +202,7 @@ is_constant_offset (Dwarf_Attribute *attr,
     case DW_FORM_data8:
     case DW_FORM_sdata:
     case DW_FORM_udata:
+    case DW_FORM_implicit_const:
       break;
     }
 
index e65620fdaf4f8715e1bea60c569fa33da6605393..61cd98f46bc7076b03c694dfb89b60845dd40fdc 100644 (file)
@@ -1,3 +1,8 @@
+2021-02-12  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (attr_callback): Don't handle blocks as expression
+       blocks for DWARF version 4 or higher.
+
 2021-02-03 Timm Bäder <tbaeder@redhat.com>
 
        * ar.c (do_oper_extract): Extract should_truncate_fname function
index 11692bb5bba539bb9ffb11b42dc8fa1bd912d444..9d2a25a44cea243de0a43c9ca55ca6aa45e8c581 100644 (file)
@@ -7599,7 +7599,9 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
        case DW_AT_GNU_call_site_data_value:
        case DW_AT_GNU_call_site_target:
        case DW_AT_GNU_call_site_target_clobbered:
-         if (form != DW_FORM_data16)
+         if (form == DW_FORM_exprloc
+             || (form != DW_FORM_data16
+                 && attrp->cu->version < 4)) /* blocks were expressions.  */
            {
              putchar ('\n');
              print_ops (cbargs->dwflmod, cbargs->dbg,