From patchwork Thu Dec 14 20:17:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 178894 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8822098dys; Thu, 14 Dec 2023 12:17:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1xw/bm4zJN7Yza+f4GpnrS3en18vuPiR7u05aQoPGoxFdEnlxJcntc6tWHrZNXnql1zhG X-Received: by 2002:a05:6102:c47:b0:464:8f00:c5cf with SMTP id y7-20020a0561020c4700b004648f00c5cfmr8318559vss.19.1702585068001; Thu, 14 Dec 2023 12:17:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702585067; cv=pass; d=google.com; s=arc-20160816; b=J+0qb5FQ0Y3aubzXDdDFS7HD386JRLHH7kn/XF3vm5GKAhSAbrA6CzrKBs8rj8IiLt puexI9u4CfZY8UF92T8vJ3HrJgA0GXwQwao01R/s9v0CqQL04EdGFm42THW6XZkdkWbw VuybMTZ7BF/ARoTNN4W8s0aSCTtM3mcw22HqFVEEaUQUdU5x4sbffs2TCFmqpPz8Taya pH72aB7hru9UHM4Tu9KrccXFBbPu+pUHxdeb9/OPvYbS1zv23MNVzNHfaaX6fVJQWFAh PO4pkPeqNgrB/2RKwIpRrhXpZSclRhIpDR1btAZiVirlwcSo6Xd2y8XHjJanMxlXAMUO 8o8A== 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:user-agent :message-id:date:organization:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=+g39pkg0+b4qOyQXTKAmoorCcmrjZJANQfiuNm8iJLI=; fh=bNk5JXvdI7C6mAB7KZhcMA/BpQtA2n2NRbo91aS1Hts=; b=iecu6gTTUz2X1NAun/bxjSp2LugIFvhpCg40/7J80L9cyu4zdHue6QegqY0p3QjeC4 fUUzwmcQnLPYWQN5k2n53Jo5N6nwOaJ8N4Z5cmwyZ+mJWa99RnA5eayOvaMjTz+GLXIJ tacgyAZCjGItSioOxvVXACwaL3Zabgzg90FZnuOp0ys7VZ4Co9NCPQeLvO/j3XAs5JRj qZB1HWw8Rhfmv5M1HG6v4ZE0p+v9pV203tFMF8P04tNZxvRhWlX1E+dBgyJo6o6oAT2V WKiC8BDgY0fSVm945iu8uc9bF3nXv1ZjJjySiXBVKdDB8VFG8i7qNgOV8taJdQubXyOt FPUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=cEeYNVMK; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u9-20020a67f509000000b0046487a3a429si3079305vsn.162.2023.12.14.12.17.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:17:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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=@adacore.com header.s=google header.b=cEeYNVMK; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACCB93861896 for ; Thu, 14 Dec 2023 20:17:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 0ADE53858D20 for ; Thu, 14 Dec 2023 20:17:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0ADE53858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0ADE53858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702585045; cv=none; b=ULXW6Sx1XaPSN0QQJKyCvwi5V+76EyeriwKOL45umEKJlpE/L8QdX8yeyPLK7QN/7IHbzbdM3PtcGDMovK/R80RqiUNc0vyWpQbwvvobix7/1PubZfDK1LaQfsNVhHFUZ+pyafM0g74fs8zIKvSFvxe/QpMHYYNB72OAdjwiPno= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702585045; c=relaxed/simple; bh=HsTrpCdEoSqi+UXRTdU0nDiOIv5iZpAJkhmhJ6lfDhc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AJ8TinNsf6X8qXhy8IxDjFELEVOn0Kcf8gWjK0Ep0MdSmVU9ptPTQpZwyeG2Ss+J+lufsC6KlAfTBz1znlp0edZ9m98jB9eTy5MtCCyEFwDnZP0U9OiAiutrNDCnU6n04yY3m5E1M+0BMsp0BuKypdZUronijKlRpbrAZG4SX+k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6cec976b197so5147842b3a.0 for ; Thu, 14 Dec 2023 12:17:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702585043; x=1703189843; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=+g39pkg0+b4qOyQXTKAmoorCcmrjZJANQfiuNm8iJLI=; b=cEeYNVMK37clH6tLBmjiFVq9DES0adzMk2EkFpCtZU1+/GHgOxAmugMd4EJ9Y8S7ev 3AHkMyv/jKI4eML+tothAQk6vVIYssYdC0yTuTDiWHOY88fDryIQc36fSRmpujq76VV4 anw6zaSFuJC0IFjf4OrtNrGFZE6n0IybawVPy/XVNcgjLroFPMYPGqXwxQhh6/iGxmQL KxzhbF4vroPHfEpfTYE+A5PgZod7wTWZPBBCKelfr62fOSx7+24JBRxk/ndlSbJpjZ5M 5FJhvPznYJt9I7riAMrUQN24I9iVS28QTsd/wY0ZGrxcGCF6QgGpl+f9OnqqTM7sdBuS hACw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702585043; x=1703189843; h=mime-version:user-agent:message-id:date:organization:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+g39pkg0+b4qOyQXTKAmoorCcmrjZJANQfiuNm8iJLI=; b=kGjN9JC2uoHa+Qdh9+6dQv/18ptMrLaza9GsgtGkMmApMLGofZtmSlFzgIvsRBakNU /9iGsw6AR2sIEUZL3UvvMGwdbyFqQQzZFJRUEk+nTewxurSBxZKX4wO5zKuLPnIemW/F sVUFxwLA4EUQKd1/QCSBu8X2eoVu+5RG+BfzgfWFLVzQEthFqr7zwAXyA7rJT4S/+++j 9fcuL4i6QVHaNEpBIolE4i82cAvIn0TcPRFsUJ83E/Ye664a3YPezsi4xNsS45FDaNCF 4wQVv8wd73eItsFM86s4DN3lnfDZ8hV2jUmU0OJk6Ro8esJhX65XhkJ+ezpmwXi2R5P5 1V2g== X-Gm-Message-State: AOJu0YziNK19WQoPiOS7SXg1jAFR5lBcl/ban6tzG2Oq/+QMXc4ugOiP d0rYfec/e7UENIqBt2zEMEew6GEMy090u9aF8NWOTw== X-Received: by 2002:a05:6a00:1acc:b0:6ce:55b1:caf2 with SMTP id f12-20020a056a001acc00b006ce55b1caf2mr6934875pfv.3.1702585043049; Thu, 14 Dec 2023 12:17:23 -0800 (PST) Received: from free.home ([2804:7f1:2080:cecc:5977:530e:86b5:e7be]) by smtp.gmail.com with ESMTPSA id h17-20020aa786d1000000b006ce7ed5ba42sm12524051pfo.171.2023.12.14.12.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:17:22 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3BEKHAk1489854 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 17:17:10 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Jakub Jelinek , "David S. Miller" , Eric Botcazou Subject: [PATCH #1/2] strub: sparc: omit frame in strub_leave [PR112917] Organization: Free thinker, does not speak for AdaCore Date: Thu, 14 Dec 2023 17:17:09 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785289840027653025 X-GMAIL-MSGID: 1785289840027653025 If we allow __strub_leave to allocate a frame on sparc, it will overlap with a lot of the stack range we're supposed to scrub, because of the large fixed-size outgoing args and register save area. Unfortunately, setting up the PIC register seems to prevent the frame pointer from being omitted. Since the strub runtime doesn't issue calls or use global variables, at least on sparc, disabling PIC to compile strub.c seems to do the right thing. Regstrapped on x86_64-linux-gnu, also testing on sparc-solaris2.11.3. (but it will likely take forever on the cfarm machine; if someone with faster sparc machines could give this a spin and confirm, that would be appreciated.) Ok to install? IIRC this patch gets 32-bit sparc to pass all strub tests, but sparc64 still fails many of them; there's another one for sparc64 that fixes them, and that will improve sparc -m32 as well. for libgcc/ChangeLog PR middle-end/112917 * config.host (sparc, sparc64): Enable... * config/sparc/t-sparc: ... this new fragment. --- libgcc/config.host | 2 ++ libgcc/config/sparc/t-sparc | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 libgcc/config/sparc/t-sparc diff --git a/libgcc/config.host b/libgcc/config.host index 694e3e9f54cad..54d06978a5d2c 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -199,9 +199,11 @@ riscv*-*-*) ;; sparc64*-*-*) cpu_type=sparc + tmake_file="${tmake_file} sparc/t-sparc" ;; sparc*-*-*) cpu_type=sparc + tmake_file="${tmake_file} sparc/t-sparc" ;; s390*-*-*) cpu_type=s390 diff --git a/libgcc/config/sparc/t-sparc b/libgcc/config/sparc/t-sparc new file mode 100644 index 0000000000000..fb1bf1fc29cc4 --- /dev/null +++ b/libgcc/config/sparc/t-sparc @@ -0,0 +1,4 @@ +# This is needed for __strub_leave to omit the frame pointer, without +# which it will allocate a register save area on the stack and leave +# it unscrubbed and most likely unused, because it's a leaf function. +CFLAGS-strub.c += -fno-PIC -fomit-frame-pointer From patchwork Thu Dec 14 21:28:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 178911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8863640dys; Thu, 14 Dec 2023 13:29:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMbu+AKk6iLFWN66/nAcmLpBVJt9dnByYZhlMs2STnHbI5r8r5m1oS0F5GAH4Lf8gb+kX4 X-Received: by 2002:ad4:41d0:0:b0:67e:fd7f:38e1 with SMTP id a16-20020ad441d0000000b0067efd7f38e1mr2988454qvq.62.1702589348553; Thu, 14 Dec 2023 13:29:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702589348; cv=pass; d=google.com; s=arc-20160816; b=PJ1tY3B5nd09hZe5hI+mw1agAJvatjsYeHfKLsdA+X7nZe/Z10RdwVbWrBuAIV1oWg z3h2GHPvuCgmNFj5lcjRGIyif+l2dKcct0hWzCNZTTDkhFZ32/63HNOQOOJvkzLI6/4Q 62rHXuEnobUVE/MyZhHRyfSKPFmxZdZe+CFgZppaP8jlFVdqYERerlOGujsUTV0quVSH YMH9Gfqn2zDB19aJpCdw9kixcRI4M5eWxk0UhHYao/yKI0rvuFAU7FdnO3JGQHeNs+kV R0c96wrr5sL1+xvJhFQJ3PnZ15ZaJTLTL9CvcDApEVGhQgSavsStMKRRZPTLvfVhvxyI Omsw== 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:user-agent :message-id:in-reply-to:date:references:organization:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=JfOMdZkveom3dpPw5atfBAGxaPJBLOoennVUbSB4XUA=; fh=bNk5JXvdI7C6mAB7KZhcMA/BpQtA2n2NRbo91aS1Hts=; b=WWf4d5BjpJdrp1Vw4nAR5o5NszNwTNAg5O8mNxDbtAPYsuZZqu1f7j1sSbmX0sTajT RkL6hA5v/KxKfvNrj5Q/qut1anOydI7EtGGV/CIQnVoafYeXiiuDVgD+v8XwtoidEoWY vXujPSl/WQnbyXcFnsVK5DtrwYCVVAB+rCxgri2L2U7ROnmHOEtx/WprTnlztW9asbcU KJofHTEI8aHZr4N8vgqLtVUzXlbJ6VfQDHb/c4n8rvfI+quOFZ1s9+QJITa1XMGcCW5H o3eF955D9zF8cmbbuESPGk8MWAtqj1MHOTV6X2SBfnyNDDXrjgDbLaZ8L3Y90+vjt8Xw iStg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b="i1S/eEhy"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b18-20020a0ccd12000000b00679e94355f5si1172388qvm.278.2023.12.14.13.29.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:29:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b="i1S/eEhy"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45A7A38618E8 for ; Thu, 14 Dec 2023 21:29:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 29E003858C2C for ; Thu, 14 Dec 2023 21:28:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29E003858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 29E003858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702589324; cv=none; b=JbzqclsmsvMowRBA1+vZve7o1TROzGt3tvfIk9N9EQz/ThLlxkPL+CK/K8Qeq1C8pe26EEpDD0DdSiqQbzbdtM9yixKw+rZwt8qp2GEfCG74DNLxv19lmhSXv9zkGnCRUfyvdc06HOsJVxb1qNYlvugdlkt08AqFaOttZa5MQsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702589324; c=relaxed/simple; bh=vuBk0siOunvGoWyUwOtFd507zlIlQDN7S2NpsVK0+ts=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AiofzNipEjpW7kBjl/NI2RvE4G23nzT0cCVvh4KdE2jE0xzWdC+6l8BITHMJBXYYwjItyypYslVcycKBY6H2bAoZx3254toS1nu3Yr7idAjYtCAsKp6wZ2FWHbo/cn1prxprI8z26O0NrNxvOWUFNrurXQ2wlRAlmRFWposwt5c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5c701bd98f3so35053a12.1 for ; Thu, 14 Dec 2023 13:28:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702589322; x=1703194122; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JfOMdZkveom3dpPw5atfBAGxaPJBLOoennVUbSB4XUA=; b=i1S/eEhy0SWpbzhEFTG8zEsDxa3FIHsnnebqX3nauRiwSfn2Wou/Lo+Ghv8BHVO/pZ omrr0RmX7oIpF79kj3ypTWoopEVBWjrIHaqdNvFYj4cigMQpQqe4S2J+c4WxhK+u5hhK orJ7m/tfLY6olzYVHz3wukwqxXQeilwdUZQfZUC48m5UzfLwc9gs0HoE0zZldwmLhgRh kUYPl4klrksqn0pp1s/hFUQYTCOLaBvcrcIESNS1+UfjUadSA+BMj9++yV8bToW/VDp6 BIIVem1+uyu4bS+8oc2qCNtmQFfegASZpd64yrWIgsBgBsUon4GaABoQeY2RwAkwm/Tf qx3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702589322; x=1703194122; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JfOMdZkveom3dpPw5atfBAGxaPJBLOoennVUbSB4XUA=; b=pWv+KgHK/MD0l7fn8r4qY0WwsRpncmTe5f9KMTqebq4w65Bex3iFBTyNUe1ex4omrC LaC2+2ByzvUVRxsgTaJBWoelqT5SrTHHhParumgZFDh4lqwjlhHTT9uvNqz6BF1FDtDz lUWSo+/6XMLppPaDd+no7BeplUOpCuxAgLevhUlFcy8Um3j05j37JEtqH1nU9yewnmAn aceOkyH0DGjOX3MtO1vmCe4uuVSvoCc7W2bTlZFKXhlyAR0V1nqlVo6/WJh9Imni0SjA +JSFY12eG3/FHl84RNR3qaWCNvN6rseW3lg6ApKiHkLFuAasQ9w4YtGVa+UMpAWvroRx n0tg== X-Gm-Message-State: AOJu0YzXi397G9drVCBkN+QgPhGxJSjqTvvh0g2J3O3rQiljr3WysQtM XvgFpsiRyjZgw8mrUyGX4zBUTc/etVzTfZiLqhDhxw== X-Received: by 2002:a05:6a20:daa0:b0:190:37f5:f7da with SMTP id iy32-20020a056a20daa000b0019037f5f7damr6247847pzb.59.1702589321779; Thu, 14 Dec 2023 13:28:41 -0800 (PST) Received: from free.home ([2804:7f1:2080:cecc:5977:530e:86b5:e7be]) by smtp.gmail.com with ESMTPSA id p25-20020a056a0026d900b006ce3b01cba2sm11380636pfw.108.2023.12.14.13.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 13:28:41 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3BELSR5u491427 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 14 Dec 2023 18:28:27 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: Rainer Orth , Jakub Jelinek , "David S. Miller" , Eric Botcazou Subject: [PATCH #2/2] strub: sparc64: unbias the stack address [PR112917] Organization: Free thinker, does not speak for AdaCore References: Date: Thu, 14 Dec 2023 18:28:27 -0300 In-Reply-To: (Alexandre Oliva's message of "Thu, 14 Dec 2023 17:17:09 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785294328840594507 X-GMAIL-MSGID: 1785294328840594507 The stack pointer is biased by 2047 bytes on sparc64, so the range it delimits is way off. Unbias the addresses returned by __builtin_stack_address (), so that the strub builtins, inlined or not, can function correctly. I've considered introducing a new target macro, but using STACK_POINTER_OFFSET seems safe, and it enables the register save areas to be scrubbed as well. Because of the large fixed-size outgoing args area next to the register save area on sparc, we still need __strub_leave to not allocate its own frame, otherwise it won't be able to clear part of the frame it should. Regstrapped on x86_64-linux-gnu, also testing on sparc-solaris2.11.3. Ok to install? for gcc/ChangeLog PR middle-end/112917 * builtins.cc (expand_bultin_stack_address): Add STACK_POINTER_OFFSET. --- gcc/builtins.cc | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 7c2732ab79e6f..4c8c514fe8618 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -5443,8 +5443,38 @@ expand_builtin_frame_address (tree fndecl, tree exp) static rtx expand_builtin_stack_address () { - return convert_to_mode (ptr_mode, copy_to_reg (stack_pointer_rtx), - STACK_UNSIGNED); + rtx ret = convert_to_mode (ptr_mode, copy_to_reg (stack_pointer_rtx), + STACK_UNSIGNED); + + /* Unbias the stack pointer, bringing it to the boundary between the + stack area claimed by the active function calling this builtin, + and stack ranges that could get clobbered if it called another + function. It should NOT encompass any stack red zone, that is + used in leaf functions. + + On SPARC, the register save area is *not* considered active or + used by the active function, but rather as akin to the area in + which call-preserved registers are saved by callees. This + enables __strub_leave to clear what would otherwise overlap with + its own register save area. + + If the address is computed too high or too low, parts of a stack + range that should be scrubbed may be left unscrubbed, scrubbing + may corrupt active portions of the stack frame, and stack ranges + may be doubly-scrubbed by caller and callee. + + In order for it to be just right, the area delimited by + @code{__builtin_stack_address} and @code{__builtin_frame_address + (0)} should encompass caller's registers saved by the function, + local on-stack variables and @code{alloca} stack areas. + Accumulated outgoing on-stack arguments, preallocated as part of + a function's own prologue, are to be regarded as part of the + (caller) function's active area as well, whereas those pushed or + allocated temporarily for a call are regarded as part of the + callee's stack range, rather than the caller's. */ + ret = plus_constant (ptr_mode, ret, STACK_POINTER_OFFSET); + + return force_reg (ptr_mode, ret); } /* Expand a call to builtin function __builtin_strub_enter. */