Bug 20648 - over cautious .cfi_sections consistency check
Summary: over cautious .cfi_sections consistency check
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-29 13:40 UTC by Matthew Fortune
Modified: 2016-10-06 11:49 UTC (History)
0 users

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


Attachments
Proposed patch (291 bytes, patch)
2016-09-29 13:40 UTC, Matthew Fortune
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Fortune 2016-09-29 13:40:30 UTC
Created attachment 9538 [details]
Proposed patch

.cfi_sections had consistency checking added as part of support for new compact eh_frame sections.  The original check was simply to disallow any variation in the sections specified when multiple .cfi_sections directives were seen.  This caused some issues as the directive is supposed to allow additional sections to be listed via multiple instances.

As it happens the original compact eh support did not actually prevent switching to the compact form if the first .cfi_sections came after the first CFI data:

        .cfi_startproc
        .cfi_sections .eh_frame_entry
        .cfi_endproc

The fix for PR gas/19614 fixed both the issues above but ended up still left the consistency check more aggressive that it needs to be.

For background... the need for the consistency check comes from the change in behavior of all the other .cfi* directives depending on whether the original or compact form of eh_frame is to be generated.

Other non-GCC users of gas however now face a change in behavior that is not technically necessary. I.e. llvm as per https://llvm.org/bugs/show_bug.cgi?id=29017.

A reasonable fix would be to make the consistency check specifically about the one problem case where one turns on compact EH after emitting CFI data. This could be done by looking at the compact_eh global changing from false to true (when cfi_sections_set is true) but that would allow the following which may be misleading:

        .cfi_sections .eh_frame_entry
        .cfi_startproc
        .cfi_sections .eh_frame
        .cfi_endproc

I.e. the use of .eh_frame may mean a user expects the non-compact form.

Instead we can check if a new .cfi_sections specifies either of .eh_frame or .eh_frame_entry and if so verifies whether this is now different from what was there before.  Specifically it means the testcase directly above is rejected and the one below is accepted:

        .cfi_sections .eh_frame
        .cfi_startproc
        .cfi_sections .debug_frame
        .cfi_endproc
Comment 1 cvs-commit@gcc.gnu.org 2016-10-06 11:47:55 UTC
The master branch has been updated by Matthew Fortune <mpf@sourceware.org>:

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

commit 3d3424e9a8d6ad56160b98bf6e223c0346164468
Author: Matthew Fortune <matthew.fortune@imgtec.com>
Date:   Thu Sep 29 11:13:46 2016 +0100

    Refine .cfi_sections check to only consider compact eh_frame
    
    The .cfi_sections directive can be safely used multiple times
    with different sections named at any time unless the compact form
    of exception handling is requested after CFI information has
    been emitted.  Only the compact form of CFI information changes
    the way in which CFI is generated and therefore cannot be
    retrospectively requested after generating CFI information.
    
    gas/
    
    	PR gas/20648
    	* dw2gencfi.c (dot_cfi_sections): Refine the check for
    	inconsistent .cfi_sections to only consider compact vs non
    	compact forms.
    	* testsuite/gas/cfi/cfi-common-9.d: New file.
    	* testsuite/gas/cfi/cfi-common-9.s: New file.
    	* testsuite/gas/cfi/cfi.exp: Run new test.
Comment 2 Matthew Fortune 2016-10-06 11:49:04 UTC
Fixed on master