From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10149 invoked by alias); 15 Dec 2018 22:29:48 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 10119 invoked by uid 89); 15 Dec 2018 22:29:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT autolearn=ham version=3.3.2 spammy=lla, H*r:4.89, unwinding, H*Ad:U*schwab X-Spam-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: hall.aurel32.net Received: from hall.aurel32.net (HELO hall.aurel32.net) (163.172.24.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Dec 2018 22:29:44 +0000 Received: from [2001:bc8:30d7:120:9bb5:8936:7e6a:9e36] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gYIRJ-0007ey-AE; Sat, 15 Dec 2018 23:29:41 +0100 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.91) (envelope-from ) id 1gYIRI-0006pB-NU; Sat, 15 Dec 2018 23:29:40 +0100 From: Aurelien Jarno To: libc-stable@sourceware.org Cc: Andreas Schwab Subject: [2.28 COMMITTED] RISC-V: properly terminate call chain (bug 23125) Date: Mon, 01 Jan 2018 00:00:00 -0000 Message-Id: <20181215222911.26160-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-12/txt/msg00020.txt.bz2 From: Andreas Schwab 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. (cherry picked from commit 2dd12baa045f25c52b30a34b10f72d51f2605413) --- ChangeLog | 9 +++++++++ elf/Makefile | 5 ++++- elf/tst-unwind-main.c | 38 ++++++++++++++++++++++++++++++++++++++ sysdeps/riscv/start.S | 7 ++++++- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 elf/tst-unwind-main.c diff --git a/ChangeLog b/ChangeLog index d8459496bac..81555f1675a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2018-10-30 Andreas Schwab + + [BZ #23125] + * sysdeps/riscv/start.S (ENTRY_POINT): Mark ra as undefined. + Don't use tail call. + * elf/tst-unwind-main.c: New file. + * elf/Makefile (tests): Add tst-unwind-main. + (CFLAGS-tst-unwind-main.c): Define. + 2018-12-15 Florian Weimer * support/blob_repeat.c (check_mul_overflow_size_t): New function. diff --git a/elf/Makefile b/elf/Makefile index cd0771307f9..43f625af056 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -186,7 +186,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-tlsalign tst-tlsalign-extern tst-nodelete-opened \ tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-noload \ tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \ - tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note + tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \ + tst-unwind-main # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -1484,3 +1485,5 @@ tst-libc_dlvsym-static-ENV = \ $(objpfx)tst-libc_dlvsym-static.out: $(objpfx)tst-libc_dlvsym-dso.so $(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so + +CFLAGS-tst-unwind-main.c += -funwind-tables diff --git a/elf/tst-unwind-main.c b/elf/tst-unwind-main.c new file mode 100644 index 00000000000..d1236032d77 --- /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 + . */ + +#include +#include +#include + +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); +} diff --git a/sysdeps/riscv/start.S b/sysdeps/riscv/start.S index 4635ddb5eb8..2d6f06e6305 100644 --- a/sysdeps/riscv/start.S +++ b/sysdeps/riscv/start.S @@ -43,6 +43,10 @@ __libc_start_main wants this in a5. */ ENTRY (ENTRY_POINT) + /* Terminate call stack by noting ra is undefined. Use a dummy + .cfi_label to force starting the FDE. */ + .cfi_label .Ldummy + cfi_undefined (ra) call .Lload_gp mv a5, a0 /* rtld_fini. */ /* main may be in a shared library. */ @@ -54,7 +58,8 @@ ENTRY (ENTRY_POINT) lla a4, __libc_csu_fini mv a6, sp /* stack_end. */ - tail __libc_start_main@plt + call __libc_start_main@plt + ebreak END (ENTRY_POINT) /* Dynamic links need the global pointer to be initialized prior to calling -- 2.19.1