[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/29268] New: readelf misinterprets register rule inheritanc

From: sevaa at sprynet dot com
Subject: [Bug binutils/29268] New: readelf misinterprets register rule inheritance from CIE to FDE
Date: Mon, 20 Jun 2022 18:10:50 +0000


            Bug ID: 29268
           Summary: readelf misinterprets register rule inheritance from
                    CIE to FDE
           Product: binutils
           Version: 2.39 (HEAD)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: sevaa at sprynet dot com
  Target Milestone: ---

Created attachment 14154
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14154&action=edit
Test binary

Consider the debug info attached binary. The binary's first FDE in .eh_frame
has initial_location 0x1060, and the following instructions:

DW_CFA_advance_loc 4    # Move PC by 4
DW_CFA_undefined 16     # Change the rule for R16 to undefined

The linked CIE marks R16 as the return address, and has the following

DW_CFA_def_cfa 7, 8    # CFA is at R7+8
DW_CFA_offset 16, 1    # Set the rule for R16 to [CFA+1*data_aligment_factor])

The GNU readelf, if executed with --debug-dump=frames-interp, dumps the FDE
as follows:

00000018 0000000000000014 0000001c FDE cie=00000000

     LOC           CFA      ra    

0000000000001060 rsp+8    u     
0000000000001064 rsp+8    u

Meanwhile, an alternative parser thinks that at the range [0x1060-0x1064), the
rule for RA/R16 should be as inherited from the CIE, and it goes c-8.

I've debugged readelf (the latest master, as of 06/01/22), to that point. There
are two passes over the FDE instructions: one starting on dwarf.c:9296, the
other starting at dwarf.c:9442. On the first pass, when DW_CFA_undefined is
encountered, there is the following case statement:

READ_ULEB (reg, start, block_end);
if (frame_need_space (fc, reg) >= 0)
    fc->col_type[reg] = DW_CFA_undefined;

If I understand correctly, the intended purpose of the first pass is to
allocate enough memory in the fc->col_type and fc->col_offset arrays, and the
logic of this operator's handling was meant to be: if this register was
not mentioned before, allocate space for it, and reset its rule to undefined.
HOWEVER, if the register WAS mentioned before (e. g. in the CIE),
frame_need_space() returns 0, and the if() body executes anyway, and resets
the rule for the register to undefined, erasing the initial state as specified
by the CIE.

I think the if statement should go, instead, "if (frame_need_space (fc, reg) >
0)". Same for other register-rule-type operators on the first pass.

You are receiving this mail because:
You are on the CC list for the bug.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]