This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] DWARF: Allow hard frame pointer even if frame pointer isn't used
- From: Jason Merrill <jason at redhat dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Michael Matz <matz at suse dot de>, Segher Boessenkool <segher at kernel dot crashing dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Cary Coutant <ccoutant at gmail dot com>
- Date: Tue, 4 Sep 2018 16:03:20 -0400
- Subject: Re: [PATCH] DWARF: Allow hard frame pointer even if frame pointer isn't used
- References: <CAMe9rOpuzruGwKLemne71evtdVuKTAK9Z6MpUZng-eGGGQU5ww@mail.gmail.com>
OK.
On Tue, Sep 4, 2018 at 11:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Sep 3, 2018 at 10:01 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Mon, Sep 3, 2018 at 9:44 AM, Michael Matz <matz@suse.de> wrote:
>>> Hi,
>>>
>>> On Mon, 3 Sep 2018, H.J. Lu wrote:
>>>
>>>> > So, what's the testcase testing then? Before the patch it doesn't ICE,
>>>> > after the patch it doesn't ICE. What should I look out for so I can see
>>>> > that what the testcase is producing without the patch is wrong?
>>>>
>>>> Before the patch, debug info is wrong since it uses hard frame pointer
>>>> which isn't set up for the function. You can do "readelf -w" on .o file to
>>>> verify the debug info.
>>>
>>> Yeah, that's what I thought as well, but it's correct:
>>>
>>> % ./gcc/cc1plus -quiet -O2 -g -fno-omit-frame-pointer -fvar-tracking x.cc
>>> % gcc -c x.s
>>> % readelf -wfi x.o
>>> ...
>>> <1><8a>: Abbrev Number: 9 (DW_TAG_subprogram)
>>> <8b> DW_AT_specification: <0x3a>
>>> <8f> DW_AT_decl_line : 6
>>> <90> DW_AT_decl_column : 5
>>> <91> DW_AT_object_pointer: <0xa7>
>>> <95> DW_AT_low_pc : 0x0
>>> <9d> DW_AT_high_pc : 0x3
>>> <a5> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
>>> <a7> DW_AT_GNU_all_call_sites: 1
>>> ...
>>> <2><fe>: Abbrev Number: 11 (DW_TAG_formal_parameter)
>>> <ff> DW_AT_name : d
>>> <101> DW_AT_decl_file : 1
>>> <102> DW_AT_decl_line : 6
>>> <103> DW_AT_decl_column : 63
>>> <104> DW_AT_type : <0x78>
>>> <108> DW_AT_location : 2 byte block: 91 8 (DW_OP_fbreg: 8)
>>> ...
>>> DW_CFA_def_cfa: r7 (rsp) ofs 8
>>> DW_CFA_offset: r16 (rip) at cfa-8
>>> DW_CFA_nop
>>> DW_CFA_nop
>>> ...
>>>
>>> So, argument 'd' is supposed to be at DW_AT_frame_base + 8, which is
>>> %rsp+8+8, aka %rsp+16, which is correct given that it's the eigth argument
>>> (including the implicit this parameter).
>>
>> Can we use DW_AT_frame_base when the frame pointer isn't available?
>> If yes,
>>
>> gcc_assert ((SUPPORTS_STACK_ALIGNMENT
>> && (elim == hard_frame_pointer_rtx
>> || elim == stack_pointer_rtx))
>> || elim == (frame_pointer_needed
>> ? hard_frame_pointer_rtx
>> : stack_pointer_rtx));
>>
>> should be changed to
>>
>> gcc_assert (elim == hard_frame_pointer_rtx
>> || elim == stack_pointer_rtx);
>>
>> This will also fix:
>>
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86593
>>
>
> Since hard frame pointer is encoded with DW_OP_fbreg which uses the
> DW_AT_frame_base attribute, not hard frame pointer directly, we should
> allow hard frame pointer when generating DWARF info even if frame pointer
> isn't used.
>
> OK for trunk?
>
> --
> H.J.