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

See Also:
Last reconfirmed:

Proposed patch (291 bytes, patch)
2016-09-29 13:40 IST, 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 IST
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_sections .eh_frame_entry

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_sections .eh_frame

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_sections .debug_frame
Comment 1 cvs-commit@gcc.gnu.org 2016-10-06 11:47:55 IST
The master branch has been updated by Matthew Fortune <mpf@sourceware.org>:


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.
    	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 IST
Fixed on master