Two small readelf.c fixes

Mark Wielaard mjw at redhat.com
Mon Aug 27 18:59:35 UTC 2012


Hi,

While doing release testing for 0.155 I found two small issues in
readelf.c. The first is triggered by the new readelf-self testcase
on ARM. register_info is called by print_cfa_program with loc being
NULL, but didn't check for that possibility. The second is a compile
error on s390 because we were using %z to print the offset in
print_debug_macro_section which isn't correct, but only shows on s390
because size_t is unsigned long (not int) there.
The attached patches fix these issues.

I'll write a more direct testcase for the first issue after the
release because the underlying issue really is an unknown DWARF
register number on the architecture.

Cheers,

Mark
-------------- next part --------------
commit e89c500fbbd7a54912b06fce0729367b94b52a50
Author: Mark Wielaard <mjw at redhat.com>
Date:   Mon Aug 27 14:30:05 2012 +0200

    readelf.c (register_info): Handle loc == NULL.
    
    register_info is called by print_cfa_program with loc being NULL.
    
    Signed-off-by: Mark Wielaard <mjw at redhat.com>

diff --git a/src/ChangeLog b/src/ChangeLog
index d80f844..72804bd 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2012-08-27  Mark Wielaard  <mjw at redhat.com>
+
+	* readelf.c (register_info): Handle loc == NULL.
+
 2012-08-22  Jeff Kenton  <jkenton at tilera.com>
 
 	* elflint.c (valid_e_machine): Add EM_TILEGX and EM_TILEPRO.
diff --git a/src/readelf.c b/src/readelf.c
index dc49669..4ff8ebb 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4305,9 +4305,12 @@ register_info (Ebl *ebl, unsigned int regno, const Ebl_Register_Location *loc,
 				 bits ?: &ignore, type ?: &ignore);
   if (n <= 0)
     {
-      snprintf (name, REGNAMESZ, "reg%u", loc->regno);
+      if (loc != NULL)
+	snprintf (name, REGNAMESZ, "reg%u", loc->regno);
+      else
+	snprintf (name, REGNAMESZ, "??? 0x%x", regno);
       if (bits != NULL)
-	*bits = loc->bits;
+	*bits = loc != NULL ? loc->bits : 0;
       if (type != NULL)
 	*type = DW_ATE_unsigned;
       set = "??? unrecognized";
@@ -4315,7 +4318,7 @@ register_info (Ebl *ebl, unsigned int regno, const Ebl_Register_Location *loc,
   else
     {
       if (bits != NULL && *bits <= 0)
-	*bits = loc->bits;
+	*bits = loc != NULL ? loc->bits : 0;
       if (type != NULL && *type == DW_ATE_void)
 	*type = DW_ATE_unsigned;
 

commit 3e44006ae24843eff9b7248f3e250cf0fe41e7aa
Author: Mark Wielaard <mjw at redhat.com>
Date:   Mon Aug 27 15:21:58 2012 +0200

    readelf.c (print_debug_macro_section): Print offset as PRIx64.
    
    Signed-off-by: Mark Wielaard <mjw at redhat.com>

diff --git a/src/ChangeLog b/src/ChangeLog
index 72804bd..fc576fc 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
 2012-08-27  Mark Wielaard  <mjw at redhat.com>
 
+	* readelf.c (print_debug_macro_section): Print offset as PRIx64.
+
+2012-08-27  Mark Wielaard  <mjw at redhat.com>
+
 	* readelf.c (register_info): Handle loc == NULL.
 
 2012-08-22  Jeff Kenton  <jkenton at tilera.com>
diff --git a/src/readelf.c b/src/readelf.c
index 4ff8ebb..2954e74 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6324,8 +6324,8 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 
   while (readp < readendp)
     {
-      printf (gettext (" Offset:             0x%zx\n"),
-	      readp - (const unsigned char *) data->d_buf);
+      printf (gettext (" Offset:             0x%" PRIx64 "\n"),
+	      (uint64_t) (readp - (const unsigned char *) data->d_buf));
 
       // Header, 2 byte version, 1 byte flag, optional .debug_line offset,
       // optional vendor extension macro entry table.


More information about the elfutils-devel mailing list