From patchwork Fri Feb 23 17:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Remus X-Patchwork-Id: 20883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp721847dyb; Fri, 23 Feb 2024 09:12:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWrMMhfqk5jPLd2M75/cPTu8MRfJSeV8pEjmVijHLM0hxYXR1XCFbb5bOWnjgFV2SUpFq/4Valu0MIRyvOyc/fyC1LcUQ== X-Google-Smtp-Source: AGHT+IHT9Crm+0tOzoWAWKNJQLgWZWqmOzEIZtfdGcGTL8D4l7h/eUYO3mEQuqo4kv8nP3ZCNYJl X-Received: by 2002:a05:620a:3bd6:b0:787:9720:908 with SMTP id yf22-20020a05620a3bd600b0078797200908mr450830qkn.32.1708708345822; Fri, 23 Feb 2024 09:12:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708708345; cv=pass; d=google.com; s=arc-20160816; b=VSiSJUN57dFzKNpWm6TNW0pp37y4HpJ8+nKfXBGlPpVjR5GvBRncrqwkihUPGr041C C5recoAtJvxJwC1+tjr+daXuzFcBoouVQ6papZOaLKgOCn/zQnnClueiekXYzZ0ww5o+ f+uWdzRNttGAJFhDyJIRpbY8turgNGTE9aywdj3ktakIz+mYKsPFRVKi9ZzgHEUWdHoB LLdU9jUyxyV+Py5aVGVLjJUH1006mYbiCHeHK8Q3hUmgneQXVJmo9iB+ArEdkGHJ3kKC xlU/jIpzihyA/6yyi0krkSfxHAitLOQrgLi5C02mvnz+br0jRur2lUhFNv6v6DyW2Nt5 wnWg== 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=JmSCVbF8UXZOc8GZ1o/HJKbZAUSqeDVggRvfU0Ide4o=; fh=vTbGg4wY0rLaolKO+EtTu7rlJzNAP3iHbUH+MVoijcQ=; b=K3pCSsMviKe6WL0HIZfRrA3oMdfHw+j7yawbxzNAdelS7y90APUejBI/6QCB1eUpGa AndqmzaPUvnHJRf2D7vrKafJIzxrmP9pDsRTlSgiQL5bfyTg2nckB1JtpGVNv+C2k2Eq PagOz0nsh0HYL+C/zY8hLjybDycx8yfI+vnrrD/ZhEfPmZTummHV/0LKEtCfRaEVe5Y8 7vse2w7Pql+WSMeQzS5zHG3qR1fkeNinyTORVPLa3YyU0bx4Vb1y5gdpeWRAd3sPbenA AqNK1pNuMJQJQmdD3iz908FJz9APK1k6vRrsTHKN4YICtMs5DZHpu9IBx3ethnpO2Syk Mtjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=KFUyIEYY; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id pi10-20020a05620a378a00b007871e945b29si15462696qkn.251.2024.02.23.09.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 09:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=KFUyIEYY; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 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 76F143858282 for ; Fri, 23 Feb 2024 17:12:25 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 593CF3858021 for ; Fri, 23 Feb 2024 17:09:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 593CF3858021 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 593CF3858021 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708708189; cv=none; b=DQxbb1cDK55Y9HpE/AAsLJLx5AB3gAzbkd21ZSCn9PSACQQLpuOAJmxmvhccvugonSX+xIo/2FBJIQKdbmU4z0f8rETjtG6uf03vFXK5nLkzhCPi2Hoiqgo7rtKjAMhiZmCuPJRiA3kZA9TuUR5+TwIASR4iO+OR9O2ZZb5aktk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708708189; c=relaxed/simple; bh=miUF0VAM2yV3HogS/iIqSQuQlb5jeXDhkdCjZXXw2BQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=chO27b21mSMsrh+ARdvZFGu+R28nSw3b8HUBjkKZdk2i9bdQ9TRIPi+1i85UdYUroE9yYY72qib8fz5XMuPidHhkiowQdYiJcnhvwdPWlc9i8ydolgnivm+wDQP72bqACeD71wWXgtv8OhRolQsCwSWFyIn2pP51zWWFq5unjK4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41NGVd6J017750; Fri, 23 Feb 2024 17:09:42 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=JmSCVbF8UXZOc8GZ1o/HJKbZAUSqeDVggRvfU0Ide4o=; b=KFUyIEYY/yQ+MZeKLFozbxEpbRqKeXcT5aZBDsdS5wdDkIrn6qk8wqpyR6MbL3nooHSw yeBq4NUKwe6UoZgJfobbItxSOpJdI+zRdlBmarQv0o7suaIxG51NMS2w/KqoYNd1QwqV OCyOB58mosD3uKgVqqbTz6ogDtHcK9+dsuPgqTuPFdOkTnY9jsHniPc3x/kVSgC5upAE qu+trpgUQyolmZt5PY/O4T6PH0jzr0vyQd8AzYHVi6QuiUwvP4+4Tui5Bdp9TBsFtcWj OD47uL55v76hvU/u2R5WoxM+DRC/xgSTXEfWpmb2VBWmhsBVl6Sncx4paD2YO3QiQdvv kg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wexej9tye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 17:09:39 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41NGdx4R003623; Fri, 23 Feb 2024 17:08:08 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wb74u71wr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 17:08:07 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41NH82hk42336902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Feb 2024 17:08:04 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 62B162004B; Fri, 23 Feb 2024 17:08:02 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3205820040; Fri, 23 Feb 2024 17:08:02 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 23 Feb 2024 17:08:02 +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: Fri, 23 Feb 2024 18:07:51 +0100 Message-Id: <20240223170800.3993092-1-jremus@linux.ibm.com> X-Mailer: git-send-email 2.40.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: tsCXLhx2M44wYaxRopC4rwYvZi9CjAqG X-Proofpoint-GUID: tsCXLhx2M44wYaxRopC4rwYvZi9CjAqG 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-23_03,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 adultscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402230124 X-Spam-Status: No, score=-6.6 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: 1791710562457597269 X-GMAIL-MSGID: 1791710562457597269 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 Changes v1 -> v2: - Resolved a regression reported by Linaro-TCWG-CI on AArch64 in one of the generic ld SFrame test cases. The test case contained a .cfi_def_cfa directive, specifying a CFA base register number that is not necessarily a SFrame SP/FP register number on all architectures. This caused the changes from patch 6 to skip SFrame FDE generation on AArch64 (and s390x aswell) with a warning, causing the test case to fail. 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 +- ld/testsuite/ld-sframe/discard.s | 1 - libsframe/doc/sframe-spec.texi | 8 +- libsframe/sframe-dump.c | 10 ++ 38 files changed, 549 insertions(+), 32 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