[PATCH] readelf: It is not an error if there are no line number statements

Mark Wielaard mark@klomp.org
Wed Aug 26 12:30:42 GMT 2020


It can happen that there are no line number statements at the end of
a debug line section. So don't check that there are any more bytes
after the last file entry. And print "No line number statements."

libdw already got this corner case correct.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 5 +++++
 src/readelf.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 2452cd40..8eb2103d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-26  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (print_debug_line_section): It is not an error if there
+	are no line number statements at the end of a debug line section.
+
 2020-07-19  Mark Wielaard  <mark@klomp.org>
 
 	* elfclassify.c (process_current_path): Handle fwrite failing.
diff --git a/src/readelf.c b/src/readelf.c
index 685d0b17..41933d95 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8642,7 +8642,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
 		    printf (", ");
 		}
 	      printf ("\n");
-	      if (linep >= lineendp)
+	      if (linep > lineendp)
 		goto invalid_unit;
 	    }
 	}
@@ -8685,6 +8685,12 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
 	  ++linep;
 	}
 
+      if (linep == lineendp)
+	{
+	  puts (gettext ("\nNo line number statements."));
+	  return;
+	}
+
       puts (gettext ("\nLine number statements:"));
       Dwarf_Word address = 0;
       unsigned int op_index = 0;
-- 
2.18.4



More information about the Elfutils-devel mailing list