From patchwork Thu Feb 22 16:01:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Remus X-Patchwork-Id: 20804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp35329dyb; Thu, 22 Feb 2024 08:02:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqGyboWDEA5M/s50G+wLXgdCYBfWstI3Yjl6ujEPTx0iws/qJTXDXr9EAJhPUr+UsOvZzGOZprrXaUrygPRnsV99EQMA== X-Google-Smtp-Source: AGHT+IFv5e3FEfGTOkwqlRva/rQJ7H5mTLk990tl8BxuhHfwL7ayTEF1/5Zz26nbrR4W7+T2+w1I X-Received: by 2002:a5d:5cd1:0:b0:33d:8754:80bf with SMTP id cg17-20020a5d5cd1000000b0033d875480bfmr1800179wrb.13.1708617738909; Thu, 22 Feb 2024 08:02:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708617738; cv=pass; d=google.com; s=arc-20160816; b=GzlEH82pbZuekz+sx9dpn3HTvMqECtgpv19ISd7O566Rqsgoj3GgoSJwja4quvY2fZ JDxF0WzgfMJD5/5kX+50L/WkBc/YgGN+RgFe6BxbzaS8vCJf30mAkO2DwyWCGlh3LFhr 7SBrBVdlXRKHHHnMaVQGBBICI++fbGYtS+HYCtVqTNFBADBMb4fq9bO9DssfAeVGp9++ 37haq+KUN509fdOdxZCk4+hFybRCLQl719hq5geovuOHDwN8sn4yw1s55GOnj9ykp7Tf Gy87TYN4jDjPr17vR9e1a3W4A/Q+OmvePcccd0Imc1EnpG9L3d46R9+39Ec104fMKbAT 9i6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:message-id:date:subject:cc:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=/k77qyBKs9jELU5CvM64IkuWYCrOGghk1Ma1IW5GJc0=; fh=vTbGg4wY0rLaolKO+EtTu7rlJzNAP3iHbUH+MVoijcQ=; b=MgVv8q/0PTsAsBg9qPolu8fcS8aUc5i4t3DUXKqQMvftv54/3815UYPJaH6uXvfF4s XCuWM31NF7TgjCNkePccVTSjZfmFEZl/zNW2ibxvbzfh//g+Kr9Tg7JejSfq3mhaQNkp PagRcWhYS/E5Ib1HWeaTS3n01MOS/jRZKKbYP4Qkv16a+iKR4cvuLIhVJwQzxfjbfJ47 1s8j1MiJb5yuXmBWEYI2NOFkresBBlEHbcaD1h/y/0ZMJlvXIs5heMKPDZrLHollJbnX NMzvxfviozTFIjAlZTNzpjxn5eC8D4NPE1slFvZaIY3X1IQZln6PbFoBaRY48xF338Iw hZkQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Zewarpty; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r16-20020a5d4950000000b0033aeaa748c0si7875183wrs.436.2024.02.22.08.02.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 08:02:18 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Zewarpty; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0746D38582B0 for ; Thu, 22 Feb 2024 16:02:17 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 234073858C32 for ; Thu, 22 Feb 2024 16:01:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 234073858C32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 234073858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708617711; cv=none; b=aCD6GL1OKSeGErgIWwy0wWUr0w/pfBuNQgHx2N5flqrH4NokyS3K4YhRWRVkVVch8iaV92fElUYKTgynRGueXkYYP0x2uIcOlcPT3DGCNbeTOUhFwm23gsO7qOYwv+rdZ6d1ifvlBwy7YTl5wiFk88K9r9DMrCgb5y3+3l+Ic74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708617711; c=relaxed/simple; bh=l4c21YnnPiOhWl6xgE1PKqEiIJVGKwAoR+jDsOhtkos=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=c+gOoSDfsfBivrczCaEif/1V/Q1x66XnGor7vZkAdGskwwSdWNxALRXw1gnpPHZ/JrgkMH6uoMtrf8TAXZEKphmKWTa95JlTt9kGzfabp0/ERzujosMgNneI39E+gSgd53604dCQFiXLKn+S7e3HHvMv++9hYEqhYiJnnVACBYI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41MFv7T3031899; Thu, 22 Feb 2024 16:01:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=/k77qyBKs9jELU5CvM64IkuWYCrOGghk1Ma1IW5GJc0=; b=ZewarptyFXMlRomz/4lSUph8oKROlVivl2vzW3kHbJfldtwlVPf26HEuwAQARwz4FYoO W/LfTJ/Nw+QWG8WMjPH8XM9AwjU/ts23J8dzL0r4SwNOWkjzPIQVooapweesx45aXTOr NBCMQQMQM2DUYkxF6PVT48Wi4/e/f5zfbzpgL7Q1YBih92kbpYLHQpCFGj1bBhCaEU9K HE7vUOZrKt9E4uxbYZ3i8MRq0mvlWpd0SvVRZIf4xgWUVVnZqJ93AdBDmmljglZiwqWS ETyemYBccj9S2yBIq6G+gsKJCWHx3kdv5G8M8pBFI+3pSpo5p2zefX0HiqShfGp2RrYp 0g== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3we9c00812-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 16:01:33 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41ME6vnK013463; Thu, 22 Feb 2024 16:01:31 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3wb7h0qeyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 16:01:31 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41MG1Pti7471824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Feb 2024 16:01:27 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C12E92005A; Thu, 22 Feb 2024 16:01:25 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A06C22004F; Thu, 22 Feb 2024 16:01:25 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 22 Feb 2024 16:01:25 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org, Indu Bhagat Cc: Jens Remus , Andreas Krebbel Subject: [RFC PATCH 0/9] s390: Initial support to generate SFrame info from CFI directives in assembler Date: Thu, 22 Feb 2024 17:01:14 +0100 Message-Id: <20240222160123.2554459-1-jremus@linux.ibm.com> X-Mailer: git-send-email 2.40.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: sZjteAOewVwCHzQOKGaSBVV3gPG-_4lQ X-Proofpoint-GUID: sZjteAOewVwCHzQOKGaSBVV3gPG-_4lQ X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_11,2024-02-22_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402220127 X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791615554561132456 X-GMAIL-MSGID: 1791615554561132456 This patch series adds initial support to the assembler on s390x to generate SFrame stack trace information from CFI directives. It is largely based on the respective AArch64 support. Please be aware that the SFrame support for s390x provided by patch 9 of this series still has some open issues, which need to be addressed. Any ideas or assistance to overcome the current SFrame limitations listed below and in the patch description are very welcome. Patches 1-8 are generic cleanups and enhancements to the generation of SFrame information in the assembler. Patch 9 adds the initial s390x support and is purely RFC. Patches 1-3 are minor cleanups/enhancements to the existing SFrame support on AArch64 and x86 AMD64. Patch 4 enables readelf/objdump to dump the SFrame fixed offsets from CFA to the frame pointer (FP) and return address (RA). Patch 5 enhances an SFrame warning message to print the human readable DWARF call frame instruction name. Patch 6 and 7 resolve issues that cause the assembler to either generate bad SFrame FDE or to silently skip it. Both issues would be triggered by s390-specific SFrame error test cases introduced by patch 9. Patch 8 adds verbose assembler warning messages when generation of SFrame FDE is skipped. Patch 9 adds initial support to the assembler on s390x to generate SFrame stack trace information from CFI directives. Due to differences in the s390x ELF ABI [1] compared to the AArch64 and x68 AMD64 ELF ABIs and the simplified assumptions of the current SFrame format V2 there are several unresolved issues (see also patch description): - GCC on s390x may save the frame pointer (FP; r11) and/or return address (RA; r14) registers in other registers (e.g. floating-point registers) instead of saving them on the stack. SFrame currently only supports FP/RA tracking on the stack. This can be reproduced by using a small inline assembler statement, that specifies r11 (FP) and/or r14 (RA) as output operand(s). It can also be observed when compiling a minimal C program using GCC without optimizations. - The s390x ELF ABI does not specify a frame pointer register number. Currently GCC and clang both mostly use register r11, but GCC can also be observed to use r14. On s390x a compiler may choose about any register number for that purpose and declare it using CFI directives. This can be observed when compiling glibc, as parts of its hand- written assembler uses register r12 as frame pointer. - GCC on s390x may copy the return address (RA) from register r14 to another register and even use that to return to the caller. Effectively this is just a specialization of the first bullet. If my understanding of the current SFrame format is not wrong I assume the following enhancements to SFrame would be required to fully support the s390x architecture: - Tracking of the CFA base pointer register number specified in CFI directives .cfi_def_cfa and .cfi_def_cfa_register. - Tracking of SP, FP, and RA register contents being saved in other registers instead of on the stack, as specified by CFI directive .cfi_register. - Both would effectively require support in SFrame to track all of the 17 registers specified as saved in the s390x ELF ABI (r6-r13, r15, and f8-f15), since SP, FP, and RA could be saved in one of those and thus would need to be restored during unwinding. - Potentially optional, if the use in glibc could be removed: Tracking of SP, FP, and RA register contents being CFA+offset, as specified by .cfi_val_offset. [1] ELF ABI s390x Supplement: https://github.com/IBM/s390x-abi/releases Thanks and regards, Jens Jens Remus (9): x86: Remove unused SFrame CFI RA register variable aarch64: Align SFrame terminology in comments to specs and x86 sframe: Enhance comments for SFRAME_CFA_*_REG macros readelf/objdump: Dump SFrame CFA fixed FP and RA offsets gas: Print DWARF call frame insn name in SFrame warning message gas: Skip SFrame FDE if CFI specifies non-FP/SP base register gas: Warn if SFrame FDE is skipped due to non-default return column gas: User readable warnings if SFrame FDE is not generated s390: Initial support to generate .sframe from CFI directives in assembler gas/config/tc-aarch64.h | 6 +- gas/config/tc-i386.c | 1 - gas/config/tc-i386.h | 4 +- gas/config/tc-s390.c | 55 +++++++ gas/config/tc-s390.h | 31 ++++ gas/gen-sframe.c | 146 ++++++++++++++++-- gas/gen-sframe.h | 2 + .../gas/cfi-sframe/cfi-sframe-common-1.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-2.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-3.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-4.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-5.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-6.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-7.d | 2 + .../gas/cfi-sframe/cfi-sframe-common-8.d | 2 + .../gas/cfi-sframe/cfi-sframe-s390-1.d | 23 +++ .../gas/cfi-sframe/cfi-sframe-s390-1.s | 37 +++++ .../gas/cfi-sframe/cfi-sframe-s390-2.d | 23 +++ .../gas/cfi-sframe/cfi-sframe-s390-2.s | 37 +++++ .../gas/cfi-sframe/cfi-sframe-s390-err-1.d | 15 ++ .../gas/cfi-sframe/cfi-sframe-s390-err-1.s | 37 +++++ .../gas/cfi-sframe/cfi-sframe-s390-err-2.d | 15 ++ .../gas/cfi-sframe/cfi-sframe-s390-err-2.s | 37 +++++ .../gas/cfi-sframe/cfi-sframe-s390-err-3.d | 15 ++ .../gas/cfi-sframe/cfi-sframe-s390-err-3.s | 6 + .../gas/cfi-sframe/cfi-sframe-s390-err-4.d | 15 ++ .../gas/cfi-sframe/cfi-sframe-s390-err-4.s | 5 + .../gas/cfi-sframe/cfi-sframe-x86_64-1.d | 1 + gas/testsuite/gas/cfi-sframe/cfi-sframe.exp | 13 +- gas/testsuite/gas/cfi-sframe/common-empty-1.d | 4 +- gas/testsuite/gas/cfi-sframe/common-empty-2.d | 4 +- gas/testsuite/gas/cfi-sframe/common-empty-3.d | 3 + .../gas/scfi/x86_64/scfi-cfi-sections-1.d | 2 + .../gas/scfi/x86_64/scfi-dyn-stack-1.d | 2 + include/sframe.h | 7 +- libsframe/doc/sframe-spec.texi | 8 +- libsframe/sframe-dump.c | 10 ++ 37 files changed, 549 insertions(+), 31 deletions(-) create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-1.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-1.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-2.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-2.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-1.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-1.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-2.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-2.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-3.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-3.s create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-4.d create mode 100644 gas/testsuite/gas/cfi-sframe/cfi-sframe-s390-err-4.s