public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Subject: Re: [PATCH] libdw: Handle GNU DebugFission split ranges.
Date: Thu, 24 May 2018 13:26:00 -0000	[thread overview]
Message-ID: <1527168367.2911.19.camel@klomp.org> (raw)
In-Reply-To: <20180519140351.24361-1-mark@klomp.org>

[-- Attachment #1: Type: text/plain, Size: 1126 bytes --]

On Sat, 2018-05-19 at 16:03 +0200, Mark Wielaard wrote:
> GNU DebugFission split dwarf handles DW_FORM_sec_offset specially for
> attributes that point to ranges. The .debug_ranges section is not in
> the .dwo file, but in the main/skeleton object file. The sec_offset is
> not relocated (in the ELF file), but is an offset against the skeleton
> DIE DW_AT_GNU_ranges_base attribute. dwarf_formudata is changed so it
> still looks like a normal offset ptr into the .debug_ranges section.
> dwarf_ranges is adapted to look for the .debug_ranges in the main object
> file. dwarf_highpc and dwarf_lowpc now handle the highpc and lowpc
> attributes being inherited for the split unit DIE from the skeleton.
> 
> A new testcase is added to iterate over all ranges in a split GNU
> DebugFission file.

After double checking the test results after incorporating the full
DWARF5 rnglists support into readelf and libdw I found an embarrassing
bug. We didn't initialize the CU ranges_base causing some bad test
results. We also didn't handle bad DWARF correctly in one case. I am
pushing the following fixes for this.

[-- Attachment #2: Type: text/x-patch, Size: 3883 bytes --]

From c2d14cc492aa7fd28740d5789fede64ce81a063b Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 24 May 2018 15:20:25 +0200
Subject: [PATCH] libdw: Initialize ranges_base, add invalid DWARF test and fix
 expected output.

We never initialized the CU ranges_base, which meant we didn't actually
calculate it correctly. This caused bad ranges on some DIEs. The expected
output in the testcase was wrong. We also crashed on invalid dwarf.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog               | 5 +++++
 libdw/dwarf_ranges.c          | 6 ++++++
 libdw/libdw_findcu.c          | 1 +
 tests/ChangeLog               | 7 ++++++-
 tests/get-units-invalid.c     | 7 +++++++
 tests/run-all-dwarf-ranges.sh | 7 ++++---
 6 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4db0f5c..c302628 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-24  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf_ranges.c (dwarf_ranges): Check for NULL cu.
+	* libdw_findcu.c (__libdw_intern_next_unit): Initialize ranges_base.
+
 2018-05-18  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf_formudata.c (__libdw_formptr): Handle the special case
diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c
index b0450cf..52a61ee 100644
--- a/libdw/dwarf_ranges.c
+++ b/libdw/dwarf_ranges.c
@@ -123,6 +123,12 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
   /* We have to look for a noncontiguous range.  */
   size_t secidx = IDX_debug_ranges;
   Dwarf_CU *cu = die->cu;
+  if (cu == NULL)
+    {
+      __libdw_seterrno (DWARF_E_INVALID_DWARF);
+      return -1;
+    }
+
   const Elf_Data *d = cu->dbg->sectiondata[secidx];
   if (d == NULL && cu->unit_type == DW_UT_split_compile)
     {
diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
index d22ddae..83c2eb1 100644
--- a/libdw/libdw_findcu.c
+++ b/libdw/libdw_findcu.c
@@ -121,6 +121,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
   newp->base_address = (Dwarf_Addr) -1;
   newp->addr_base = (Dwarf_Off) -1;
   newp->str_off_base = (Dwarf_Off) -1;
+  newp->ranges_base = (Dwarf_Off) -1;
 
   newp->startp = data->d_buf + newp->start;
   newp->endp = data->d_buf + newp->end;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index a021a01..86bcf9d 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,6 +1,11 @@
+2018-05-24  Mark Wielaard  <mark@klomp.org>
+
+	* get-units-invalid.c (main): Add check for invalid dwarf_ranges.
+	* run-all-dwarf-ranges.sh: Correct expected output.
+
 2018-05-18  Mark Wielaard  <mark@klomp.org>
 
-	* tests/Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges.
+	* Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges.
 	(TESTS): Add run-all-dwarf-ranges.sh.
 	(EXTRA_DIST): Add run-all-dwarf-ranges.sh,
 	testfilesplitranges4.debug.bz2, testfile-ranges-hello.dwo.bz2
diff --git a/tests/get-units-invalid.c b/tests/get-units-invalid.c
index 9ec16ee..58b32c0 100644
--- a/tests/get-units-invalid.c
+++ b/tests/get-units-invalid.c
@@ -79,6 +79,13 @@ main (int argc, char *argv[])
 			  dwarf_diename (&result));
 		  return -1;
 		}
+	      Dwarf_Addr base, start, end;
+	      if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1)
+		{
+		  printf ("Should NOT have a ranges: %s\n",
+			  dwarf_diename (&result));
+		  return -1;
+		}
 	    }
 	  else if (unit_type == DW_UT_type)
 	    printf ("subdie: %s\n", dwarf_diename (&subdie));
diff --git a/tests/run-all-dwarf-ranges.sh b/tests/run-all-dwarf-ranges.sh
index 0bd641b..ba5528d 100755
--- a/tests/run-all-dwarf-ranges.sh
+++ b/tests/run-all-dwarf-ranges.sh
@@ -37,11 +37,12 @@ die: world.c (11)
  400500..400567
 
 die: happy (1d)
- 8009e0..8009ff
- 8008e0..8008f7
+ 40051c..400526
+ 400530..400534
+ 400535..40053f
 
 die: sad (1d)
- 400530..400534
+ 40051c..400526
  400535..40053f
 
 EOF
-- 
1.8.3.1


      parent reply	other threads:[~2018-05-24 13:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-19 14:04 Mark Wielaard
2018-05-22 22:42 ` Mark Wielaard
2018-05-24 13:26 ` Mark Wielaard [this message]

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=1527168367.2911.19.camel@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).