From patchwork Mon Apr 25 07:19:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 614300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3qtd0D33QDz9t60 for ; Mon, 25 Apr 2016 17:19:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=hd7RdSYa; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:cc:from:subject:message-id:date :mime-version:content-type; q=dns; s=default; b=Hgt0luMNNcpw/Asg WTA4pMhHy/JQ8TaKlTtySoHoqggLxtsp+iSIXZ4v+RQwbvGB57BZ6tBgXlOaGjBJ rgbz3sPH94lMORUaOtd/7rGEfNz+xLMls4CN7q9dUkq+Xb+5KSQszyP0U8oEXemh YvrePQIkUoqHNvFuq5tt6Pz43AQ= 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:to:cc:from:subject:message-id:date :mime-version:content-type; s=default; bh=LTLO+QVK7SSL8fvmem/mm0 GEiNk=; b=hd7RdSYaTJpIJ7YXm1PylWrsC1VTjNzy8Z6dyhxNks74uFboQEPN4l 0vWheDhVHA3wS3FmqL4fYNCPqomh7Ix0IJ3i34gljNCXJhdKsuafGxJFyIBixh7M pLc3/EjMinfnX/T2rSzjoxBv1OYrOJSJ+uHpglhugJ0zTD7elCf60= Received: (qmail 78240 invoked by alias); 25 Apr 2016 07:19:48 -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 78227 invoked by uid 89); 25 Apr 2016 07:19:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=fde, Hx-languages-length:2145, alter, 2016-04-25 X-HELO: relay1.mentorg.com To: GNU C Library CC: Sandra Loosemore From: Chung-Lin Tang Subject: [PATCH, nios2, committed] Fix stdlib/tst-makecontext regression for Nios II Message-ID: <05c99014-2aac-3202-b8d8-784cf1246f15@codesourcery.com> Date: Mon, 25 Apr 2016 15:19:31 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 This patch fixes the backtrace infinite loop regression for the stdlib/tst-makecontext testcase that happened for a number of targets, Nios II included. Most archs fixed this by a combination of removing FDEs and/or launching the makecontext wrapped function from the trampoline, but this one is slightly different. Basically FDE lookup does not use exactly the return address, but rather (return_address - 1). This causes the use of ra == &__start_context (beginning of function), to actually lookup the FDE of the prior __setcontext instead. Since the CFIs in __setcontext has nothing to alter/restore/undefine RA, it just keeps spinning at that FDE until the testcase backtrace callback's counter is up, and asserts fail. So this regression can be fixed by simply adding an NOP before __startcontext, which allows the FDE lookup to just fail and return NULL there, and close the backtrace. Tested and committed. 2016-04-25 Chung-Lin Tang * sysdeps/unix/sysv/linux/nios2/setcontext.S (__startcontext): Add nop before __startcontext, add explaining comments. diff --git a/sysdeps/unix/sysv/linux/nios2/setcontext.S b/sysdeps/unix/sysv/linux/nios2/setcontext.S index f10e8ff..177aa4b 100644 --- a/sysdeps/unix/sysv/linux/nios2/setcontext.S +++ b/sysdeps/unix/sysv/linux/nios2/setcontext.S @@ -85,6 +85,18 @@ ENTRY(__setcontext) PSEUDO_END (__setcontext) weak_alias (__setcontext, setcontext) + /* We add an NOP here to separate between __setcontext/__startcontext. + The wanted behavior that happens is: when unwinding from a function + called inside a makecontext() context, FDE lookup will use + '&__startcontext - 1', then returns NULL for no FDE found, + and immediately ends the unwind, in a normal fashion. + + If this NOP word does not exist, FDE lookup just repeatedly finds + __setcontext's FDE in an infinite loop, due to the convention of + using 'address - 1' for FDE lookup. Modifiying/deleting the below + __startcontext's FDE has no help on this. */ + nop + ENTRY(__startcontext) mov r4, r16 bne r4, zero, __setcontext