From patchwork Thu Oct 25 09:53:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 988995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-96725-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="IDSBB2/H"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gjBb6WT9z9sBQ for ; Thu, 25 Oct 2018 20:53:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=r5Xbkzy1DYZ4rFky3VwlQnEm9PUTk 9xEa2ebxgDB1Xl0a8L7YgfoUhENeweLl7BUXn6WFTsUZmxamE53Tz1guaQ8LSPn1 rK0Y7MPqJygHKeZZc6riM+PcPrsaj7kvalKNhZYLzZQh/+/BAHUKs262FHNlfcne 2maxoDP7W5CcBg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=gwrHsPOPRfDJ/571LCfeGWZlBHc=; b=IDS BB2/HNdLu++QUxkVbgi1PXAvIa83E0RRCeAlB/Z4TLhdLPZlyyfXdMPtwmx2V8XQ b0jAVYTW2P4CTBAY9aGk6+z4DyQFpie/sFR0c2s0mHvkHC/m/sn6BrQsnNjsLSQ4 k5/WWdzvZKyLnLILIEt3AnKc7UvqyD8gwh/grUos= Received: (qmail 93416 invoked by alias); 25 Oct 2018 09:53:53 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 93334 invoked by uid 89); 25 Oct 2018 09:53:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.2 spammy=unwinding, 2191, 2.19.1 X-HELO: mx1.suse.de From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] RISC-V: properly terminate call chain X-Yow: Yow! Date: Thu, 25 Oct 2018 11:53:44 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 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. [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. --- elf/Makefile | 4 +++- elf/tst-unwind-main.c | 38 ++++++++++++++++++++++++++++++++++++++ sysdeps/riscv/start.S | 7 ++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 elf/tst-unwind-main.c diff --git a/elf/Makefile b/elf/Makefile index 455ec730fc..d277d34b17 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -187,7 +187,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ 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-unwind-ctor + tst-unwind-ctor tst-unwind-main # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -1495,3 +1495,5 @@ $(objpfx)tst-libc_dlvsym-static.out: $(objpfx)tst-libc_dlvsym-dso.so $(objpfx)tst-big-note: $(objpfx)tst-big-note-lib.so $(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-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 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 + . */ + +#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 4635ddb5eb..ba3e2cf16c 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 + unimp END (ENTRY_POINT) /* Dynamic links need the global pointer to be initialized prior to calling