This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] dwarf: Read register number as unsigned in DW_CFA_def_cfa*


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=32ef30002cee3661eb645cd14bcc4ff77ea10f45

commit 32ef30002cee3661eb645cd14bcc4ff77ea10f45
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Fri Oct 27 09:01:36 2017 -0400

    dwarf: Read register number as unsigned in DW_CFA_def_cfa*
    
    When displaying the .debug_frame section, the register numbers in the
    DW_CFA_def_cfa* statements are read as signed numbers.  I have come
    across a target that has register 121, encoded as 0x79 in unsigned LEB128.
    Interpreting this as signed results in -7, which makes readelf display
    "r-7".
    
    The DWARF5 standard (6.4.2.2) states that the register numbers should be
    treated as unsigned LEB128.
    
    Simply replacing READ_SLEB with READ_ULEB resulted in warnings like
    these:
    
    /home/emaisin/src/binutils-gdb/binutils/dwarf.c: In function ââ?¬Ë?display_debug_framesââ?¬â?¢:
    /home/emaisin/src/binutils-gdb/binutils/dwarf.c:355:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
           if ((var) != _val)     \
                     ^
    /home/emaisin/src/binutils-gdb/binutils/dwarf.c:7866:8: note: in expansion of macro ââ?¬Ë?READ_ULEBââ?¬â?¢
            READ_ULEB (fc->cfa_reg);
            ^
    ... so I also changed Frame_Chunk::cfa_reg to an unsigned int.
    
    binutils/ChangeLog:
    
    	* dwarf.c (struct Frame_Chunk) <cfa_reg>: Change type to
    	unsigned int.
    	(display_debug_frames): Read CFA reg as an unsigned number.

Diff:
---
 binutils/ChangeLog | 6 ++++++
 binutils/dwarf.c   | 8 ++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index ad9d33b..8d77c68 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2017-10-27  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* dwarf.c (struct Frame_Chunk) <cfa_reg>: Change type to
+	unsigned int.
+	(display_debug_frames): Read CFA reg as an unsigned number.
+
 2017-10-25  Alan Modra  <amodra@gmail.com>
 
 	* nm.c (filter_symbols): Match "__gnu_lto_slim" optionally prefixed
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 06702ef..873f104 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -6646,7 +6646,7 @@ typedef struct Frame_Chunk
   int data_factor;
   dwarf_vma pc_begin;
   dwarf_vma pc_range;
-  int cfa_reg;
+  unsigned int cfa_reg;
   dwarf_vma cfa_offset;
   unsigned int ra;
   unsigned char fde_encoding;
@@ -7863,7 +7863,7 @@ display_debug_frames (struct dwarf_section *section,
 	      break;
 
 	    case DW_CFA_def_cfa:
-	      READ_SLEB (fc->cfa_reg);
+	      READ_ULEB (fc->cfa_reg);
 	      READ_ULEB (fc->cfa_offset);
 	      fc->cfa_exp = 0;
 	      if (! do_debug_frames_interp)
@@ -7872,7 +7872,7 @@ display_debug_frames (struct dwarf_section *section,
 	      break;
 
 	    case DW_CFA_def_cfa_register:
-	      READ_SLEB (fc->cfa_reg);
+	      READ_ULEB (fc->cfa_reg);
 	      fc->cfa_exp = 0;
 	      if (! do_debug_frames_interp)
 		printf ("  DW_CFA_def_cfa_register: %s\n",
@@ -7991,7 +7991,7 @@ display_debug_frames (struct dwarf_section *section,
 	      break;
 
 	    case DW_CFA_def_cfa_sf:
-	      READ_SLEB (fc->cfa_reg);
+	      READ_ULEB (fc->cfa_reg);
 	      READ_ULEB (fc->cfa_offset);
 	      fc->cfa_offset = fc->cfa_offset * fc->data_factor;
 	      fc->cfa_exp = 0;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]