[Bug libc/23125] New: riscv64: endless loop when throwing an exception from a constructor

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] New: riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

            Bug ID: 23125
           Summary: riscv64: endless loop when throwing an exception from
                    a constructor
           Product: glibc
           Version: 2.27
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: aurelien at aurel32 dot net
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---
              Host: riscv64-linux-gnu
            Target: riscv64-linux-gnu
             Build: riscv64-linux-gnu

Created attachment 10990
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10990&action=edit
testcase

The attached C++ code, extracted from googletest, tries to throw an exception
from a constructor. On riscv64, the processes goes into an endless loop using
100% of the CPU instead.

This has been first reported on the GCC bugzilla, and Jim Wilson found that the
issue was actually a GNU libc bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85492

To patches has been proposed so far:

--- a/sysdeps/riscv/start.S    
+++ a/sysdeps/riscv/start.S    
@@ -44,6 +44,7 @@

 ENTRY (ENTRY_POINT)
        call  .Lload_gp
+       li    ra, 0     /* Need 0 return address for unwind.  */
        mv    a5, a0  /* rtld_fini.  */
        /* main may be in a shared library.  */
        la   a0, main

and

--- a/sysdeps/riscv/start.S
+++ b/sysdeps/riscv/start.S
@@ -43,6 +43,8 @@
    __libc_start_main wants this in a5.  */

 ENTRY (ENTRY_POINT)
+       /* Mark ra as undefined in order to stop unwinding here!  */
+       cfi_undefined (ra)
        call  .Lload_gp
        mv    a5, a0  /* rtld_fini.  */
        /* main may be in a shared library.  */

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com
              Flags|                            |security-

--- Comment #1 from Florian Weimer <fweimer at redhat dot com> ---
Do we have an existing test case for this in the glibc test suite?

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
I'm not aware of an existing test for this in the glibc testsuite.

We do have bug 2682 for inappropriate unwinding from atexit handlers (bug
2682 comment 4 gives an architecture-independent test), but that's a
different bug, in the same general area of cases that need special
handling to terminate unwinding.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

Andrew Waterman <andrew at sifive dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrew at sifive dot com

--- Comment #3 from Andrew Waterman <andrew at sifive dot com> ---
I endorse the CFI-directive patch.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

Palmer Dabbelt <palmer at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |palmer at gcc dot gnu.org
           Assignee|unassigned at sourceware dot org   |palmer at gcc dot gnu.org

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

--- Comment #4 from Aurelien Jarno <aurelien at aurel32 dot net> ---
I have tried to write a patch for this bug, but it doesn't cope well with the
test infrastructure. To trigger the bug, the test has to trigger an unwind
(either calling _Unwind_Backtrace from libgcc1 or triggering a C++ exception)
directly from main. As soon as the test infrastructure is used, the unwind is
not triggered from main and it's not possible to trigger the bug anymore.

Any idea how to do handle that?

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

--- Comment #5 from Florian Weimer <fweimer at redhat dot com> ---
I think it's okay not to use the test harness in such cases.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

--- Comment #6 from Aurelien Jarno <aurelien at aurel32 dot net> ---
Thanks Florian. In that case, I guess the patch posted on the mailing list can
be committed as is.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

Andreas Schwab <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|riscv64-linux-gnu           |
               Host|riscv64-linux-gnu           |riscv64-*-*
              Build|riscv64-linux-gnu           |

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

Andreas Schwab <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |2.29

--- Comment #8 from Andreas Schwab <[hidden email]> ---
Fixed in 2.29.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug libc/23125] riscv64: endless loop when throwing an exception from a constructor

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23125

--- Comment #7 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  2dd12baa045f25c52b30a34b10f72d51f2605413 (commit)
      from  fec8bb7ca93d66cd2b019cfebcee6b3e6560ea36 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2dd12baa045f25c52b30a34b10f72d51f2605413

commit 2dd12baa045f25c52b30a34b10f72d51f2605413
Author: Andreas Schwab <[hidden email]>
Date:   Tue Sep 25 11:11:27 2018 +0200

    RISC-V: properly terminate call chain (bug 23125)

    Mark the ra register as undefined in _start, so that unwinding through
    main works correctly.  Also, don't use a tail call so that ra points after
    the call to __libc_start_main, not after the previous call.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                        |    9 +++++++++
 elf/Makefile                                     |    4 +++-
 elf/{tst-unwind-ctor-lib.c => tst-unwind-main.c} |   20 ++++++++------------
 sysdeps/riscv/start.S                            |    7 ++++++-
 4 files changed, 26 insertions(+), 14 deletions(-)
 copy elf/{tst-unwind-ctor-lib.c => tst-unwind-main.c} (77%)

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