about summary refs log tree commit diff
path: root/elf/tst-unwind-main.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2018-09-25 11:11:27 +0200
committerAndreas Schwab <schwab@suse.de>2018-10-30 12:07:25 +0100
commit2dd12baa045f25c52b30a34b10f72d51f2605413 (patch)
tree0b6533d453252b050dcf19f052a1ccb4d6bf46cb /elf/tst-unwind-main.c
parentfec8bb7ca93d66cd2b019cfebcee6b3e6560ea36 (diff)
downloadglibc-2dd12baa045f25c52b30a34b10f72d51f2605413.tar.gz
glibc-2dd12baa045f25c52b30a34b10f72d51f2605413.tar.xz
glibc-2dd12baa045f25c52b30a34b10f72d51f2605413.zip
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.
Diffstat (limited to 'elf/tst-unwind-main.c')
-rw-r--r--elf/tst-unwind-main.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/elf/tst-unwind-main.c b/elf/tst-unwind-main.c
new file mode 100644
index 0000000000..d1236032d7
--- /dev/null
+++ b/elf/tst-unwind-main.c
@@ -0,0 +1,38 @@
+/* Test unwinding through main.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unwind.h>
+#include <unistd.h>
+#include <support/test-driver.h>
+
+static _Unwind_Reason_Code
+callback (struct _Unwind_Context *ctx, void *arg)
+{
+  return _URC_NO_REASON;
+}
+
+int
+main (void)
+{
+  /* Arrange for this test to be killed if _Unwind_Backtrace runs into an
+     endless loop.  We cannot use the test driver because the complete
+     call chain needs to be compiled with -funwind-tables so that
+     _Unwind_Backtrace is able to reach _start.  */
+  alarm (DEFAULT_TIMEOUT);
+  _Unwind_Backtrace (callback, 0);
+}