Bug 29132 - [4.1 Regression] Mips exception handling broken.
: [4.1 Regression] Mips exception handling broken.
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: debug
: 4.2.0
: P1 normal
: 4.1.2
Assigned To: roger
:
: EH, wrong-code
:
:
  Show dependency treegraph
 
Reported: 2006-09-18 20:46 UTC by David Daney
Modified: 2006-09-25 03:23 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: mipsel-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.1.1 4.2.0
Known to fail: 4.1.2
Last reconfirmed: 2006-09-22 16:51:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Daney 2006-09-18 20:46:21 UTC
The combination of GCC (r116604 or later) and binutils-2.17 creates bad
.eh_frame data causing SIGSEGV at runtime anytime an exception is thrown.

To reproduce just run the g++ testsuite.  All exception tests FAIL.

This problem is discussed further in:
http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00732.html
Comment 1 roger 2006-09-18 21:27:52 UTC
Hi David,

I was wondering if you have a MIPS tree handy, whether you could easily
test the following single line patch:

Index: dwarf2out.c
===================================================================
*** dwarf2out.c (revision 117035)
--- dwarf2out.c (working copy)
*************** dwarf2out_begin_prologue (unsigned int l
*** 2572,2578 ****
    fde = &fde_table[fde_table_in_use++];
    fde->decl = current_function_decl;
    fde->dw_fde_begin = dup_label;
!   fde->dw_fde_current_label = NULL;
    fde->dw_fde_hot_section_label = NULL;
    fde->dw_fde_hot_section_end_label = NULL;
    fde->dw_fde_unlikely_section_label = NULL;
--- 2572,2578 ----
    fde = &fde_table[fde_table_in_use++];
    fde->decl = current_function_decl;
    fde->dw_fde_begin = dup_label;
!   fde->dw_fde_current_label = dup_label;
    fde->dw_fde_hot_section_label = NULL;
    fde->dw_fde_hot_section_end_label = NULL;
    fde->dw_fde_unlikely_section_label = NULL;

Due to all the abstraction with debugging formats, its difficult to tell the
order in which things get executed, and whether this initial value for
dw_fde_current_label survives long enough to avoid use of a set_loc.

Many thanks in advance,
Comment 2 Andrew Pinski 2006-09-18 21:32:04 UTC
The patch also went into the 4.1 branch.
Comment 3 ddaney 2006-09-18 21:32:54 UTC
Subject: Re:  [4.2 Regression] Mips exception handling broken.

roger at eyesopen dot com wrote:
> ------- Comment #1 from roger at eyesopen dot com  2006-09-18 21:27 -------
> Hi David,
> 
> I was wondering if you have a MIPS tree handy, whether you could easily
> test the following single line patch:
> 
> Index: dwarf2out.c
> ===================================================================
> *** dwarf2out.c (revision 117035)
> --- dwarf2out.c (working copy)
> *************** dwarf2out_begin_prologue (unsigned int l
> *** 2572,2578 ****
>     fde = &fde_table[fde_table_in_use++];
>     fde->decl = current_function_decl;
>     fde->dw_fde_begin = dup_label;
> !   fde->dw_fde_current_label = NULL;
>     fde->dw_fde_hot_section_label = NULL;
>     fde->dw_fde_hot_section_end_label = NULL;
>     fde->dw_fde_unlikely_section_label = NULL;
> --- 2572,2578 ----
>     fde = &fde_table[fde_table_in_use++];
>     fde->decl = current_function_decl;
>     fde->dw_fde_begin = dup_label;
> !   fde->dw_fde_current_label = dup_label;
>     fde->dw_fde_hot_section_label = NULL;
>     fde->dw_fde_hot_section_end_label = NULL;
>     fde->dw_fde_unlikely_section_label = NULL;
> 
> Due to all the abstraction with debugging formats, its difficult to tell the
> order in which things get executed, and whether this initial value for
> dw_fde_current_label survives long enough to avoid use of a set_loc.
> 

I will try the patch now.  A full build with libgcj will take me several 
hours to build and test.

David Daney.
Comment 4 ddaney 2006-09-18 21:59:19 UTC
Subject: Re:  [4.2 Regression] Mips exception handling broken.

roger at eyesopen dot com wrote:
> ------- Comment #1 from roger at eyesopen dot com  2006-09-18 21:27 -------
> Hi David,
> 
> I was wondering if you have a MIPS tree handy, whether you could easily
> test the following single line patch:
> 
> Index: dwarf2out.c
> ===================================================================
> *** dwarf2out.c (revision 117035)
> --- dwarf2out.c (working copy)
> *************** dwarf2out_begin_prologue (unsigned int l
> *** 2572,2578 ****
>     fde = &fde_table[fde_table_in_use++];
>     fde->decl = current_function_decl;
>     fde->dw_fde_begin = dup_label;
> !   fde->dw_fde_current_label = NULL;
>     fde->dw_fde_hot_section_label = NULL;
>     fde->dw_fde_hot_section_end_label = NULL;
>     fde->dw_fde_unlikely_section_label = NULL;
> --- 2572,2578 ----
>     fde = &fde_table[fde_table_in_use++];
>     fde->decl = current_function_decl;
>     fde->dw_fde_begin = dup_label;
> !   fde->dw_fde_current_label = dup_label;
>     fde->dw_fde_hot_section_label = NULL;
>     fde->dw_fde_hot_section_end_label = NULL;
>     fde->dw_fde_unlikely_section_label = NULL;
> 
> Due to all the abstraction with debugging formats, its difficult to tell the
> order in which things get executed, and whether this initial value for
> dw_fde_current_label survives long enough to avoid use of a set_loc.
> 
> Many thanks in advance,
> 

Preliminary results using: readelf --debug-dump=frames libstdc++.so show 
that this patch is working.

I now get:

00000064 00000024 00000068 FDE cie=00000000 pc=0003ed40..0003eed4
   Augmentation data:     00 00 00 00

   DW_CFA_advance_loc: 16 to 0003ed50
   DW_CFA_def_cfa_offset: 48
   DW_CFA_advance_loc: 24 to 0003ed68
   DW_CFA_offset: r16 at cfa-24
   DW_CFA_offset: r17 at cfa-20
   DW_CFA_offset: r18 at cfa-16
   DW_CFA_offset: r19 at cfa-12
   DW_CFA_offset: r20 at cfa-8


Both addresses shown for DW_CFA_advance_loc are within the range of PC 
for the FDE.  It will take (a lot) more time to see if the code actually 
works on my test platform, but it looks good to me so far.

David Daney.
Comment 5 David Daney 2006-09-19 05:58:27 UTC
OK, I finished running make -k check with a i686-linux -> mipsel-linux cross
compiler on my mips board for c, c++, java and there are only the 'normal'
failures (mostly attributable to running the testsuite on a remote board). 
Exception handling seems to be fixed with the Roger's patch applied.

I would say test it on a couple of other targets of your choice and then commit
it.

Thanks Roger for fixing this.
Comment 6 Roger Sayle 2006-09-21 17:13:46 UTC
Subject: Bug 29132

Author: sayle
Date: Thu Sep 21 17:13:33 2006
New Revision: 117114

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117114
Log:
2006-09-21  Roger Sayle  <roger@eyesopen.com>

    PR debug/29132
    * dwarf2out.c (dwarf2out_begin_prologue): Initialise the current label,
    dw_fde_current_label, to be the start of the function, i.e. the same
    value as dw_fde_begin.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
Comment 7 roger 2006-09-22 16:51:25 UTC
Fixed on mainline (confirmed on mips-sgi-irix6.5).  It'll take another day or
two to backport to the 4.1 branch, as bootstrap and regtest on MIPS takes a
while.
Comment 8 Roger Sayle 2006-09-24 15:56:00 UTC
Subject: Bug 29132

Author: sayle
Date: Sun Sep 24 15:55:51 2006
New Revision: 117180

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117180
Log:

    PR debug/29132
    Backport from mainline
    * dwarf2out.c (dwarf2out_begin_prologue): Initialise the current label,
    dw_fde_current_label, to be the start of the function, i.e. the same
    value as dw_fde_begin.


Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/dwarf2out.c
Comment 9 Andrew Pinski 2006-09-25 03:23:05 UTC
Fixed.