public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdw: Handle DW_FORM_[ref|strp]_sup[48] as DW_FORM_GNU_[ref|strp]_alt.
Date: Tue, 08 May 2018 13:42:00 -0000	[thread overview]
Message-ID: <1525786968-5504-1-git-send-email-mark@klomp.org> (raw)

Although we don't yet handle DWARF5 supplemental files, they are like
mostly like GNU alt files.  This way using any of the supplemental files
will at least generate an appropriate error message.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog           |  9 +++++++++
 libdw/dwarf_formref.c     |  2 ++
 libdw/dwarf_formref_die.c | 15 +++++++++++----
 libdw/dwarf_formstring.c  |  6 ++++--
 src/ChangeLog             |  5 +++++
 src/readelf.c             |  2 ++
 6 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index cc7eae9..5e2c0d8 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,12 @@
+2018-05-08  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf_formref.c (__libdw_formref): Explicitly don't handle
+	DW_FORM_ref_sup4 and DW_FORM_ref_sup8.
+	* dwarf_formref_die.c (dwarf_formref_die): Handle DW_FORM_ref_sup4
+	and DW_FORM_ref_sup8.
+	* dwarf_formstring.c (dwarf_formstring): Handle DW_FORM_strp_sup
+	as DW_FORM_GNU_strp_alt.
+
 2018-05-05  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf.h: Add DWARF line content descriptions.
diff --git a/libdw/dwarf_formref.c b/libdw/dwarf_formref.c
index 2240a25..2bae2a4 100644
--- a/libdw/dwarf_formref.c
+++ b/libdw/dwarf_formref.c
@@ -86,6 +86,8 @@ __libdw_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset)
     case DW_FORM_ref_addr:
     case DW_FORM_ref_sig8:
     case DW_FORM_GNU_ref_alt:
+    case DW_FORM_ref_sup4:
+    case DW_FORM_ref_sup8:
       /* These aren't handled by dwarf_formref, only by dwarf_formref_die.  */
       __libdw_seterrno (DWARF_E_INVALID_REFERENCE);
       return -1;
diff --git a/libdw/dwarf_formref_die.c b/libdw/dwarf_formref_die.c
index d47fb2f..f196331 100644
--- a/libdw/dwarf_formref_die.c
+++ b/libdw/dwarf_formref_die.c
@@ -44,13 +44,20 @@ dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *result)
   struct Dwarf_CU *cu = attr->cu;
 
   Dwarf_Off offset;
-  if (attr->form == DW_FORM_ref_addr || attr->form == DW_FORM_GNU_ref_alt)
+  if (attr->form == DW_FORM_ref_addr || attr->form == DW_FORM_GNU_ref_alt
+      || attr->form == DW_FORM_ref_sup4 || attr->form == DW_FORM_ref_sup8)
     {
       /* This has an absolute offset.  */
 
-      uint8_t ref_size = (cu->version == 2 && attr->form == DW_FORM_ref_addr
-			  ? cu->address_size
-			  : cu->offset_size);
+      uint8_t ref_size;
+      if (cu->version == 2 && attr->form == DW_FORM_ref_addr)
+	ref_size = cu->address_size;
+      else if (attr->form == DW_FORM_ref_sup4)
+	ref_size = 4;
+      else if (attr->form == DW_FORM_ref_sup8)
+	ref_size = 8;
+      else
+	ref_size = cu->offset_size;
 
       Dwarf *dbg_ret = (attr->form == DW_FORM_GNU_ref_alt
 			? INTUSE(dwarf_getalt) (cu->dbg) : cu->dbg);
diff --git a/libdw/dwarf_formstring.c b/libdw/dwarf_formstring.c
index e7396a7..c55c7f0 100644
--- a/libdw/dwarf_formstring.c
+++ b/libdw/dwarf_formstring.c
@@ -48,7 +48,8 @@ dwarf_formstring (Dwarf_Attribute *attrp)
 
   Dwarf_CU *cu = attrp->cu;
   Dwarf *dbg = cu->dbg;
-  Dwarf *dbg_ret = (attrp->form == DW_FORM_GNU_strp_alt
+  Dwarf *dbg_ret = ((attrp->form == DW_FORM_GNU_strp_alt
+		     || attrp->form == DW_FORM_strp_sup)
 		    ? INTUSE(dwarf_getalt) (dbg) : dbg);
 
   if (unlikely (dbg_ret == NULL))
@@ -70,7 +71,8 @@ dwarf_formstring (Dwarf_Attribute *attrp)
 
   uint64_t off;
   if (attrp->form == DW_FORM_strp
-      || attrp->form == DW_FORM_GNU_strp_alt)
+      || attrp->form == DW_FORM_GNU_strp_alt
+      || attrp->form == DW_FORM_strp_sup)
     {
       if (__libdw_read_offset (dbg, dbg_ret, cu_sec_idx (cu),
 			       attrp->valp, cu->offset_size, &off,
diff --git a/src/ChangeLog b/src/ChangeLog
index 4b55bbc..b1041a8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-05  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (attr_callback): Handle DW_FORM_ref_sup4 and
+	DW_FORM_ref_sup8 as references.
+
 2018-04-24  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (print_debug_str_section): Take raw section data. Don't
diff --git a/src/readelf.c b/src/readelf.c
index c2fcfff..c69910a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6130,6 +6130,8 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
     case DW_FORM_ref2:
     case DW_FORM_ref1:
     case DW_FORM_GNU_ref_alt:
+    case DW_FORM_ref_sup4:
+    case DW_FORM_ref_sup8:
       if (cbargs->silent)
 	break;
       Dwarf_Die ref;
-- 
1.8.3.1

             reply	other threads:[~2018-05-08 13:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 13:42 Mark Wielaard [this message]
2018-05-11 15:34 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1525786968-5504-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).