Bug 16252 - readelf -wF mishandles DW_CFA_restore_state
Summary: readelf -wF mishandles DW_CFA_restore_state
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.23
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-26 11:19 UTC by Andreas Schwab
Modified: 2014-06-09 14:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (723 bytes, patch)
2014-05-28 09:19 UTC, romain.chastenet
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schwab 2013-11-26 11:19:11 UTC
readelf -wF loses the state of the saved registers after DW_CFA_restore_state.

$ readelf -wf nptl/pthread_cond_timedwait.os
Contents of the .eh_frame section:

00000000 0000001c 00000000 CIE
  Version:               1
  Augmentation:          "zPLR"
  Code alignment factor: 1
  Data alignment factor: -4
  Return address column: 8
  Augmentation data:     9b ed ff ff ff 1b 1b

  DW_CFA_def_cfa: r4 (esp) ofs 4
  DW_CFA_offset: r8 (eip) at cfa-4
  DW_CFA_nop
  DW_CFA_nop

00000020 00000058 00000024 FDE cie=00000000 pc=00000000..00000570
  Augmentation data:     cf ff ff ff

  DW_CFA_advance_loc: 1 to 00000001
  DW_CFA_def_cfa_offset: 8
  DW_CFA_offset: r5 (ebp) at cfa-8
  DW_CFA_advance_loc: 1 to 00000002
  DW_CFA_def_cfa_offset: 12
  DW_CFA_offset: r7 (edi) at cfa-12
  DW_CFA_advance_loc: 1 to 00000003
  DW_CFA_def_cfa_offset: 16
  DW_CFA_offset: r6 (esi) at cfa-16
  DW_CFA_advance_loc: 1 to 00000004
  DW_CFA_def_cfa_offset: 20
  DW_CFA_offset: r3 (ebx) at cfa-20
  DW_CFA_advance_loc1: 114 to 00000076
  DW_CFA_def_cfa_offset: 52
  DW_CFA_remember_state
  DW_CFA_advance_loc2: 440 to 0000022e
  DW_CFA_def_cfa_offset: 20
  DW_CFA_advance_loc: 7 to 00000235
  DW_CFA_def_cfa_offset: 16
  DW_CFA_restore: r3 (ebx)
  DW_CFA_advance_loc: 1 to 00000236
  DW_CFA_def_cfa_offset: 12
  DW_CFA_restore: r6 (esi)
  DW_CFA_advance_loc: 1 to 00000237
  DW_CFA_def_cfa_offset: 8
  DW_CFA_restore: r7 (edi)
  DW_CFA_advance_loc: 1 to 00000238
  DW_CFA_def_cfa_offset: 4
  DW_CFA_restore: r5 (ebp)
  DW_CFA_advance_loc: 1 to 00000239
  DW_CFA_restore_state
  DW_CFA_advance_loc: 9 to 00000242
  DW_CFA_def_cfa_offset: 20
  DW_CFA_advance_loc: 63 to 00000281
  DW_CFA_def_cfa_offset: 52
  DW_CFA_advance_loc1: 84 to 000002d5
  DW_CFA_def_cfa_offset: 20
  DW_CFA_advance_loc1: 64 to 00000315
  DW_CFA_def_cfa_offset: 52
  DW_CFA_advance_loc1: 244 to 00000409
  DW_CFA_def_cfa_offset: 20
  DW_CFA_advance_loc: 28 to 00000425
  DW_CFA_def_cfa_offset: 52
  DW_CFA_nop
  DW_CFA_nop

$ readelf -wF nptl/pthread_cond_timedwait.os
Contents of the .eh_frame section:

00000000 0000001c 00000000 CIE "zPLR" cf=1 df=-4 ra=8
   LOC   CFA      ra      
00000000 esp+4    c-4   

00000020 00000058 00000024 FDE cie=00000000 pc=00000000..00000570
   LOC   CFA      ebx   ebp   esi   edi   ra      
00000000 esp+4    u     u     u     u     c-4   
00000001 esp+8    u     c-8   u     u     c-4   
00000002 esp+12   u     c-8   u     c-12  c-4   
00000003 esp+16   u     c-8   c-16  c-12  c-4   
00000004 esp+20   c-20  c-8   c-16  c-12  c-4   
00000076 esp+52   c-20  c-8   c-16  c-12  c-4   
0000022e esp+20   c-20  c-8   c-16  c-12  c-4   
00000235 esp+16   u     c-8   c-16  c-12  c-4   
00000236 esp+12   u     c-8   u     c-12  c-4   
00000237 esp+8    u     c-8   u     u     c-4   
00000238 esp+4    u     u     u     u     c-4   
00000239 esp+4    c-20  u     u     u     c-4   
00000242 esp+20   c-20  u     u     u     c-4   
00000281 esp+52   c-20  u     u     u     c-4   
000002d5 esp+20   c-20  u     u     u     c-4   
00000315 esp+52   c-20  u     u     u     c-4   
00000409 esp+20   c-20  u     u     u     c-4   
00000425 esp+52   c-20  u     u     u     c-4   

There is a DW_CFA_restore_state at 00000239 that restores the state at 00000076, but readelf -wF displays u for the saved registers.
Comment 1 romain.chastenet 2014-05-28 09:19:06 UTC
Created attachment 7618 [details]
Proposed patch

The cfa_reg, cfa_exp, cfa_offset and ra fields weren't saved in the remembered state during the DW_CFA_remember_state operation. The attached patch fixes this bug.
Comment 2 Sourceware Commits 2014-06-09 14:10:10 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  d71ad7fcb80503e5bd2dec76fa1ad7f030e72995 (commit)
       via  203e84589f591db087e72f02100f45858519d532 (commit)
       via  0b128c63925cc1aaa6ea1e9c0ef07eb704349688 (commit)
      from  9caaaa8397d0d123b94d05dc7a2206b8be39727e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit d71ad7fcb80503e5bd2dec76fa1ad7f030e72995
Author: Romain Chastenet <romain.chastenet@free.fr>
Date:   Mon Jun 9 15:06:58 2014 +0100

    Correctly save and recall the CFA saved register state.
    
    	PR binutils/16252
    	* dwarf.c (display_debug_frames): Remember the state of the
    	cfa_offset, cfa_reg, ra and cfa_exp field

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

commit 203e84589f591db087e72f02100f45858519d532
Author: Ryan Mansfield <rmansfield@qnx.com>
Date:   Mon Jun 9 15:04:01 2014 +0100

    Remove reference to GASp from linker testsuite configuration.
    
          * config/default.exp (GASP): Remove.

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

commit 0b128c63925cc1aaa6ea1e9c0ef07eb704349688
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Jun 9 11:04:41 2014 +0100

    Update expected disassembly of MSP430X instructions now that the disassembler
    correcctly interprets an extension word with zero index offsets.
    
    	* gas/msp430/msp430x.d: Update to match revised assembler output.

-----------------------------------------------------------------------

Summary of changes:
 binutils/ChangeLog                 |    6 ++
 binutils/dwarf.c                   |   20 +++++--
 gas/testsuite/ChangeLog            |    4 ++
 gas/testsuite/gas/msp430/msp430x.d |  106 ++++++++++++++++++------------------
 ld/testsuite/ChangeLog             |    4 ++
 ld/testsuite/config/default.exp    |    4 --
 6 files changed, 81 insertions(+), 63 deletions(-)
Comment 3 Nick Clifton 2014-06-09 14:10:52 UTC
Patch applied.