public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Mark RA as undefined at the start of execution
@ 2018-05-19  0:51 Palmer Dabbelt
  2018-09-25 11:42 ` Andreas Schwab
  0 siblings, 1 reply; 2+ messages in thread
From: Palmer Dabbelt @ 2018-05-19  0:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: Palmer Dabbelt

glibc bug 23125 (originally GCC bug 85492) demonstrates an infinate loop
in exception handling that results from RA as being undefined at the
start of program execution.  This patch uses a CFI directive to mark RA
as undefined, which allows the backtrace to terminate.

There is no explicit glibc test case for this, but I thought I'd send
the patch out anyway as it is fixing a bug.  I'd like to have a test
before committing this.

I have not even compiled this.  I will do that before committing... :)

Thanks to Aurelian Jarno for finding the bug, and Jim Wilson for fixing
it.

ChangeLog

2018-05-18  Palmer Dabbelt  <palmer@sifive.com>

        PR 23125
        * sysdeps/riscv/start.S (ENTRY_POINT): Mark ra as undefined so
        backtraces can terminate if they reach this point.
---
 sysdeps/riscv/start.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sysdeps/riscv/start.S b/sysdeps/riscv/start.S
index 4635ddb5eb8c..93a80bc4a760 100644
--- 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.  */
-- 
2.16.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] RISC-V: Mark RA as undefined at the start of execution
  2018-05-19  0:51 [PATCH] RISC-V: Mark RA as undefined at the start of execution Palmer Dabbelt
@ 2018-09-25 11:42 ` Andreas Schwab
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2018-09-25 11:42 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: libc-alpha

On Mai 18 2018, Palmer Dabbelt <palmer@dabbelt.com> wrote:

> diff --git a/sysdeps/riscv/start.S b/sysdeps/riscv/start.S
> index 4635ddb5eb8c..93a80bc4a760 100644
> --- 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.  */

This will put the DW_CFA_undefined into the CIE, not the FDE, since it
isn't associated with an insn.  You problably want to move it after the
call (CFI directives are always associated with the preceding insn).

The same issue exists with sysdeps/unix/sysv/linux/riscv/setcontext.S.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-25 11:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-19  0:51 [PATCH] RISC-V: Mark RA as undefined at the start of execution Palmer Dabbelt
2018-09-25 11:42 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).