From patchwork Mon Dec 4 15:05:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 844285 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-87773-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="U9eqIwWp"; 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 3yr7Vj2M7Bz9t9j for ; Tue, 5 Dec 2017 02:06:04 +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:to:from:subject:date:mime-version:content-type :message-id; q=dns; s=default; b=SjNcUibg/innuHjWWnvb7TBoUaAL7c0 Iq/iucjnZX5o/7mKdDEwT9CC7FV+B7HMS+QRCl2Qzt3lhhyJCs58C4h+Dw4DNtsF tdZO/83m08+NLpHQDpAq7xoPYunsAhU9K6AzZmQ5oL8Fonk2JLhO6TxPnXNz8HpT 9iB/mDXilRaI= 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:from:subject:date:mime-version:content-type :message-id; s=default; bh=fvj5e7AX/qXmURlwIU6ku4zGakE=; b=U9eqI wWpLcASsXay1uZWDVBfZLvJpBSnNEEBcixc57aCgGI5ZCQjs4qnriQQ3s21xtT54 1OYkitbA4jon1svfrdS4Q016UzEZ+Hll0NaEBKrG+uMgkeU0Tn6Z5696KVNChJrU yS2nbcXvsv7rmpyBXJu66HDtTcNGLc36AxXeuk= Received: (qmail 104196 invoked by alias); 4 Dec 2017 15:05:58 -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 104181 invoked by uid 89); 4 Dec 2017 15:05:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=ahi, 8715 X-HELO: mx0a-001b2d01.pphosted.com To: GNU C Library From: Stefan Liebler Subject: [PATCH] S390: Add CFI rule in _dl_runtime_resolve[_vx] for unwinding. Date: Mon, 4 Dec 2017 16:05:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17120415-0040-0000-0000-000004163D8C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120415-0041-0000-0000-000020B930F8 Message-Id: <242f3a72-516b-5aed-603f-b55cc21fe361@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-04_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712040219 Hi, In _dl_runtime_resolve[_vx], unwinding fails after the new stack frame is created as there is no CFI rule for r15. This is also observable in GDB: Backtrace stopped: previous frame inner to this frame (corrupt stack?) Therefore this patch is now storing r15 on stack and is using cfi_offset rule. The stmg/lmg instruction is used to store/load r14 and r15 with one instruction. On 64bit, the offsets of the fprs have moved to store r15 directly after r14. On 31bit, the r14/r15 is now stored between the other gprs and fprs as the space wasn't used. Okay to commit? Bye. Stefan ChangeLog: * sysdeps/s390/s390-64/dl-trampoline.h (_dl_runtime_resolve): Store r15 on stack and add cfi rule. * sysdeps/s390/s390-32/dl-trampoline.h (_dl_runtime_resolve): Likewise. commit 54dea059004a57e1a415472f703c2b93eeacfc82 Author: Stefan Liebler Date: Mon Dec 4 15:32:46 2017 +0100 S390: Add CFI rule in _dl_runtime_resolve[_vx] for unwinding. In _dl_runtime_resolve[_vx], unwinding fails after the new stack frame is created as there is no CFI rule for r15. This is also observeable in GDB: Backtrace stopped: previous frame inner to this frame (corrupt stack?) Therefore this patch is now storing r15 on stack and is using cfi_offset rule. The stmg/lmg instruction is used to store/load r14 and r15 with one instruction. On 64bit, the offsets of the fprs have moved to store r15 directly after r14. On 31bit, the r14/r15 is now stored between the other gprs and fprs as the space wasn't used. ChangeLog: * sysdeps/s390/s390-64/dl-trampoline.h (_dl_runtime_resolve): Store r15 on stack and add cfi rule. * sysdeps/s390/s390-32/dl-trampoline.h (_dl_runtime_resolve): Likewise. diff --git a/sysdeps/s390/s390-32/dl-trampoline.h b/sysdeps/s390/s390-32/dl-trampoline.h index 19776ee..2d6a674 100644 --- a/sysdeps/s390/s390-32/dl-trampoline.h +++ b/sysdeps/s390/s390-32/dl-trampoline.h @@ -51,12 +51,13 @@ _dl_runtime_resolve: cfi_offset (r3, -60) cfi_offset (r4, -56) cfi_offset (r5, -52) + stm %r14,%r15,48(%r15) + cfi_offset (r14, -48) + cfi_offset (r15, -44) std %f0,56(%r15) cfi_offset (f0, -40) std %f2,64(%r15) cfi_offset (f2, -32) - st %r14,8(%r15) - cfi_offset (r14, -88) lr %r0,%r15 lm %r2,%r3,24(%r15) # load args saved by PLT #ifdef RESTORE_VRS @@ -90,13 +91,11 @@ _dl_runtime_resolve: .machinemode "zarch_nohighgprs" vlm %v24,%v31,96(%r15) # restore vector registers .machine pop - ahi %r15,224 # remove stack frame - cfi_adjust_cfa_offset (-224) + lm %r14,%r15,272(%r15)# remove stack frame and restore registers #else - ahi %r15,96 # remove stack frame - cfi_adjust_cfa_offset (-96) + lm %r14,%r15,144(%r15)# remove stack frame and restore registers #endif - l %r14,8(15) # restore registers + cfi_def_cfa_offset (96) ld %f0,56(%r15) ld %f2,64(%r15) lm %r2,%r5,32(%r15) diff --git a/sysdeps/s390/s390-64/dl-trampoline.h b/sysdeps/s390/s390-64/dl-trampoline.h index e1f95e2..29bdbb1 100644 --- a/sysdeps/s390/s390-64/dl-trampoline.h +++ b/sysdeps/s390/s390-64/dl-trampoline.h @@ -47,16 +47,17 @@ _dl_runtime_resolve: cfi_offset (r3, -88) cfi_offset (r4, -80) cfi_offset (r5, -72) - std %f0,104(%r15) - cfi_offset (f0, -56) - std %f2,112(%r15) - cfi_offset (f2, -48) - std %f4,120(%r15) - cfi_offset (f4, -40) - std %f6,128(%r15) - cfi_offset (f6, -32) - stg %r14,96(15) + stmg %r14,%r15,96(%r15) cfi_offset (r14, -64) + cfi_offset (r15, -56) + std %f0,112(%r15) + cfi_offset (f0, -48) + std %f2,120(%r15) + cfi_offset (f2, -40) + std %f4,128(%r15) + cfi_offset (f4, -32) + std %f6,136(%r15) + cfi_offset (f6, -24) lmg %r2,%r3,48(%r15) # load args for fixup saved by PLT lgr %r0,%r15 #ifdef RESTORE_VRS @@ -86,17 +87,15 @@ _dl_runtime_resolve: .machine "z13" vlm %v24,%v31,160(%r15)# restore vector registers .machine pop - aghi %r15,288 # remove stack frame - cfi_adjust_cfa_offset (-288) + lmg %r14,%r15,384(%r15)# remove stack frame and restore registers #else - aghi %r15,160 # remove stack frame - cfi_adjust_cfa_offset (-160) + lmg %r14,%r15,256(%r15)# remove stack frame and restore registers #endif - lg %r14,96(%r15) # restore registers - ld %f0,104(%r15) - ld %f2,112(%r15) - ld %f4,120(%r15) - ld %f6,128(%r15) + cfi_def_cfa_offset (160) + ld %f0,112(%r15) + ld %f2,120(%r15) + ld %f4,128(%r15) + ld %f6,136(%r15) lmg %r2,%r5,64(%r15) br %r1 cfi_endproc